@@ -43,6 +43,56 @@ final userPlaylists = ValueNotifier<List>(
4343final userCustomPlaylists = ValueNotifier <List >(
4444 Hive .box ('user' ).get ('customPlaylists' , defaultValue: []),
4545);
46+
47+ final customPlaylistsImageMigration = Future .microtask (() async {
48+ try {
49+ var needsPersist = false ;
50+ for (final playlist in userCustomPlaylists.value) {
51+ final songs = playlist['list' ];
52+ if (songs is ! List ) continue ;
53+ for (final song in songs) {
54+ if (song is ! Map ) continue ;
55+ final ytid = song['ytid' ]? .toString ();
56+ if (ytid == null || ytid.isEmpty) continue ;
57+
58+ final highRes = song['highResImage' ]? .toString () ?? '' ;
59+ final lowRes = song['lowResImage' ]? .toString () ?? '' ;
60+
61+ // A corrupted entry starts with '/' (absolute local path) or is
62+ // otherwise not an HTTP URL.
63+ final highResCorrupted =
64+ highRes.isNotEmpty && ! highRes.startsWith ('http' );
65+ final lowResCorrupted = lowRes.isNotEmpty && ! lowRes.startsWith ('http' );
66+
67+ if (highResCorrupted) {
68+ song['highResImage' ] =
69+ 'https://i.ytimg.com/vi/$ytid /maxresdefault.jpg' ;
70+ needsPersist = true ;
71+ }
72+ if (lowResCorrupted) {
73+ song['lowResImage' ] = 'https://i.ytimg.com/vi/$ytid /default.jpg' ;
74+ needsPersist = true ;
75+ }
76+ }
77+ }
78+
79+ if (needsPersist) {
80+ unawaited (
81+ addOrUpdateData ('user' , 'customPlaylists' , userCustomPlaylists.value),
82+ );
83+ logger.log (
84+ 'customPlaylistsImageMigration: repaired corrupted image URLs' ,
85+ );
86+ }
87+ } catch (e, st) {
88+ logger.log (
89+ 'Error migrating custom playlist image URLs' ,
90+ error: e,
91+ stackTrace: st,
92+ );
93+ }
94+ });
95+
4696List userLikedPlaylists = Hive .box (
4797 'user' ,
4898).get ('likedPlaylists' , defaultValue: []);
0 commit comments