Skip to content

Commit

Permalink
fix: thumbnail related cache files
Browse files Browse the repository at this point in the history
  • Loading branch information
MSOB7YY committed Jul 22, 2024
1 parent 995eba0 commit 867aac2
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
32 changes: 29 additions & 3 deletions lib/controller/thumbnail_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ class ThumbnailManager {
String? symlinkId,
bool isTemp = false,
}) {
final dirPrefix = isTemp ? 'temp/' : '';

final goodId = id != null && id.isNotEmpty;
if (goodId || type == ThumbnailType.video) {
String? filename;
Expand All @@ -51,9 +49,36 @@ class ThumbnailManager {
} else if (goodId) {
filename = '$id.png';
} else if (url != null) {
filename = url.splitLast('/').substring(0, 11); // custom urls like dAdjsaB_GKL_hqdefault.jpg
try {
int? indexStart;
final index1try = url.indexOf('/vi/shorts/');
if (index1try > -1) {
indexStart = index1try + 11; // '/vi/shorts/'.length
} else {
final index2try = url.indexOf('/vi/');
if (index2try > -1) {
indexStart = index2try + 4; // '/vi/'.length
}
}
if (indexStart != null) {
filename = url.substring(indexStart, indexStart + 11); // custom urls like dAdjsaB_GKL_hqdefault.jpg
} else {
// -- just a backup
bool isFirstMatch = false;
filename = url.splitLastM(
'/',
onMatch: (part) {
if (isFirstMatch) return part;
isFirstMatch = true;
return null;
},
);
}
isTemp = true;
} catch (_) {}
}
if (filename == null || filename.isEmpty) return null;
final dirPrefix = isTemp ? 'temp/' : '';
return File("${AppDirs.YT_THUMBNAILS}$dirPrefix$filename");
}
String? finalUrl = url;
Expand All @@ -65,6 +90,7 @@ class ThumbnailManager {
}

if (finalUrl != null) {
final dirPrefix = isTemp ? 'temp/' : '';
return File("${AppDirs.YT_THUMBNAILS_CHANNELS}$dirPrefix${symlinkId ?? finalUrl}");
}

Expand Down
2 changes: 2 additions & 0 deletions lib/youtube/widgets/yt_notification_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ class _YoutubeVideoCardNotificationState extends State<YoutubeVideoCardNotificat
key: ValueKey(videoThumbnail),
isImportantInCache: false,
customUrl: videoThumbnail,
videoId: widget.notification.id, // just as a backup
preferLowerRes: true,
width: thumbnailWidth,
height: thumbnailHeight,
borderRadius: 8.0,
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: 3.5.4-beta+240722218
version: 3.5.5-beta+240722218

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

0 comments on commit 867aac2

Please sign in to comment.