From 42ecb21f20501b4a24a54a2cb6ee9d91e6bdda37 Mon Sep 17 00:00:00 2001 From: MSOB7YY Date: Mon, 28 Oct 2024 00:45:27 +0300 Subject: [PATCH] chore: cleanup & shi - fix download folders not listing properly - fix error trying to sort folders with names having BIG numbers at the end - fix question mark in filename breaking downloads - fix download stuck sometimes (silly code mistake) - force thumbnail calculated scale to not exceed certain value - other useless small refactors --- .gitignore | 4 +- lib/controller/folders_controller.dart | 18 ++++---- lib/controller/json_to_history_parser.dart | 18 ++++---- .../waveform_extractor_windows.dart | 5 ++- lib/controller/waveform_controller.dart | 4 +- .../controller/youtube_controller.dart | 4 +- .../functions/video_download_options.dart | 5 +-- pubspec.yaml | 2 +- .../flutter/generated_plugin_registrant.cc | 41 ------------------- windows/flutter/generated_plugin_registrant.h | 15 ------- windows/flutter/generated_plugins.cmake | 33 --------------- 11 files changed, 35 insertions(+), 114 deletions(-) delete mode 100644 windows/flutter/generated_plugin_registrant.cc delete mode 100644 windows/flutter/generated_plugin_registrant.h delete mode 100644 windows/flutter/generated_plugins.cmake diff --git a/.gitignore b/.gitignore index fd9a6ee35..fc444c966 100644 --- a/.gitignore +++ b/.gitignore @@ -56,4 +56,6 @@ chlog_hash.dart temp_changelog.md temp_changelog_hash.md test.dart -CHANGELOG_pretty.txt \ No newline at end of file +CHANGELOG_pretty.txt + +windows/flutter/generated_** \ No newline at end of file diff --git a/lib/controller/folders_controller.dart b/lib/controller/folders_controller.dart index 5c57c099f..f87dbed7b 100644 --- a/lib/controller/folders_controller.dart +++ b/lib/controller/folders_controller.dart @@ -194,19 +194,23 @@ class Folders { } if (charCodes.isNotEmpty) { final startIndex = codes.length - charCodes.length; - return _ParsedResult( - extractedNumber: int.parse(String.fromCharCodes(charCodes.reversed)), - charactersCount: charCodes.length, - startAtIndex: startIndex, - textPart: text.substring(0, startIndex), - ); + try { + return _ParsedResult( + extractedNumber: num.parse(String.fromCharCodes(charCodes.reversed)), + charactersCount: charCodes.length, + startAtIndex: startIndex, + textPart: text.substring(0, startIndex), + ); + } catch (_) { + // -- big numbers and format exception + } } return null; } } class _ParsedResult { - final int extractedNumber; + final num extractedNumber; final int charactersCount; final int startAtIndex; final String textPart; diff --git a/lib/controller/json_to_history_parser.dart b/lib/controller/json_to_history_parser.dart index 38e140ea0..ed73c6b97 100644 --- a/lib/controller/json_to_history_parser.dart +++ b/lib/controller/json_to_history_parser.dart @@ -439,10 +439,12 @@ class JsonToHistoryParser { HistoryController.inst.updateMostPlayedPlaylist(); // -- youtube history -- - YoutubeHistoryController.inst.removeDuplicatedItems(datesAddedYoutube); - YoutubeHistoryController.inst.sortHistoryTracks(datesAddedYoutube); - await YoutubeHistoryController.inst.saveHistoryToStorage(datesAddedYoutube); - YoutubeHistoryController.inst.updateMostPlayedPlaylist(); + if (datesAddedYoutube.isNotEmpty) { + YoutubeHistoryController.inst.removeDuplicatedItems(datesAddedYoutube); + YoutubeHistoryController.inst.sortHistoryTracks(datesAddedYoutube); + await YoutubeHistoryController.inst.saveHistoryToStorage(datesAddedYoutube); + YoutubeHistoryController.inst.updateMostPlayedPlaylist(); + } isParsing.value = false; @@ -597,8 +599,8 @@ class JsonToHistoryParser { if (isMatchingTypeLink) { tracksIdsMap = >{}; allTracks.loop((trMap) { - String? videoId = NamidaLinkUtils.extractYoutubeId(trMap['comment'] as String); - videoId ??= NamidaLinkUtils.extractYoutubeId(trMap['filename'] as String); + String? videoId = NamidaLinkUtils.extractYoutubeId(trMap['comment'] as String? ?? ''); + videoId ??= NamidaLinkUtils.extractYoutubeId(trMap['filename'] as String? ?? ''); if (videoId != null && videoId.isNotEmpty) { tracksIdsMap!.addForce(videoId, Track.decide(trMap['path'], trMap['v'])); } @@ -767,8 +769,8 @@ class JsonToHistoryParser { Iterable tracks = []; if (tracksIdsMap != null) { - final match = tracksIdsMap[vh.id] ?? []; - if (match.isNotEmpty) { + final match = tracksIdsMap[vh.id]; + if (match != null && match.isNotEmpty) { tracks = matchAll ? match : [match.first]; } } diff --git a/lib/controller/platform/waveform_extractor/waveform_extractor_windows.dart b/lib/controller/platform/waveform_extractor/waveform_extractor_windows.dart index 1499a83f2..d983e0e9b 100644 --- a/lib/controller/platform/waveform_extractor/waveform_extractor_windows.dart +++ b/lib/controller/platform/waveform_extractor/waveform_extractor_windows.dart @@ -7,7 +7,10 @@ class _WaveformExtractorWindows extends WaveformExtractor { late String ffmpegExePath; late String waveformExePath; - static const _supportedFormats = {'wav', 'flac', 'mp3', 'ogg', 'opus', 'webm'}; + static const _supportedFormats = { + 'wav', 'flac', 'mp3', 'ogg', 'opus', 'webm', // + 'WAV', 'FLAC', 'MP3', 'OGG', 'OPUS', 'WEBM', + }; @override void init() { diff --git a/lib/controller/waveform_controller.dart b/lib/controller/waveform_controller.dart index 7e17f8493..88f25a56e 100644 --- a/lib/controller/waveform_controller.dart +++ b/lib/controller/waveform_controller.dart @@ -109,8 +109,8 @@ class WaveformController { final dynamicScale = _currentScaleMap[posInMap] ?? 0.01; final intensity = settings.animatingThumbnailIntensity.value; final finalScale = dynamicScale * intensity * 0.00005; - - return finalScale.isNaN ? 0.01 : finalScale; + if (finalScale.isNaN || finalScale > 0.3) return 0.01; + return finalScale; } final _waveformExtractor = WaveformExtractor.platform()..init(); diff --git a/lib/youtube/controller/youtube_controller.dart b/lib/youtube/controller/youtube_controller.dart index a038fd5b1..1d626a9e9 100644 --- a/lib/youtube/controller/youtube_controller.dart +++ b/lib/youtube/controller/youtube_controller.dart @@ -310,7 +310,7 @@ class YoutubeController { } } - static const String cleanupFilenameRegex = r'[*#\$|/\\!^:"]'; + static const String cleanupFilenameRegex = r'[*#\$|/\\!^:"\?]'; String cleanupFilename(String filename) => filename.replaceAll(RegExp(cleanupFilenameRegex, caseSensitive: false), '_'); // -- things here are not refreshed. should be called in startup only. @@ -582,7 +582,7 @@ class YoutubeController { latestEditedGroupDownloadTask[groupName] = DateTime.now().millisecondsSinceEpoch; } - final _completersVAI = >{}; + final _completersVAI = >{}; Future downloadYoutubeVideos({ required List itemsConfig, diff --git a/lib/youtube/functions/video_download_options.dart b/lib/youtube/functions/video_download_options.dart index ff8ae1bbe..6068b45f1 100644 --- a/lib/youtube/functions/video_download_options.dart +++ b/lib/youtube/functions/video_download_options.dart @@ -2,7 +2,6 @@ import 'dart:io'; import 'package:flutter/material.dart'; -import 'package:namida/class/file_parts.dart'; import 'package:namida/controller/ffmpeg_controller.dart'; import 'package:namida/controller/navigator_controller.dart'; import 'package:namida/controller/settings_controller.dart'; @@ -288,7 +287,7 @@ class YTDownloadOptionFolderListTileState extends State=3.4.0 <4.0.0" diff --git a/windows/flutter/generated_plugin_registrant.cc b/windows/flutter/generated_plugin_registrant.cc deleted file mode 100644 index 96666f909..000000000 --- a/windows/flutter/generated_plugin_registrant.cc +++ /dev/null @@ -1,41 +0,0 @@ -// -// Generated file. Do not edit. -// - -// clang-format off - -#include "generated_plugin_registrant.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -void RegisterPlugins(flutter::PluginRegistry* registry) { - ConnectivityPlusWindowsPluginRegisterWithRegistrar( - registry->GetRegistrarForPlugin("ConnectivityPlusWindowsPlugin")); - DynamicColorPluginCApiRegisterWithRegistrar( - registry->GetRegistrarForPlugin("DynamicColorPluginCApi")); - FlutterJsPluginRegisterWithRegistrar( - registry->GetRegistrarForPlugin("FlutterJsPlugin")); - FlutterUdidPluginCApiRegisterWithRegistrar( - registry->GetRegistrarForPlugin("FlutterUdidPluginCApi")); - FlutterVolumeControllerPluginCApiRegisterWithRegistrar( - registry->GetRegistrarForPlugin("FlutterVolumeControllerPluginCApi")); - JustAudioWindowsPluginRegisterWithRegistrar( - registry->GetRegistrarForPlugin("JustAudioWindowsPlugin")); - PermissionHandlerWindowsPluginRegisterWithRegistrar( - registry->GetRegistrarForPlugin("PermissionHandlerWindowsPlugin")); - SharePlusWindowsPluginCApiRegisterWithRegistrar( - registry->GetRegistrarForPlugin("SharePlusWindowsPluginCApi")); - Sqlite3FlutterLibsPluginRegisterWithRegistrar( - registry->GetRegistrarForPlugin("Sqlite3FlutterLibsPlugin")); - UrlLauncherWindowsRegisterWithRegistrar( - registry->GetRegistrarForPlugin("UrlLauncherWindows")); -} diff --git a/windows/flutter/generated_plugin_registrant.h b/windows/flutter/generated_plugin_registrant.h deleted file mode 100644 index dc139d85a..000000000 --- a/windows/flutter/generated_plugin_registrant.h +++ /dev/null @@ -1,15 +0,0 @@ -// -// Generated file. Do not edit. -// - -// clang-format off - -#ifndef GENERATED_PLUGIN_REGISTRANT_ -#define GENERATED_PLUGIN_REGISTRANT_ - -#include - -// Registers Flutter plugins. -void RegisterPlugins(flutter::PluginRegistry* registry); - -#endif // GENERATED_PLUGIN_REGISTRANT_ diff --git a/windows/flutter/generated_plugins.cmake b/windows/flutter/generated_plugins.cmake deleted file mode 100644 index 797872b82..000000000 --- a/windows/flutter/generated_plugins.cmake +++ /dev/null @@ -1,33 +0,0 @@ -# -# Generated file, do not edit. -# - -list(APPEND FLUTTER_PLUGIN_LIST - connectivity_plus - dynamic_color - flutter_js - flutter_udid - flutter_volume_controller - just_audio_windows - permission_handler_windows - share_plus - sqlcipher_flutter_libs - url_launcher_windows -) - -list(APPEND FLUTTER_FFI_PLUGIN_LIST -) - -set(PLUGIN_BUNDLED_LIBRARIES) - -foreach(plugin ${FLUTTER_PLUGIN_LIST}) - add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/windows plugins/${plugin}) - target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin) - list(APPEND PLUGIN_BUNDLED_LIBRARIES $) - list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) -endforeach(plugin) - -foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST}) - add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/windows plugins/${ffi_plugin}) - list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries}) -endforeach(ffi_plugin)