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,14 +68,16 @@ 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
|
||||||
|
? ServiceUtils.onlyContainsEnglish(query)
|
||||||
? res
|
? res
|
||||||
|
: res
|
||||||
.sorted((a, b) => b.views.compareTo(a.views))
|
.sorted((a, b) => b.views.compareTo(a.views))
|
||||||
.map((sibling) {
|
.map((sibling) {
|
||||||
int score = 0;
|
int score = 0;
|
||||||
@ -105,8 +107,8 @@ class SpotubeTrack extends Track {
|
|||||||
.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;
|
||||||
|
@ -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