OpenMediacenterMobileFlutter/lib/api/video_api.dart
lukas-heiligenbrunner 9ef317f0ba outsourced lots of api calls to api folder
centered error message when failed loading video feed
display server url on settings page
2022-10-15 20:28:31 +02:00

71 lines
1.8 KiB
Dart

import 'dart:convert';
import 'dart:math';
import 'dart:typed_data';
import '../log/log.dart';
import '../types/actor.dart';
import '../types/tag.dart';
import '../types/video.dart';
import '../types/video_data.dart';
import 'api.dart';
Future<VideoData> loadVideoData(int videoId) async {
final data = await API.query("video", "loadVideo", {'MovieId': videoId});
final d = jsonDecode(data);
final video = VideoData.fromJson(d);
return video;
}
Future<List<VideoT>> loadVideo(Tag? tag, int filterIdx) async {
final data = await API
.query("video", "getMovies", {'Tag': tag?.tagId ?? 1, 'Sort': filterIdx});
final d = jsonDecode(data);
List<VideoT> dta =
(d['Videos'] as List).map((e) => VideoT.fromJson(e)).toList();
return dta;
}
Future<List<VideoT>> loadShuffledVideos(int nr) async {
final data = await API.query("video", "getRandomMovies",
{'Number': nr, 'Seed': Random().nextInt(0x7fffffff)});
final d = jsonDecode(data);
List<VideoT> dta =
(d['Videos'] as List).map((e) => VideoT.fromJson(e)).toList();
return dta;
}
Future<List<VideoT>> loadVideoByActor(Actor actor) async {
final data =
await API.query("actor", "getActorInfo", {'ActorId': actor.actorId});
final d = jsonDecode(data);
List<VideoT> dta =
(d['Videos'] as List).map((e) => VideoT.fromJson(e)).toList();
return dta;
}
Future<bool> addLike(int movieId) async {
final data = await API.query("video", "addLike", {'MovieId': movieId});
final d = jsonDecode(data);
if (d["result"] != 'success') {
Log.w(d);
}
return d["result"] == 'success';
}
Future<Uint8List> fetchThumbnail(int movieId) async {
final base64str =
await API.query("video", "readThumbnail", {'Movieid': movieId});
return base64Decode(base64str.substring(23));
}