Skip to content

Commit

Permalink
chore: improved single download filename logic
Browse files Browse the repository at this point in the history
  • Loading branch information
MSOB7YY committed Sep 26, 2024
1 parent 1d38cd0 commit 96ac21b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
38 changes: 32 additions & 6 deletions lib/youtube/functions/download_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,34 @@ Future<void> showDownloadVideoBottomSheet({
updateTagsMap(defaultInitialTags);
updateTagsMap(settings.youtube.initialDefaultMetadataTags);

bool videoOutputFilenameWasUserEdited = false;
void updatefilenameOutput({String customName = ''}) {
if (videoOutputFilenameWasUserEdited) return;

if (customName != '') {
videoOutputFilenameController.text = customName;
return;
}
if (initialItemConfig != null) return; // cuz already set.

final filenameBuilderInSetting = settings.youtube.downloadFilenameBuilder.value;
if (filenameBuilderInSetting.isNotEmpty) {
final finalFilenameTempRebuilt = YoutubeController.filenameBuilder.rebuildFilenameWithDecodedParams(
filenameBuilderInSetting,
videoId,
streamResult.value,
null,
streamInfoItem ?? initialItemConfig?.streamInfoItem,
playlistInfo,
selectedVideoOnlyStream.value,
selectedAudioOnlyStream.value,
initialItemConfig?.index,
initialItemConfig?.totalLength,
);
if (finalFilenameTempRebuilt != null && finalFilenameTempRebuilt.isNotEmpty) {
videoOutputFilenameController.text = finalFilenameTempRebuilt;
return;
}
}

final videoTitle = videoInfo.value?.title ?? videoId;
if (selectedAudioOnlyStream.value == null && selectedVideoOnlyStream.value == null) {
Expand All @@ -100,6 +122,14 @@ Future<void> showDownloadVideoBottomSheet({
}
}

if (initialItemConfig != null) {
updatefilenameOutput(customName: initialItemConfig.filename.filename);
updateTagsMap(initialItemConfig.ffmpegTags);
videoOutputFilenameWasUserEdited = true;
} else {
updatefilenameOutput(customName: settings.youtube.downloadFilenameBuilder.value);
}

void showWebmWarning() {
snackyy(
title: lang.WARNING,
Expand All @@ -119,11 +149,6 @@ Future<void> showDownloadVideoBottomSheet({
if (selectedVideoOnlyStream.value?.isWebm == true) showWebmWarning(); // webm doesnt support tag editing
}

if (initialItemConfig != null) {
updatefilenameOutput(customName: initialItemConfig.filename.filename);
updateTagsMap(initialItemConfig.ffmpegTags);
}

void onStreamsObtained(VideoStreamsResult? streams) {
streamResult.value = streams;
if (streams?.info != null) videoInfo.value = streams!.info!;
Expand Down Expand Up @@ -629,6 +654,7 @@ Future<void> showDownloadVideoBottomSheet({
controller: videoOutputFilenameController,
hintText: videoOutputFilenameController.text,
labelText: lang.FILE_NAME,
onChanged: (_) => videoOutputFilenameWasUserEdited = true,
validatorMode: AutovalidateMode.always,
validator: (value) {
if (value == null) return lang.PLEASE_ENTER_A_NAME;
Expand Down
4 changes: 3 additions & 1 deletion lib/youtube/pages/yt_playlist_download_subpage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ class _YTPlaylistDownloadPageState extends State<YTPlaylistDownloadPage> {

YoutubeItemDownloadConfig _getDummyDownloadConfig(String id, int index, {String? defaultFilename}) {
final streamInfoItem = widget.infoLookup[id];
final filename = defaultFilename ?? streamInfoItem?.title ?? YoutubeInfoController.utils.getVideoName(id) ?? id;
final filenameBuilderSettings = settings.youtube.downloadFilenameBuilder.value;
final filename =
filenameBuilderSettings.isNotEmpty ? filenameBuilderSettings : (defaultFilename ?? streamInfoItem?.title ?? YoutubeInfoController.utils.getVideoName(id) ?? id);
return YoutubeItemDownloadConfig(
index: index,
totalLength: widget.playlistInfo?.videosCount ?? widget.ids.length,
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: namida
description: A Beautiful and Feature-rich Music Player, With YouTube & Video Support Built in Flutter
publish_to: "none"
version: 4.4.84-beta+240926220
version: 4.4.9-beta+240926220

environment:
sdk: ">=3.4.0 <4.0.0"
Expand Down

0 comments on commit 96ac21b

Please sign in to comment.