Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:anilist tracking service #155

Merged
merged 29 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
defdd6d
feat:get anilist data
appdevelpo Dec 19, 2023
92c1b63
initial desktop support
appdevelpo Dec 21, 2023
b147a33
feat(mobile):add anilist
appdevelpo Dec 25, 2023
10e9524
feat: anilist fully support on desktop
appdevelpo Jan 7, 2024
cc98cef
feat: show snakbar
appdevelpo Jan 8, 2024
e2b80c1
fix: anilist ui for android
appdevelpo Jan 9, 2024
4332326
Merge branch 'dev' into feat/anilist
MiaoMint Jan 9, 2024
986bd7a
anilist tracking page
MiaoMint Jan 9, 2024
ae86d24
fix anilist tracking page
MiaoMint Jan 10, 2024
b5300fc
anilist more page
MiaoMint Jan 10, 2024
4f5dcd0
AniList binding page
MiaoMint Jan 10, 2024
93ab44c
getMediaList by using id
appdevelpo Jan 11, 2024
ca3f819
fix: edit list error
appdevelpo Jan 11, 2024
e32db08
Merge branch 'dev' into feat/anilist
MiaoMint Jan 11, 2024
be5c89d
Revert "fix: edit list error"
MiaoMint Jan 12, 2024
14b268b
Merge branch 'dev' into feat/anilist
MiaoMint Jan 13, 2024
a7032e1
feat: desktop tracking dialog
MiaoMint Jan 13, 2024
46daa8a
feat: android tracking dialog
MiaoMint Jan 13, 2024
7f37732
fix
MiaoMint Jan 13, 2024
eb4136a
fix
MiaoMint Jan 14, 2024
afcd3cd
Refactor AnilistType usage in detail_tracking_button.dart
MiaoMint Jan 15, 2024
a97c944
Merge remote-tracking branch 'origin/dev' into feat/anilist
MiaoMint Jan 15, 2024
7b4ced3
Refactor Anilist tracking dialog and horizontal list widget
MiaoMint Jan 15, 2024
a35a143
Add auto-tracking feature and Anilist integration
MiaoMint Jan 15, 2024
20b0a11
Fix Anilist token saving and cookie handling
MiaoMint Jan 16, 2024
75f7099
Fix error handling in AniListProvider and AnilistMorePage
MiaoMint Jan 16, 2024
3501810
Merge remote-tracking branch 'origin/dev' into feat/anilist
MiaoMint Jan 16, 2024
b3e9c75
add i18n
appdevelpo Jan 16, 2024
426e251
Update localization and UI text
MiaoMint Jan 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@
"get-lastest-data-error": "Failed to get latest data",
"modify-tmdb-binding": "Modify TMDB Binding",
"no-tmdb-data": "No TMDB data matched, please bind the data yourself",
"tmdb-key-missing": "TMDB API Key missing, please fill in the settings"
"tmdb-key-missing": "TMDB API Key missing, please fill in the settings",
"tracker": "Tracking"
},
"video": {
"episodes": "Episodes",
Expand Down
Binary file added assets/icon/anilist.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 30 additions & 5 deletions lib/controllers/detail_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:fluent_ui/fluent_ui.dart' as fluent;
import 'package:flutter/material.dart';
import 'package:flutter_i18n/flutter_i18n.dart';
import 'package:get/get.dart';
import 'package:miru_app/data/providers/anilist_provider.dart';
import 'package:miru_app/data/providers/tmdb_provider.dart';
import 'package:miru_app/models/index.dart';
import 'package:miru_app/views/dialogs/tmdb_binding.dart';
Expand Down Expand Up @@ -43,6 +44,8 @@ class DetailPageController extends GetxController {
final RxString error = ''.obs;
final RxBool isLoading = true.obs;
final RxInt selectEpGroup = 0.obs;
// final RxString aniListID = ''.obs;
// final RxString aniListMediaId = ''.obs;
final Rx<TMDBDetail?> tmdb = Rx(null);
final Rx<ExtensionService?> runtime = Rx(null);
ExtensionType get type =>
Expand All @@ -65,6 +68,10 @@ class DetailPageController extends GetxController {
return bg;
}

final anlistExtensionMap = <ExtensionType, String>{
ExtensionType.bangumi: "ANIME",
ExtensionType.manga: "MANGA",
};
MiruDetail? _miruDetail;

int _tmdbID = -1;
Expand Down Expand Up @@ -136,6 +143,7 @@ class DetailPageController extends GetxController {
try {
_miruDetail = await DatabaseService.getMiruDetail(package, url);
_tmdbID = _miruDetail?.tmdbID ?? -1;
AniListProvider.userVal["id"] = _miruDetail?.aniListID ?? "";
await getDetail();
await getTMDBDetail();
await getHistory();
Expand All @@ -149,7 +157,7 @@ class DetailPageController extends GetxController {
// 修改 tmdb 绑定
modifyTMDBBinding() async {
// 判断是否有 key
if (MiruStorage.getSetting(SettingKey.tmdbKay) == "") {
if (MiruStorage.getSetting(SettingKey.tmdbKey) == "") {
showPlatformSnackbar(
context: currentContext,
content: 'detail.tmdb-key-missing'.i18n,
Expand Down Expand Up @@ -193,8 +201,13 @@ class DetailPageController extends GetxController {
getRemoteDeatil() async {
try {
detail = await runtime.value!.detail(url);
await DatabaseService.putMiruDetail(package, url, detail!,
tmdbID: _tmdbID);
await DatabaseService.putMiruDetail(
package,
url,
detail!,
tmdbID: _tmdbID,
anilistID: AniListProvider.userVal["id"],
);
} catch (e) {
// 弹出错误信息
if (runtime.value == null) {
Expand Down Expand Up @@ -261,6 +274,15 @@ class DetailPageController extends GetxController {
);
}

saveAniListIds() async {
await DatabaseService.putMiruDetail(
package,
url,
detail!,
anilistID: AniListProvider.userVal["id"],
);
}

getHistory() async {
// 获取历史记录
final history_ = await DatabaseService.getHistoryByPackageAndUrl(
Expand All @@ -277,8 +299,10 @@ class DetailPageController extends GetxController {
}

refreshFavorite() async {
isFavorite.value =
await DatabaseService.isFavorite(package: package, url: url);
isFavorite.value = await DatabaseService.isFavorite(
package: package,
url: url,
);
}

toggleFavorite() async {
Expand Down Expand Up @@ -383,6 +407,7 @@ class DetailPageController extends GetxController {
),
),
child: WatchPage(
anilistId: AniListProvider.userVal["id"],
cover: detail!.cover,
playList: urls,
package: package,
Expand Down
68 changes: 68 additions & 0 deletions lib/controllers/tracking_page_controller.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import 'dart:io';

import 'package:desktop_webview_window/desktop_webview_window.dart';
import 'package:get/get.dart';
import 'package:miru_app/data/providers/anilist_provider.dart';
import 'package:miru_app/utils/miru_storage.dart';
import 'package:miru_app/views/pages/tracking/anilist_webview.dart';

class TrackingPageController extends GetxController {
final anilistIsLogin = false.obs;
final anilistOauthUrl = "".obs;
final anilistUserData = {}.obs;

Future<Map<String, dynamic>> initAnilistData() async {
final Map<String, dynamic> result = {};
result["userData"] = await AniListProvider.getuserData();
result["animeData"] =
await AniListProvider.getCollection(AnilistType.anime);
result["mangaData"] =
await AniListProvider.getCollection(AnilistType.manga);
return result;
}

updateAniListToken(String accessToken) {
MiruStorage.setSetting(SettingKey.aniListToken, accessToken);
anilistIsLogin.value = true;
initAnilistData();
}

logoutAniList() {
MiruStorage.setSetting(SettingKey.aniListToken, "");
anilistIsLogin.value = false;
}

loginAniList() async {
const loginUrl =
"https://anilist.co/api/v2/oauth/authorize?client_id=16214&response_type=token";
if (Platform.isAndroid) {
Get.to(
() => const AnilistWebViewPage(
url: loginUrl,
),
);
return;
}
final webview = await WebviewWindow.create();
webview
..launch(
loginUrl,
)
..addOnUrlRequestCallback((url) {
if (url.contains("miru-app")) {
AniListProvider.saveAuthToken(url);
webview.close();
}
});
}

@override
void onInit() {
final token = MiruStorage.getSetting(SettingKey.aniListToken);
if (token != "") {
anilistIsLogin.value = true;
initAnilistData();
}
super.onInit();
}
}
40 changes: 37 additions & 3 deletions lib/controllers/watch/video_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import 'package:flutter_i18n/flutter_i18n.dart';
import 'package:get/get.dart';
import 'package:media_kit/media_kit.dart';
import 'package:media_kit_video/media_kit_video.dart';
import 'package:miru_app/controllers/detail_controller.dart';
import 'package:miru_app/data/providers/bt_server_provider.dart';
import 'package:miru_app/models/index.dart';
import 'package:miru_app/views/dialogs/bt_dialog.dart';
Expand All @@ -31,6 +32,8 @@ import 'package:fluent_ui/fluent_ui.dart' as fluent;
import 'package:crypto/crypto.dart';
import 'package:miru_app/utils/miru_storage.dart';
import 'package:flutter_hls_parser/flutter_hls_parser.dart';
import 'package:miru_app/views/widgets/messenger.dart';
import 'package:miru_app/data/providers/anilist_provider.dart';

class VideoPlayerController extends GetxController {
final String title;
Expand All @@ -39,14 +42,15 @@ class VideoPlayerController extends GetxController {
final int playIndex;
final int episodeGroupId;
final ExtensionService runtime;

final String anilistId;
VideoPlayerController({
required this.title,
required this.playList,
required this.detailUrl,
required this.playIndex,
required this.episodeGroupId,
required this.runtime,
required this.anilistId,
});

final player = Player();
Expand All @@ -71,7 +75,8 @@ class VideoPlayerController extends GetxController {

final torrentMediaFileList = <String>[].obs;
final currentTorrentFile = ''.obs;

bool _isAutoUpdateProgress =
MiruStorage.getSetting(SettingKey.autoUpdateProgress);
String _torrenHash = "";
final ReceivePort qualityRereceivePort = ReceivePort();
Isolate? qualityReceiver;
Expand All @@ -85,7 +90,11 @@ class VideoPlayerController extends GetxController {
[DeviceOrientation.landscapeLeft, DeviceOrientation.landscapeRight]);
SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersiveSticky);
}

if (_isAutoSeekPosition) {
_isAutoSeekPosition = false;
// showPlatformSnackbar(context: , content: content)
}
// final _c = Get.find<DetailPageController>(tag: title);
if (player.platform is NativePlayer) {
await (player.platform as dynamic).setProperty('cache', 'yes');
await (player.platform as dynamic)
Expand Down Expand Up @@ -271,6 +280,31 @@ class VideoPlayerController extends GetxController {
});
}

updateProgress(BuildContext context) async {
if (_isAutoUpdateProgress &&
AniListProvider.anilistToken.isNotEmpty &&
AniListProvider.userVal['mediaId'].isNotEmpty) {
_isAutoUpdateProgress = false;
debugPrint(anilistId);
try {
final res = await AniListProvider.editList(
status: "CURRENT",
id: AniListProvider.userVal['id'],
mediaId: AniListProvider.userVal['mediaId'],
progress: (playIndex + 1).toString());
showPlatformSnackbar(
context: context,
content: "anilist set to progress ${playIndex + 1}");

AniListProvider.userVal["id"] = res;
debugPrint("save to $res");
await Get.find<DetailPageController>().saveAniListIds();
} catch (e) {
showPlatformSnackbar(context: context, content: e.toString());
}
}
}

play() async {
// 如果已经 delete 当前 controller
if (!Get.isRegistered<VideoPlayerController>(tag: title)) {
Expand Down
Loading