Skip to content

Commit

Permalink
chore: cleanup & shi
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
MSOB7YY committed Oct 27, 2024
1 parent d51ad94 commit 42ecb21
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 114 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,6 @@ chlog_hash.dart
temp_changelog.md
temp_changelog_hash.md
test.dart
CHANGELOG_pretty.txt
CHANGELOG_pretty.txt

windows/flutter/generated_**
18 changes: 11 additions & 7 deletions lib/controller/folders_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -194,19 +194,23 @@ class Folders<T extends Folder> {
}
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;
Expand Down
18 changes: 10 additions & 8 deletions lib/controller/json_to_history_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -597,8 +599,8 @@ class JsonToHistoryParser {
if (isMatchingTypeLink) {
tracksIdsMap = <String, List<Track>>{};
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']));
}
Expand Down Expand Up @@ -767,8 +769,8 @@ class JsonToHistoryParser {
Iterable<Track> tracks = <Track>[];

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];
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ class _WaveformExtractorWindows extends WaveformExtractor {
late String ffmpegExePath;
late String waveformExePath;

static const _supportedFormats = <String>{'wav', 'flac', 'mp3', 'ogg', 'opus', 'webm'};
static const _supportedFormats = <String>{
'wav', 'flac', 'mp3', 'ogg', 'opus', 'webm', //
'WAV', 'FLAC', 'MP3', 'OGG', 'OPUS', 'WEBM',
};

@override
void init() {
Expand Down
4 changes: 2 additions & 2 deletions lib/controller/waveform_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions lib/youtube/controller/youtube_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -582,7 +582,7 @@ class YoutubeController {
latestEditedGroupDownloadTask[groupName] = DateTime.now().millisecondsSinceEpoch;
}

final _completersVAI = <YoutubeItemDownloadConfig, Completer<VideoStreamsResult>>{};
final _completersVAI = <YoutubeItemDownloadConfig, Completer<VideoStreamsResult?>>{};

Future<void> downloadYoutubeVideos({
required List<YoutubeItemDownloadConfig> itemsConfig,
Expand Down
5 changes: 2 additions & 3 deletions lib/youtube/functions/video_download_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -288,7 +287,7 @@ class YTDownloadOptionFolderListTileState extends State<YTDownloadOptionFolderLi
int rootFiles = 0;
Directory(AppDirs.YOUTUBE_DOWNLOADS).listSyncSafe().loop((d) {
if (d is Directory) {
availableDirectoriesNames[d.path.getDirectoryName] = 0;
availableDirectoriesNames[d.path.splitLast(Platform.pathSeparator)] = 0;
} else {
rootFiles++;
}
Expand All @@ -312,7 +311,7 @@ class YTDownloadOptionFolderListTileState extends State<YTDownloadOptionFolderLi
void onFolderAdd(String name) {
onGroupNameChanged(name);
try {
availableDirectoriesNames[name] = Directory(FileParts.joinPath(AppDirs.YOUTUBE_DOWNLOADS, name)).listSyncSafe().length; // prolly 0 but eghh maybe edge cases
availableDirectoriesNames[name] = 0;
} catch (_) {}
widget.onDownloadFolderAdded?.call(name);
}
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.6.06-beta+241027216
version: 4.6.1-beta+241027217

environment:
sdk: ">=3.4.0 <4.0.0"
Expand Down
41 changes: 0 additions & 41 deletions windows/flutter/generated_plugin_registrant.cc

This file was deleted.

15 changes: 0 additions & 15 deletions windows/flutter/generated_plugin_registrant.h

This file was deleted.

33 changes: 0 additions & 33 deletions windows/flutter/generated_plugins.cmake

This file was deleted.

0 comments on commit 42ecb21

Please sign in to comment.