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
This commit is contained in:
Kingkor Roy Tirtho 2022-05-02 23:06:17 +06:00
parent 3b7f7785b6
commit c0e2a21765
4 changed files with 66 additions and 38 deletions

View File

@ -200,6 +200,9 @@ class Home extends HookConsumerWidget {
statusBarColor: brightness == Brightness.dark statusBarColor: brightness == Brightness.dark
? Colors.blueGrey[900] ? Colors.blueGrey[900]
: Colors.white, // status bar color : Colors.white, // status bar color
statusBarIconBrightness: brightness == Brightness.dark
? Brightness.light
: Brightness.dark,
), ),
); );
return null; return null;

View File

@ -46,15 +46,32 @@ class PlayerView extends HookConsumerWidget {
final PaletteColor paletteColor = usePaletteColor(context, albumArt); final PaletteColor paletteColor = usePaletteColor(context, albumArt);
final brightness = Theme.of(context).brightness;
useEffect(() { useEffect(() {
SystemChrome.setSystemUIOverlayStyle( SystemChrome.setSystemUIOverlayStyle(
SystemUiOverlayStyle( SystemUiOverlayStyle(
statusBarColor: paletteColor.color, // status bar color statusBarColor: paletteColor.color, // status bar color
), ),
); );
return null; return;
}, [paletteColor.color]); }, [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( return SafeArea(
child: Scaffold( child: Scaffold(
appBar: const PageWindowTitleBar( appBar: const PageWindowTitleBar(

View File

@ -102,7 +102,8 @@ Future<List?> searchSong(
"id": val["result"]["id"], "id": val["result"]["id"],
"full_title": val["result"]["full_title"], "full_title": val["result"]["full_title"],
"albumArt": val["result"]["song_art_image_url"], "albumArt": val["result"]["song_art_image_url"],
"url": val["result"]["url"] "url": val["result"]["url"],
"author": val["result"]["primary_artist"]["name"],
}; };
}).toList(); }).toList();
return results; return results;
@ -128,23 +129,33 @@ Future<String?> getLyrics(
authHeader: authHeader, authHeader: authHeader,
); );
if (results == null) return null; if (results == null) return null;
final worthyOne = results title = getTitle(
.map((result) { title,
artists: artists,
onlyCleanArtist: true,
).trim();
final ratedLyrics = results.map((result) {
final gTitle = (result["full_title"] as String).toLowerCase(); final gTitle = (result["full_title"] as String).toLowerCase();
int points = 0; int points = 0;
final hasTitle = gTitle.contains(title.toLowerCase()); final hasTitle = gTitle.contains(title);
final hasAllArtists = final hasAllArtists =
artists.every((artist) => gTitle.contains(artist.toLowerCase())); 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]) { for (final criteria in [
hasTitle,
hasAllArtists,
fromOriginalAuthor,
]) {
if (criteria) points++; if (criteria) points++;
} }
return {"result": result, "points": points}; return {"result": result, "points": points};
}) }).sorted(
.sorted( (a, b) => ((a["points"] as int).compareTo(a["points"] as int)),
(a, b) => ((b["points"] as int).compareTo(a["points"] as int)), );
) final worthyOne = ratedLyrics.first["result"];
.first["result"];
String? lyrics = await extractLyrics(Uri.parse(worthyOne["url"])); String? lyrics = await extractLyrics(Uri.parse(worthyOne["url"]));
return lyrics; return lyrics;

View File

@ -37,39 +37,36 @@ Future<SpotubeTrack> toSpotubeTrack(
// the find should be lazy thus everything case insensitive // the find should be lazy thus everything case insensitive
final ytTitle = video.title.toLowerCase(); final ytTitle = video.title.toLowerCase();
final bool hasTitle = ytTitle.contains(title); final bool hasTitle = ytTitle.contains(title);
final bool hasYtTitle = title.contains(ytTitle);
final bool hasAllArtists = track.artists?.every( final bool hasAllArtists = track.artists?.every(
(artist) => ytTitle.contains(artist.name!.toLowerCase()), (artist) => ytTitle.contains(artist.name!.toLowerCase()),
) ?? ) ??
false; false;
final bool authorIsArtist = track.artists?.any((artist) { final bool authorIsArtist = track.artists?.first.name?.toLowerCase() ==
return artist.name?.toLowerCase() == video.author.toLowerCase(); video.author.toLowerCase();
}) ??
false;
final bool hasNoLive = !containsTextInBracket(ytTitle, "live"); final bool hasNoLiveInTitle = !containsTextInBracket(ytTitle, "live");
final bool hasOfficialVideo = [
"(official video)",
"[official video]",
"(official music video)",
"[official music video]"
].any((v) => ytTitle.contains(v));
final bool hasOfficialAudio = [ // final bool hasOfficialVideo = [
"[official audio]", // "(official video)",
"(official audio)", // "[official video]",
].any((v) => ytTitle.contains(v)); // "(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; int rate = 0;
for (final el in [ for (final el in [
hasTitle, hasTitle,
hasYtTitle,
hasAllArtists, hasAllArtists,
authorIsArtist, authorIsArtist,
hasNoLive, hasNoLiveInTitle,
!video.isLive, !video.isLive,
hasOfficialAudio, // hasOfficialVideo,
hasOfficialVideo, // hasOfficialAudio,
]) { ]) {
if (el) rate++; if (el) rate++;
} }