2022-08-30 21:25:21 +00:00
|
|
|
import 'dart:convert';
|
2022-10-15 18:28:31 +00:00
|
|
|
import 'dart:math';
|
|
|
|
import 'dart:typed_data';
|
2022-08-30 21:25:21 +00:00
|
|
|
|
2022-10-15 18:28:31 +00:00
|
|
|
import '../log/log.dart';
|
|
|
|
import '../types/actor.dart';
|
|
|
|
import '../types/tag.dart';
|
|
|
|
import '../types/video.dart';
|
2022-08-30 21:25:21 +00:00
|
|
|
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;
|
|
|
|
}
|
2022-10-15 18:28:31 +00:00
|
|
|
|
|
|
|
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));
|
|
|
|
}
|