From f97b20da49a5c7e9e44dee9d5b98f3e8311fc85f Mon Sep 17 00:00:00 2001 From: jscampucci Date: Tue, 2 Jul 2024 11:23:14 +0200 Subject: [PATCH] [conv] ffmpeg full conversion --- -vcodec | 0 lib/constants.dart | 36 ++++- lib/dlForm/cubit/dl_form_cubit.dart | 20 +-- lib/dlForm/cubit/dl_form_state.dart | 6 +- lib/dlForm/dl_form.dart | 2 +- .../formComponents/format_dropdown.dart | 6 +- lib/dlForm/formComponents/submit_button.dart | 2 +- lib/models/Video.dart | 7 +- lib/screens/home.dart | 2 +- lib/services/converter.dart | 46 +++++- lib/services/download.dart | 17 ++- lib/videoList/cubit/videos_cubit.dart | 132 +++++++++++++++--- macos/Flutter/GeneratedPluginRegistrant.swift | 2 + pubspec.lock | 90 +++++++++++- pubspec.yaml | 2 + .../flutter/generated_plugin_registrant.cc | 6 + windows/flutter/generated_plugins.cmake | 2 + 17 files changed, 320 insertions(+), 58 deletions(-) create mode 100644 -vcodec diff --git a/-vcodec b/-vcodec new file mode 100644 index 0000000..e69de29 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 1b3364b..8ce0e71 100644 --- a/lib/dlForm/cubit/dl_form_cubit.dart +++ b/lib/dlForm/cubit/dl_form_cubit.dart @@ -2,6 +2,8 @@ import 'dart:convert'; import 'package:bloc/bloc.dart'; import 'package:equatable/equatable.dart'; +import 'package:flutter/material.dart'; +import 'package:notube/constants.dart'; import 'package:notube/models/video.dart'; import 'package:notube/services/download.dart'; @@ -12,7 +14,7 @@ class DlFormCubit extends Cubit { late DLServices dlService; - void setFormat(String newFormat) { + void setFormat(Format newFormat) { emit(state.copyWith( format: newFormat, )); @@ -39,17 +41,15 @@ class DlFormCubit extends Cubit { var playlistTitle = dataInfos['title']; for (var videoTmp in dataInfos['entries']) { var video = Video.fromJson(videoTmp); - video.copyWith( - 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.copyWith( - format: state.format, - ); - videos.add(video); + videos.add(video.copyWith( + format: state.format, + filename: '${video.id}_${state.format.format}')); } emit(state.copyWith( isParsed: true, @@ -60,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