-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from miru-project/feat/bittorrent-playback
Feat: bittorrent playback
- Loading branch information
Showing
35 changed files
with
632 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,7 +34,7 @@ Miru App | |
|
||
## Todo | ||
|
||
- [ ] BTトレント | ||
- [x] BTトレント | ||
- [ ] より良いデバッグツール | ||
- [ ] データの同期 | ||
- [ ] 字幕の自動検索 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,7 @@ Miru App | |
|
||
## Todo | ||
|
||
- [ ] BTトレント | ||
- [x] BTトレント | ||
- [ ] ゆりゆたさるデバッグツール | ||
- [ ] データぬちゃーき | ||
- [ ] じまちゅるぬじちゃーきんさく | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,7 @@ Miru App | |
|
||
## Todo | ||
|
||
- [ ] BT 种子播放 | ||
- [x] BT 种子播放 | ||
- [ ] 更好的调试工具 | ||
- [ ] 数据同步 | ||
- [ ] 自动搜寻字幕 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import 'dart:typed_data'; | ||
|
||
import 'package:dio/dio.dart'; | ||
|
||
class BTServerApi { | ||
static const baseApi = "http://localhost:3000"; | ||
static final dio = Dio(BaseOptions( | ||
baseUrl: baseApi, | ||
)); | ||
static Future<String> getVersion() async { | ||
return (await dio.get<String>("/version")).data!; | ||
} | ||
|
||
static Future<String> addTorrent(Uint8List torrent) async { | ||
return (await dio.post<Map<String, dynamic>>("/torrent", | ||
data: torrent, | ||
options: Options( | ||
headers: { | ||
"Content-Type": "application/x-bittorrent", | ||
"Content-Length": torrent.length, | ||
}, | ||
))) | ||
.data!["infoHash"]; | ||
} | ||
|
||
static Future<String> removeTorrent(String infoHash) async { | ||
return (await dio.delete<String>("/torrent/$infoHash")).data!; | ||
} | ||
|
||
static Future<List<String>> getFileList(String infoHash) async { | ||
final fileList = (await dio.get<Map<String, dynamic>>("/torrent/$infoHash")) | ||
.data!['files']; | ||
return List<String>.from(fileList); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter/scheduler.dart'; | ||
import 'package:get/get.dart'; | ||
import 'package:miru_app/pages/main/controller.dart'; | ||
import 'package:miru_app/utils/bt_server.dart'; | ||
import 'package:miru_app/widgets/messenger.dart'; | ||
|
||
class BTDialogController extends GetxController { | ||
final isInstalled = false.obs; | ||
final isDownloading = false.obs; | ||
final progress = 0.0.obs; | ||
|
||
final _mainController = Get.find<MainController>(); | ||
late final isRuning = _mainController.btServerisRunning; | ||
late final version = _mainController.btServerVersion; | ||
|
||
@override | ||
void onInit() { | ||
super.onInit(); | ||
SchedulerBinding.instance.addPostFrameCallback((_) async { | ||
isInstalled.value = await BTServerUtils.isInstalled(); | ||
}); | ||
} | ||
|
||
downloadOrUpgradeServer(BuildContext context) async { | ||
isDownloading.value = true; | ||
try { | ||
await BTServerUtils.downloadLatestBTServer( | ||
onReceiveProgress: (p0, p1) { | ||
progress.value = p0 / p1; | ||
print(progress.value); | ||
}, | ||
); | ||
} catch (e) { | ||
context.mounted && | ||
showPlatformSnackbar( | ||
context: context, | ||
content: e.toString(), | ||
); | ||
} finally { | ||
isDownloading.value = false; | ||
} | ||
isInstalled.value = await BTServerUtils.isInstalled(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:fluent_ui/fluent_ui.dart' as fluent; | ||
import 'package:flutter_i18n/flutter_i18n.dart'; | ||
import 'package:get/get.dart'; | ||
import 'package:miru_app/pages/bt_dialog/controller.dart'; | ||
import 'package:miru_app/utils/bt_server.dart'; | ||
import 'package:miru_app/utils/i18n.dart'; | ||
import 'package:miru_app/widgets/button.dart'; | ||
import 'package:miru_app/widgets/platform_widget.dart'; | ||
import 'package:miru_app/widgets/progress.dart'; | ||
|
||
class BTDialog extends StatefulWidget { | ||
const BTDialog({Key? key}) : super(key: key); | ||
|
||
@override | ||
State<BTDialog> createState() => _BTDialogState(); | ||
} | ||
|
||
class _BTDialogState extends State<BTDialog> { | ||
final BTDialogController c = Get.put(BTDialogController()); | ||
|
||
Widget _buildContent(BuildContext context) { | ||
return Obx(() { | ||
if (!c.isInstalled.value) { | ||
return Column( | ||
mainAxisSize: MainAxisSize.min, | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
children: [ | ||
Text("bt-server.not-installed".i18n), | ||
const SizedBox(height: 16), | ||
if (c.isDownloading.value) | ||
SizedBox( | ||
width: double.infinity, | ||
child: ProgressBar(value: c.progress.value), | ||
) | ||
else | ||
PlatformFilledButton( | ||
child: Text("common.install".i18n), | ||
onPressed: () { | ||
c.downloadOrUpgradeServer(context); | ||
}, | ||
), | ||
], | ||
); | ||
} | ||
|
||
return Column( | ||
mainAxisSize: MainAxisSize.min, | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
children: [ | ||
if (c.isRuning.value) | ||
Text("bt-server.running".i18n) | ||
else | ||
Text("bt-server.stopped".i18n), | ||
const SizedBox(height: 16), | ||
if (c.isRuning.value) | ||
Text( | ||
FlutterI18n.translate( | ||
context, | ||
'bt-server.version', | ||
translationParams: { | ||
"version": c.version.value, | ||
}, | ||
), | ||
) | ||
else | ||
PlatformFilledButton( | ||
child: Text("bt-server.start".i18n), | ||
onPressed: () { | ||
BTServerUtils.startServer(); | ||
}, | ||
), | ||
], | ||
); | ||
}); | ||
} | ||
|
||
Widget _buildAndroid(BuildContext context) { | ||
return AlertDialog( | ||
title: const Text("BT-Server"), | ||
content: _buildContent(context), | ||
actions: [ | ||
PlatformTextButton( | ||
child: Text("common.close".i18n), | ||
onPressed: () { | ||
Navigator.of(context).pop(); | ||
}, | ||
), | ||
], | ||
); | ||
} | ||
|
||
Widget _buildDesktop(BuildContext context) { | ||
return fluent.ContentDialog( | ||
title: const Text("BT-Server"), | ||
content: _buildContent(context), | ||
actions: [ | ||
fluent.Button( | ||
onPressed: () { | ||
Navigator.of(context).pop(); | ||
}, | ||
child: Text("common.close".i18n), | ||
), | ||
], | ||
); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return PlatformBuildWidget( | ||
androidBuilder: _buildAndroid, | ||
desktopBuilder: _buildDesktop, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.