From c0e2a217656c3ef09e791ebceb5b9ab94f345042 Mon Sep 17 00:00:00 2001 From: Kingkor Roy Tirtho Date: Mon, 2 May 2022 23:06:17 +0600 Subject: [PATCH] youtube search is now less official prone classic genius-lyrics selection improved [android] fixed status white icon in white bg & black icon in dark bg --- lib/components/Home/Home.dart | 3 ++ lib/components/Player/PlayerView.dart | 19 ++++++++++- lib/helpers/getLyrics.dart | 45 +++++++++++++++++---------- lib/helpers/search-youtube.dart | 37 ++++++++++------------ 4 files changed, 66 insertions(+), 38 deletions(-) diff --git a/lib/components/Home/Home.dart b/lib/components/Home/Home.dart index 40d984a0..b2052f1c 100644 --- a/lib/components/Home/Home.dart +++ b/lib/components/Home/Home.dart @@ -200,6 +200,9 @@ class Home extends HookConsumerWidget { statusBarColor: brightness == Brightness.dark ? Colors.blueGrey[900] : Colors.white, // status bar color + statusBarIconBrightness: brightness == Brightness.dark + ? Brightness.light + : Brightness.dark, ), ); return null; diff --git a/lib/components/Player/PlayerView.dart b/lib/components/Player/PlayerView.dart index 0d5893e5..eb66945b 100644 --- a/lib/components/Player/PlayerView.dart +++ b/lib/components/Player/PlayerView.dart @@ -46,15 +46,32 @@ class PlayerView extends HookConsumerWidget { final PaletteColor paletteColor = usePaletteColor(context, albumArt); + final brightness = Theme.of(context).brightness; + useEffect(() { SystemChrome.setSystemUIOverlayStyle( SystemUiOverlayStyle( statusBarColor: paletteColor.color, // status bar color ), ); - return null; + return; }, [paletteColor.color]); + useEffect(() { + return () { + SystemChrome.setSystemUIOverlayStyle( + SystemUiOverlayStyle( + statusBarColor: brightness == Brightness.dark + ? Colors.blueGrey[900] + : Colors.white, // status bar color + statusBarIconBrightness: brightness == Brightness.dark + ? Brightness.light + : Brightness.dark, + ), + ); + }; + }, []); + return SafeArea( child: Scaffold( appBar: const PageWindowTitleBar( diff --git a/lib/helpers/getLyrics.dart b/lib/helpers/getLyrics.dart index 26a36ec9..49adff9d 100644 --- a/lib/helpers/getLyrics.dart +++ b/lib/helpers/getLyrics.dart @@ -102,7 +102,8 @@ Future searchSong( "id": val["result"]["id"], "full_title": val["result"]["full_title"], "albumArt": val["result"]["song_art_image_url"], - "url": val["result"]["url"] + "url": val["result"]["url"], + "author": val["result"]["primary_artist"]["name"], }; }).toList(); return results; @@ -128,23 +129,33 @@ Future getLyrics( authHeader: authHeader, ); if (results == null) return null; - final worthyOne = results - .map((result) { - final gTitle = (result["full_title"] as String).toLowerCase(); - int points = 0; - final hasTitle = gTitle.contains(title.toLowerCase()); - final hasAllArtists = - artists.every((artist) => gTitle.contains(artist.toLowerCase())); + title = getTitle( + title, + artists: artists, + onlyCleanArtist: true, + ).trim(); + final ratedLyrics = results.map((result) { + final gTitle = (result["full_title"] as String).toLowerCase(); + int points = 0; + final hasTitle = gTitle.contains(title); + final hasAllArtists = + artists.every((artist) => gTitle.contains(artist.toLowerCase())); + final String lyricAuthor = result["author"].toLowerCase(); + final fromOriginalAuthor = + lyricAuthor.contains(artists.first.toLowerCase()); - for (var criteria in [hasTitle, hasAllArtists]) { - if (criteria) points++; - } - return {"result": result, "points": points}; - }) - .sorted( - (a, b) => ((b["points"] as int).compareTo(a["points"] as int)), - ) - .first["result"]; + for (final criteria in [ + hasTitle, + hasAllArtists, + fromOriginalAuthor, + ]) { + if (criteria) points++; + } + return {"result": result, "points": points}; + }).sorted( + (a, b) => ((a["points"] as int).compareTo(a["points"] as int)), + ); + final worthyOne = ratedLyrics.first["result"]; String? lyrics = await extractLyrics(Uri.parse(worthyOne["url"])); return lyrics; diff --git a/lib/helpers/search-youtube.dart b/lib/helpers/search-youtube.dart index bf2a602c..f5c414db 100644 --- a/lib/helpers/search-youtube.dart +++ b/lib/helpers/search-youtube.dart @@ -37,39 +37,36 @@ Future toSpotubeTrack( // the find should be lazy thus everything case insensitive final ytTitle = video.title.toLowerCase(); final bool hasTitle = ytTitle.contains(title); - final bool hasYtTitle = title.contains(ytTitle); final bool hasAllArtists = track.artists?.every( (artist) => ytTitle.contains(artist.name!.toLowerCase()), ) ?? false; - final bool authorIsArtist = track.artists?.any((artist) { - return artist.name?.toLowerCase() == video.author.toLowerCase(); - }) ?? - false; + final bool authorIsArtist = track.artists?.first.name?.toLowerCase() == + video.author.toLowerCase(); - final bool hasNoLive = !containsTextInBracket(ytTitle, "live"); - final bool hasOfficialVideo = [ - "(official video)", - "[official video]", - "(official music video)", - "[official music video]" - ].any((v) => ytTitle.contains(v)); + final bool hasNoLiveInTitle = !containsTextInBracket(ytTitle, "live"); - final bool hasOfficialAudio = [ - "[official audio]", - "(official audio)", - ].any((v) => ytTitle.contains(v)); + // final bool hasOfficialVideo = [ + // "(official video)", + // "[official video]", + // "(official music video)", + // "[official music video]" + // ].any((v) => ytTitle.contains(v)); + + // final bool hasOfficialAudio = [ + // "[official audio]", + // "(official audio)", + // ].any((v) => ytTitle.contains(v)); int rate = 0; for (final el in [ hasTitle, - hasYtTitle, hasAllArtists, authorIsArtist, - hasNoLive, + hasNoLiveInTitle, !video.isLive, - hasOfficialAudio, - hasOfficialVideo, + // hasOfficialVideo, + // hasOfficialAudio, ]) { if (el) rate++; }