diff --git a/-vcodec b/-vcodec new file mode 100644 index 0000000..e69de29 diff --git a/.gitignore b/.gitignore index 6b48af0..52a302f 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,9 @@ .svn/ migrate_working_dir/ +#VsCode +.vscode/ + # IntelliJ related *.iml *.ipr @@ -42,3 +45,5 @@ app.*.map.json /android/app/debug /android/app/profile /android/app/release + +samples/ \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index 31032cd..0000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "name": "notube", - "request": "launch", - "type": "dart" - }, - { - "name": "notube (profile mode)", - "request": "launch", - "type": "dart", - "flutterMode": "profile" - }, - { - "name": "notube (release mode)", - "request": "launch", - "type": "dart", - "flutterMode": "release" - } - ] -} diff --git a/lib/constants.dart b/lib/constants.dart index f4e93b4..281db6f 100644 --- a/lib/constants.dart +++ b/lib/constants.dart @@ -8,8 +8,14 @@ const colorDarkRed = Color.fromRGBO(153, 0, 0, 1); const colorMainBlue = Color(0xFF1f74ad); enum Format { - mp3(format: 'MP3'), - mp3HD(format: 'MP3 HD'), + mp3( + format: 'MP3', + ffmpegCmd: '-f mp3 -loglevel quiet -ab 192k -vn', + extension: 'mp3'), + mp3HD( + format: 'MP3 HD', + ffmpegCmd: '-f mp3 -loglevel quiet -ab 320k -vn', + extension: 'mp3'), mp4(format: 'MP4'), mp4HD( ytCmd: @@ -19,16 +25,36 @@ enum Format { ytCmd: "bestvideo[height=1440][ext=mp4]+bestaudio[ext=m4a]/bestvideo[height<=1080][ext=mp4][vcodec~='^(avc|h264)']+bestaudio[ext=m4a]/bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best", format: 'MP4 2K'), - tGP(format: '3GP'), - flv(format: 'FLV'), - m4a; + tGP( + format: '3GP', + ffmpegCmd: + '-movflags frag_keyframe+empty_moov -r 20 -s 352x288 -vb 400k -acodec aac -strict experimental -ac 1 -ar 8000 -ab 24k -f 3gp', + extension: '3gp'), + flv( + format: 'FLV', + ffmpegCmd: + '-vcodec libx264 -preset slower -b 512k -bt 512k -threads 0 -s 640x360 -aspect 16:9 -acodec libmp3lame -ar 44100 -ab 32 -progress pipe:1', + extension: 'flv'), + m4a(format: 'M4A'), + ; final String ytCmd; final String format; + final String ffmpegCmd; + final String extension; const Format({ this.ytCmd = '"18/22/bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best"', this.format = 'MP4', + this.ffmpegCmd = '', + this.extension = '', }); } + +const convertedFormats = [ + Format.mp3, + Format.mp3HD, + Format.tGP, + Format.flv, +]; diff --git a/lib/dlForm/cubit/dl_form_cubit.dart b/lib/dlForm/cubit/dl_form_cubit.dart index 6f8091a..8ce0e71 100644 --- a/lib/dlForm/cubit/dl_form_cubit.dart +++ b/lib/dlForm/cubit/dl_form_cubit.dart @@ -2,11 +2,11 @@ import 'dart:convert'; import 'package:bloc/bloc.dart'; import 'package:equatable/equatable.dart'; -import 'package:notube/models/Video.dart'; +import 'package:flutter/material.dart'; +import 'package:notube/constants.dart'; +import 'package:notube/models/video.dart'; import 'package:notube/services/download.dart'; -import 'dart:developer'; - part 'dl_form_state.dart'; class DlFormCubit extends Cubit { @@ -14,7 +14,7 @@ class DlFormCubit extends Cubit { late DLServices dlService; - void setFormat(String newFormat) { + void setFormat(Format newFormat) { emit(state.copyWith( format: newFormat, )); @@ -29,7 +29,7 @@ class DlFormCubit extends Cubit { void parseUrl() async { dlService = await DLServices.init(); - var shellStream = await dlService.analyseUrl(state.url!); + var shellStream = await dlService.analyseUrl(state.url); shellStream.listen((line) { if (line[0] == '{') { @@ -41,13 +41,15 @@ class DlFormCubit extends Cubit { var playlistTitle = dataInfos['title']; for (var videoTmp in dataInfos['entries']) { var video = Video.fromJson(videoTmp); - video.format = state.format; - videos.add(video); + videos.add(video.copyWith( + format: state.format, + filename: '${video.id}_${state.format.format}')); } } else { var video = Video.fromJson(dataInfos); - video.format = state.format; - videos.add(video); + videos.add(video.copyWith( + format: state.format, + filename: '${video.id}_${state.format.format}')); } emit(state.copyWith( isParsed: true, @@ -58,7 +60,7 @@ class DlFormCubit extends Cubit { }); } - void clearVideos() { + void clearForm() { emit(state.copyWith( videos: [], isParsed: false, diff --git a/lib/dlForm/cubit/dl_form_state.dart b/lib/dlForm/cubit/dl_form_state.dart index 6eb3567..78fa55f 100644 --- a/lib/dlForm/cubit/dl_form_state.dart +++ b/lib/dlForm/cubit/dl_form_state.dart @@ -3,21 +3,21 @@ part of 'dl_form_cubit.dart'; class DlFormState extends Equatable { const DlFormState({ this.url = '', - this.format = 'MP3', + this.format = Format.mp4, this.videos = const [], this.isParsed = false, this.extractor = '', }); final String url; - final String format; + final Format format; final bool isParsed; final List