From cbb797fc20eb55ee3c277f2b7ccb453114383433 Mon Sep 17 00:00:00 2001 From: nyakokitsu <140620899+nyakokitsu@users.noreply.github.com> Date: Tue, 2 Jan 2024 02:48:20 +0300 Subject: [PATCH] 0.0.2 --- CHANGELOG.md | 5 ++ README.md | 20 +++-- lib/src/command_runner.dart | 2 + lib/src/commands/kodik_command.dart | 20 ++--- lib/src/commands/sibnet_command.dart | 88 ++++++++++++++++++++++ lib/src/commands/update_command.dart | 2 - lib/src/messages.dart | 21 ++++++ lib/src/version.dart | 2 +- pubspec.yaml | 8 +- test/src/commands/update_command_test.dart | 2 +- 10 files changed, 146 insertions(+), 24 deletions(-) create mode 100644 lib/src/commands/sibnet_command.dart create mode 100644 lib/src/messages.dart diff --git a/CHANGELOG.md b/CHANGELOG.md index 8291407..271f783 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.0.2 + +* Sibnet parser! +* Source code optimizations + ## 0.0.1 * Release! diff --git a/README.md b/README.md index 445a6f5..7be5c31 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,11 @@ -## maco +# maco ![coverage][coverage_badge] [![License: MIT][license_badge]][license_link] +[![License: pub][pub_badge]][pub_link] + +[![Readme Card](https://github-readme-stats.vercel.app/api/pin/?username=libanime&repo=maco)](https://github.com/libanime/maco/) + An anime downloading cli based on [libanime](https://github.com/libanime/libanime). @@ -26,11 +30,11 @@ Also you can use portable version in Releases page. ## Usage ```sh -# Parse direct mp4 url for kodik player. -$ maco kodik -u //kodik.info/seria/428055/cf7b8847a36a6904743111e46c2b77d1/720p +# Parse direct mp4 url for kodik player and download. +$ maco kodik -u //kodik.info/seria/428055/cf7b8847a36a6904743111e46c2b77d1/720p -d -# Sample command option -$ maco sample --cyan +# Parse direct mp4 url for sibnet player. +$ maco sibnet -u https://video.sibnet.ru/shell.php?videoid=2235917 # Show CLI version $ maco --version @@ -62,6 +66,8 @@ $ open coverage/index.html --- -[coverage_badge]: coverage_badge.svg +[coverage_badge]: https://github.com/libanime/maco/raw/stable/coverage_badge.svg [license_badge]: https://img.shields.io/badge/license-MIT-blue.svg -[license_link]: https://opensource.org/licenses/MIT \ No newline at end of file +[license_link]: https://opensource.org/licenses/MIT +[pub_badge]: https://img.shields.io/pub/v/maco.svg +[pub_link]: https://pub.dev/packages/maco \ No newline at end of file diff --git a/lib/src/command_runner.dart b/lib/src/command_runner.dart index c2a85b2..acdaff5 100644 --- a/lib/src/command_runner.dart +++ b/lib/src/command_runner.dart @@ -2,6 +2,7 @@ import 'package:args/args.dart'; import 'package:args/command_runner.dart'; import 'package:cli_completion/cli_completion.dart'; import 'package:maco/src/commands/commands.dart'; +import 'package:maco/src/commands/sibnet_command.dart'; import 'package:maco/src/version.dart'; import 'package:mason_logger/mason_logger.dart'; import 'package:pub_updater/pub_updater.dart'; @@ -42,6 +43,7 @@ class MacoCommandRunner extends CompletionCommandRunner { // Add sub commands addCommand(KodikCommand(logger: _logger)); + addCommand(SibnetCommand(logger: _logger)); addCommand(UpdateCommand(logger: _logger, pubUpdater: _pubUpdater)); } diff --git a/lib/src/commands/kodik_command.dart b/lib/src/commands/kodik_command.dart index 6e434ac..7083ba3 100644 --- a/lib/src/commands/kodik_command.dart +++ b/lib/src/commands/kodik_command.dart @@ -5,7 +5,6 @@ import 'package:libanime/libanime.dart'; import 'package:libanime/structures/video.dart'; import 'package:mason_logger/mason_logger.dart'; -/// /// `maco kodik` /// A kodik downloader [Command] @@ -54,22 +53,22 @@ class KodikCommand extends Command { @override Future run() async { - final url = argResults!['url'].toString().startsWith('//') - ? 'https:${argResults!['url']}' - : argResults!['url'].toString(); dynamic token = 'b7cc4293ed475c4ad1fd599d114f4435'; if (argResults?.wasParsed('url') == false) { _logger.err(lightRed.wrap('Url option cannot be null.')); return ExitCode.noInput.code; } if (argResults?.wasParsed('token') == false) { - _logger.info(cyan.wrap('Token not set using default.')); + _logger.info(cyan.wrap('Token not set, using default.')); } else { token = argResults!['token']; } + final url = argResults!['url'].toString().startsWith('//') + ? 'https:${argResults!['url']}' + : argResults!['url'].toString(); final kodik = Kodik(token.toString()); Map? links = {}; - final progress = _logger.progress('Begging video extracing.'); + final progress = _logger.progress('Begging video extraction.'); try { links = await kodik.parse(url, true); } on Exception { @@ -85,7 +84,8 @@ class KodikCommand extends Command { // ignore: inference_failure_on_function_invocation final infoRq = await dio // ignore: inference_failure_on_function_invocation - .get('https://kodikapi.com/search?token=$token&player_link=$url'); + .get( + 'https://kodikapi.com/search?token=$token&player_link=$url&with_material_data=true'); // ignore: avoid_dynamic_calls info = infoRq.data['results'][0]; } on DioException { @@ -94,10 +94,12 @@ class KodikCommand extends Command { return ExitCode.unavailable.code; } + // TODO(nekokitsu): Add more info via material data. // ignore: avoid_dynamic_calls, lines_longer_than_80_chars _logger.info( - // ignore: avoid_dynamic_calls - '\n${styleBold.wrap('Title Original')}: ${info!["title_orig"]}\n${styleBold.wrap('Title RU')}: ${info!["title"]}\n${styleBold.wrap('Release Year')}: ${info!["year"]}\n${styleBold.wrap('Translator Name')}: ${info!["translation"]["title"]}\n${styleBold.wrap('Shikimori')}: https://shikimori.one/animes/${info!["shikimori_id"]}\n',); + // ignore: avoid_dynamic_calls + '\n${styleBold.wrap('Title Original')}: ${info!["title_orig"]}\n${styleBold.wrap('Title RU')}: ${info!["title"]}\n${styleBold.wrap('Release Year')}: ${info!["year"]}\n${styleBold.wrap('Translator Name')}: ${info!["translation"]["title"]}\n${styleBold.wrap('Shikimori')}: https://shikimori.one/animes/${info!["shikimori_id"]}\n', + ); } final quality = _logger.chooseOne( 'Choose quality:', diff --git a/lib/src/commands/sibnet_command.dart b/lib/src/commands/sibnet_command.dart new file mode 100644 index 0000000..cf510b8 --- /dev/null +++ b/lib/src/commands/sibnet_command.dart @@ -0,0 +1,88 @@ +import 'package:args/command_runner.dart'; +// ignore: depend_on_referenced_packages +import 'package:dio/dio.dart'; +import 'package:libanime/libanime.dart'; +import 'package:libanime/structures/video.dart'; +import 'package:mason_logger/mason_logger.dart'; + +/// `maco sibnet` +/// A Sibnet downloader [Command] + +class SibnetCommand extends Command { + /// {@macro sibnet_command} + SibnetCommand({ + required Logger logger, + }) : _logger = logger { + argParser + /*..addOption( + 'path', + abbr: 'p', + help: 'Path for downloading. (Default ./video.mp4)', + ) + ..addFlag( + 'download', + abbr: 'd', + help: 'Download video. Use path option for downloading path change.', + negatable: false, + )*/ + .addOption( + 'url', + abbr: 'u', + help: 'Player Url', + ); + } + + @override + String get description => 'Download video from Sibnet player.'; + + @override + String get name => 'sibnet'; + + final Logger _logger; + final dio = Dio(); + + @override + Future run() async { + if (argResults?.wasParsed('url') == false) { + _logger.err(lightRed.wrap('Url option cannot be null.')); + return ExitCode.noInput.code; + } + final url = argResults!['url'].toString(); + final sibnet = Sibnet(); + Video link; + final progress = _logger.progress('Begging video extraction.'); + try { + link = await sibnet.parse(url); + } on Exception { + progress.fail('An error occurred'); + _logger.err(lightRed.wrap('Link decode error!')); + return ExitCode.unavailable.code; + } + progress.complete('Fetching complete!'); + + final mp4Url = link.url; + _logger.info(mp4Url); + /* Not working, ToDo: fix + if (argResults?['download'] == true) { + var path = './video.mp4'; + // ignore: use_if_null_to_convert_nulls_to_bools + if (argResults?.wasParsed('path') == true) { + path = argResults!['path'].toString(); + } + final downloadProgress = _logger.progress('Downloading.'); + try { + await dio.download(mp4Url, path, options: Options( + headers: { + 'Referer': mp4Url + }, + ),); + } catch (e) { + downloadProgress.fail('An error occurred while downloading'); + _logger.detail('Error: $e'); + } + downloadProgress.complete('Downloaded at $path'); + }*/ + + return ExitCode.success.code; + } +} diff --git a/lib/src/commands/update_command.dart b/lib/src/commands/update_command.dart index 6f25c25..cd74ba4 100644 --- a/lib/src/commands/update_command.dart +++ b/lib/src/commands/update_command.dart @@ -6,9 +6,7 @@ import 'package:maco/src/version.dart'; import 'package:mason_logger/mason_logger.dart'; import 'package:pub_updater/pub_updater.dart'; -/// {@template update_command} /// A command which updates the CLI. -/// {@endtemplate} class UpdateCommand extends Command { /// {@macro update_command} UpdateCommand({ diff --git a/lib/src/messages.dart b/lib/src/messages.dart new file mode 100644 index 0000000..6724cd2 --- /dev/null +++ b/lib/src/messages.dart @@ -0,0 +1,21 @@ +Map en = { + 'beg_ext': 'Begging video extraction.', + 'using_def_token': 'Token not set, using default.', + 'non_null_url': 'Url option cannot be null.', + 'error_occ': 'An error occurred', + 'downloading': 'Downloading.', + 'error_dl': 'An error occurred while downloading', + "error_log": 'Error:', + 'dl_at': 'Downloaded at' +}; + +Map ru = { + 'beg_ext': 'Начинаю вытаскивание ссылки.', + 'using_def_token': 'Токен не указан, изпользую стандартный.', + 'non_null_url': 'Поле url обязательно.', + 'error_occ': 'Произошла ошибка', + 'downloading': 'Скачиваю.', + 'error_dl': 'Произошла ошибка при скачивании.', + "error_log": 'Ошибка:', + 'dl_at': 'Скачано в' +}; diff --git a/lib/src/version.dart b/lib/src/version.dart index 67a7647..19433ff 100644 --- a/lib/src/version.dart +++ b/lib/src/version.dart @@ -1,2 +1,2 @@ // Generated code. Do not modify. -const packageVersion = '0.0.1'; +const packageVersion = '0.0.2'; diff --git a/pubspec.yaml b/pubspec.yaml index 41ed544..a467b18 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: maco -description: An anime downloading cli based on libanime. -version: 0.0.1 +description: An beautiful looking anime downloading cli based on libanime. +version: 0.0.2 homepage: https://github.com/libanime/maco/ repository: https://github.com/libanime/maco/ issue_tracker: https://github.com/libanime/maco/issues @@ -16,11 +16,11 @@ environment: sdk: ">=3.0.0 <4.0.0" dependencies: - args: ^2.4.1 + args: ^2.4.2 cli_completion: ^0.3.0 dio: ^5.4.0 libanime: ^0.0.8 - mason_logger: ^0.2.5 + mason_logger: ^0.2.10 pub_updater: ^0.3.1 dev_dependencies: diff --git a/test/src/commands/update_command_test.dart b/test/src/commands/update_command_test.dart index 75d9930..c423bed 100644 --- a/test/src/commands/update_command_test.dart +++ b/test/src/commands/update_command_test.dart @@ -15,7 +15,7 @@ class _MockProgress extends Mock implements Progress {} class _MockPubUpdater extends Mock implements PubUpdater {} void main() { - const latestVersion = '0.0.1'; + const latestVersion = '0.0.2'; group('update', () { late PubUpdater pubUpdater;