mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-13 07:55:18 +00:00
feat: better track matching on youtube API
This commit is contained in:
parent
02fa54ae89
commit
904a0d3e15
@ -4,10 +4,16 @@ import 'package:spotify/spotify.dart';
|
|||||||
import 'package:spotube/extensions/album_simple.dart';
|
import 'package:spotube/extensions/album_simple.dart';
|
||||||
import 'package:spotube/extensions/artist_simple.dart';
|
import 'package:spotube/extensions/artist_simple.dart';
|
||||||
import 'package:spotube/models/matched_track.dart';
|
import 'package:spotube/models/matched_track.dart';
|
||||||
|
import 'package:spotube/provider/user_preferences_provider.dart';
|
||||||
import 'package:spotube/services/youtube/youtube.dart';
|
import 'package:spotube/services/youtube/youtube.dart';
|
||||||
import 'package:spotube/utils/service_utils.dart';
|
import 'package:spotube/utils/service_utils.dart';
|
||||||
import 'package:collection/collection.dart';
|
import 'package:collection/collection.dart';
|
||||||
|
|
||||||
|
final officialMusicRegex = RegExp(
|
||||||
|
r"official\s(video|audio|music\svideo)",
|
||||||
|
caseSensitive: false,
|
||||||
|
);
|
||||||
|
|
||||||
class SpotubeTrack extends Track {
|
class SpotubeTrack extends Track {
|
||||||
final YoutubeVideoInfo ytTrack;
|
final YoutubeVideoInfo ytTrack;
|
||||||
final String ytUri;
|
final String ytUri;
|
||||||
@ -65,19 +71,59 @@ class SpotubeTrack extends Track {
|
|||||||
final List<YoutubeVideoInfo> siblings =
|
final List<YoutubeVideoInfo> siblings =
|
||||||
await client.search("$title - ${artists.join(", ")}").then(
|
await client.search("$title - ${artists.join(", ")}").then(
|
||||||
(res) {
|
(res) {
|
||||||
final siblings = res
|
final isYoutubeApi =
|
||||||
.sorted((a, b) => b.views.compareTo(a.views))
|
client.preferences.youtubeApiType == YoutubeApiType.youtube;
|
||||||
.where((item) {
|
final siblings = isYoutubeApi ||
|
||||||
return artists.any(
|
client.preferences.searchMode == SearchMode.youtube
|
||||||
(artist) =>
|
? res
|
||||||
client.preferences.searchMode == SearchMode.youtube ||
|
.sorted((a, b) => b.views.compareTo(a.views))
|
||||||
artist.toLowerCase() == item.channelName.toLowerCase(),
|
.map((sibling) {
|
||||||
);
|
int score = 0;
|
||||||
})
|
|
||||||
.take(10)
|
|
||||||
.toList();
|
|
||||||
|
|
||||||
return siblings;
|
for (final artist in artists) {
|
||||||
|
final isSameChannelArtist =
|
||||||
|
sibling.channelName.toLowerCase() ==
|
||||||
|
artist.toLowerCase();
|
||||||
|
final channelContainsArtist = sibling.channelName
|
||||||
|
.toLowerCase()
|
||||||
|
.contains(artist.toLowerCase());
|
||||||
|
|
||||||
|
if (isSameChannelArtist || channelContainsArtist) {
|
||||||
|
score += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
final titleContainsArtist = sibling.title
|
||||||
|
.toLowerCase()
|
||||||
|
.contains(artist.toLowerCase());
|
||||||
|
|
||||||
|
if (titleContainsArtist) {
|
||||||
|
score += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sibling.title
|
||||||
|
.toLowerCase()
|
||||||
|
.contains(track.name!.toLowerCase())) {
|
||||||
|
score += 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (officialMusicRegex
|
||||||
|
.hasMatch(sibling.title.toLowerCase())) {
|
||||||
|
score += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (sibling: sibling, score: score);
|
||||||
|
})
|
||||||
|
.sorted((a, b) => b.score.compareTo(a.score))
|
||||||
|
.map((e) => e.sibling)
|
||||||
|
: res.sorted((a, b) => b.views.compareTo(a.views)).where((item) {
|
||||||
|
return artists.any(
|
||||||
|
(artist) =>
|
||||||
|
artist.toLowerCase() == item.channelName.toLowerCase(),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
return siblings.take(10).toList();
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user