Skip to content

Commit

Permalink
0.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
nyakokitsu committed Jan 1, 2024
1 parent 5de9fa6 commit cbb797f
Show file tree
Hide file tree
Showing 10 changed files with 146 additions and 24 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.0.2

* Sibnet parser!
* Source code optimizations

## 0.0.1

* Release!
Expand Down
20 changes: 13 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -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).

Expand All @@ -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
Expand Down Expand Up @@ -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
[license_link]: https://opensource.org/licenses/MIT
[pub_badge]: https://img.shields.io/pub/v/maco.svg
[pub_link]: https://pub.dev/packages/maco
2 changes: 2 additions & 0 deletions lib/src/command_runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -42,6 +43,7 @@ class MacoCommandRunner extends CompletionCommandRunner<int> {

// Add sub commands
addCommand(KodikCommand(logger: _logger));
addCommand(SibnetCommand(logger: _logger));
addCommand(UpdateCommand(logger: _logger, pubUpdater: _pubUpdater));
}

Expand Down
20 changes: 11 additions & 9 deletions lib/src/commands/kodik_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -54,22 +53,22 @@ class KodikCommand extends Command<int> {

@override
Future<int> 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<String, Video>? links = {};
final progress = _logger.progress('Begging video extracing.');
final progress = _logger.progress('Begging video extraction.');
try {
links = await kodik.parse(url, true);
} on Exception {
Expand All @@ -85,7 +84,8 @@ class KodikCommand extends Command<int> {
// 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 {
Expand All @@ -94,10 +94,12 @@ class KodikCommand extends Command<int> {
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:',
Expand Down
88 changes: 88 additions & 0 deletions lib/src/commands/sibnet_command.dart
Original file line number Diff line number Diff line change
@@ -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<int> {
/// {@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<int> 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;
}
}
2 changes: 0 additions & 2 deletions lib/src/commands/update_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> {
/// {@macro update_command}
UpdateCommand({
Expand Down
21 changes: 21 additions & 0 deletions lib/src/messages.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Map<String, String> 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<String, String> ru = {
'beg_ext': 'Начинаю вытаскивание ссылки.',
'using_def_token': 'Токен не указан, изпользую стандартный.',
'non_null_url': 'Поле url обязательно.',
'error_occ': 'Произошла ошибка',
'downloading': 'Скачиваю.',
'error_dl': 'Произошла ошибка при скачивании.',
"error_log": 'Ошибка:',
'dl_at': 'Скачано в'
};
2 changes: 1 addition & 1 deletion lib/src/version.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion test/src/commands/update_command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit cbb797f

Please sign in to comment.