mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-13 07:55:18 +00:00
chore: use scoring for non-english tracks only
This commit is contained in:
parent
a05ddaeda1
commit
93f0db0196
@ -68,62 +68,64 @@ class SpotubeTrack extends Track {
|
|||||||
onlyCleanArtist: true,
|
onlyCleanArtist: true,
|
||||||
).trim();
|
).trim();
|
||||||
|
|
||||||
final List<YoutubeVideoInfo> siblings =
|
final query = "$title - ${artists.join(", ")}";
|
||||||
await client.search("$title - ${artists.join(", ")}").then(
|
final List<YoutubeVideoInfo> siblings = await client.search(query).then(
|
||||||
(res) {
|
(res) {
|
||||||
final isYoutubeApi =
|
final isYoutubeApi =
|
||||||
client.preferences.youtubeApiType == YoutubeApiType.youtube;
|
client.preferences.youtubeApiType == YoutubeApiType.youtube;
|
||||||
final siblings = isYoutubeApi ||
|
final siblings = isYoutubeApi ||
|
||||||
client.preferences.searchMode == SearchMode.youtube
|
client.preferences.searchMode == SearchMode.youtube
|
||||||
? res
|
? ServiceUtils.onlyContainsEnglish(query)
|
||||||
.sorted((a, b) => b.views.compareTo(a.views))
|
? res
|
||||||
.map((sibling) {
|
: res
|
||||||
int score = 0;
|
.sorted((a, b) => b.views.compareTo(a.views))
|
||||||
|
.map((sibling) {
|
||||||
|
int score = 0;
|
||||||
|
|
||||||
for (final artist in artists) {
|
for (final artist in artists) {
|
||||||
final isSameChannelArtist =
|
final isSameChannelArtist =
|
||||||
sibling.channelName.toLowerCase() ==
|
sibling.channelName.toLowerCase() ==
|
||||||
artist.toLowerCase();
|
artist.toLowerCase();
|
||||||
final channelContainsArtist = sibling.channelName
|
final channelContainsArtist = sibling.channelName
|
||||||
.toLowerCase()
|
.toLowerCase()
|
||||||
.contains(artist.toLowerCase());
|
.contains(artist.toLowerCase());
|
||||||
|
|
||||||
if (isSameChannelArtist || channelContainsArtist) {
|
if (isSameChannelArtist || channelContainsArtist) {
|
||||||
score += 1;
|
score += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
final titleContainsArtist = sibling.title
|
final titleContainsArtist = sibling.title
|
||||||
.toLowerCase()
|
.toLowerCase()
|
||||||
.contains(artist.toLowerCase());
|
.contains(artist.toLowerCase());
|
||||||
|
|
||||||
if (titleContainsArtist) {
|
if (titleContainsArtist) {
|
||||||
score += 1;
|
score += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final titleContainsTrackName = sibling.title
|
final titleContainsTrackName = sibling.title
|
||||||
.toLowerCase()
|
.toLowerCase()
|
||||||
.contains(track.name!.toLowerCase());
|
.contains(track.name!.toLowerCase());
|
||||||
|
|
||||||
final hasOfficialFlag =
|
final hasOfficialFlag = officialMusicRegex
|
||||||
officialMusicRegex.hasMatch(sibling.title.toLowerCase());
|
.hasMatch(sibling.title.toLowerCase());
|
||||||
|
|
||||||
if (titleContainsTrackName) {
|
if (titleContainsTrackName) {
|
||||||
score += 3;
|
score += 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasOfficialFlag) {
|
if (hasOfficialFlag) {
|
||||||
score += 1;
|
score += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasOfficialFlag && titleContainsTrackName) {
|
if (hasOfficialFlag && titleContainsTrackName) {
|
||||||
score += 2;
|
score += 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (sibling: sibling, score: score);
|
return (sibling: sibling, score: score);
|
||||||
})
|
})
|
||||||
.sorted((a, b) => b.score.compareTo(a.score))
|
.sorted((a, b) => b.score.compareTo(a.score))
|
||||||
.map((e) => e.sibling)
|
.map((e) => e.sibling)
|
||||||
: res.sorted((a, b) => b.views.compareTo(a.views)).where((item) {
|
: res.sorted((a, b) => b.views.compareTo(a.views)).where((item) {
|
||||||
return artists.any(
|
return artists.any(
|
||||||
(artist) =>
|
(artist) =>
|
||||||
|
@ -17,6 +17,13 @@ import 'package:html/parser.dart' as parser;
|
|||||||
abstract class ServiceUtils {
|
abstract class ServiceUtils {
|
||||||
static final logger = getLogger("ServiceUtils");
|
static final logger = getLogger("ServiceUtils");
|
||||||
|
|
||||||
|
static final _englishMatcherRegex = RegExp(
|
||||||
|
"^[a-zA-Z0-9\\s!\"#\$%&\\'()*+,-.\\/:;<=>?@\\[\\]^_`{|}~]*\$",
|
||||||
|
);
|
||||||
|
static bool onlyContainsEnglish(String text) {
|
||||||
|
return _englishMatcherRegex.hasMatch(text);
|
||||||
|
}
|
||||||
|
|
||||||
static String clearArtistsOfTitle(String title, List<String> artists) {
|
static String clearArtistsOfTitle(String title, List<String> artists) {
|
||||||
return title
|
return title
|
||||||
.replaceAll(RegExp(artists.join("|"), caseSensitive: false), "")
|
.replaceAll(RegExp(artists.join("|"), caseSensitive: false), "")
|
||||||
|
Loading…
Reference in New Issue
Block a user