mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-13 16:05:18 +00:00
Integrated duration matching into authentic and popular algorithms
- Integrated duration matching into authentic and popular algorithms - Removed duration matching option
This commit is contained in:
parent
0fce2c6347
commit
b2f20d458d
@ -316,10 +316,6 @@ class Settings extends HookConsumerWidget {
|
|||||||
),
|
),
|
||||||
value: SpotubeTrackMatchAlgorithm.popular,
|
value: SpotubeTrackMatchAlgorithm.popular,
|
||||||
),
|
),
|
||||||
DropdownMenuItem(
|
|
||||||
child: Text("Match Song Duration"),
|
|
||||||
value: SpotubeTrackMatchAlgorithm.duration,
|
|
||||||
),
|
|
||||||
DropdownMenuItem(
|
DropdownMenuItem(
|
||||||
child: Text("YouTube's Top choice"),
|
child: Text("YouTube's Top choice"),
|
||||||
value: SpotubeTrackMatchAlgorithm.youtube,
|
value: SpotubeTrackMatchAlgorithm.youtube,
|
||||||
|
@ -10,8 +10,6 @@ enum SpotubeTrackMatchAlgorithm {
|
|||||||
popular,
|
popular,
|
||||||
// selects the most popular one from the author of the track
|
// selects the most popular one from the author of the track
|
||||||
authenticPopular,
|
authenticPopular,
|
||||||
// selects song that most closely matches the actual song's duration
|
|
||||||
duration,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class SpotubeTrack extends Track {
|
class SpotubeTrack extends Track {
|
||||||
|
@ -382,25 +382,7 @@ class Playback extends PersistedChangeNotifier {
|
|||||||
} else {
|
} else {
|
||||||
VideoSearchList videos =
|
VideoSearchList videos =
|
||||||
await raceMultiple(() => youtube.search.search(queryString));
|
await raceMultiple(() => youtube.search.search(queryString));
|
||||||
|
if (matchAlgorithm != SpotubeTrackMatchAlgorithm.youtube) {
|
||||||
if (matchAlgorithm == SpotubeTrackMatchAlgorithm.duration) {
|
|
||||||
//Actual duration of desired song
|
|
||||||
int targetDuration = track.duration!.inSeconds;
|
|
||||||
//start with the first result
|
|
||||||
Video bestVideoMatch = videos[0];
|
|
||||||
int minDurationDifference =
|
|
||||||
(targetDuration - videos[0].duration!.inSeconds).abs();
|
|
||||||
//Check if any other results are closer to the actual song duration and prefer those
|
|
||||||
for (int i = 1; i < videos.length; i++) {
|
|
||||||
int durationDifference =
|
|
||||||
(targetDuration - videos[i].duration!.inSeconds).abs();
|
|
||||||
if (durationDifference < minDurationDifference) {
|
|
||||||
minDurationDifference = durationDifference;
|
|
||||||
bestVideoMatch = videos[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ytVideo = bestVideoMatch;
|
|
||||||
} else if (matchAlgorithm != SpotubeTrackMatchAlgorithm.youtube) {
|
|
||||||
List<Map> ratedRankedVideos = videos
|
List<Map> ratedRankedVideos = videos
|
||||||
.map((video) {
|
.map((video) {
|
||||||
// the find should be lazy thus everything case insensitive
|
// the find should be lazy thus everything case insensitive
|
||||||
@ -416,6 +398,10 @@ class Playback extends PersistedChangeNotifier {
|
|||||||
|
|
||||||
final bool hasNoLiveInTitle =
|
final bool hasNoLiveInTitle =
|
||||||
!PrimitiveUtils.containsTextInBracket(ytTitle, "live");
|
!PrimitiveUtils.containsTextInBracket(ytTitle, "live");
|
||||||
|
final bool hasCloseDuration =
|
||||||
|
(track.duration!.inSeconds - video.duration!.inSeconds)
|
||||||
|
.abs() <=
|
||||||
|
10; //Duration matching threshold
|
||||||
|
|
||||||
int rate = 0;
|
int rate = 0;
|
||||||
for (final el in [
|
for (final el in [
|
||||||
@ -425,12 +411,14 @@ class Playback extends PersistedChangeNotifier {
|
|||||||
SpotubeTrackMatchAlgorithm.authenticPopular)
|
SpotubeTrackMatchAlgorithm.authenticPopular)
|
||||||
authorIsArtist,
|
authorIsArtist,
|
||||||
hasNoLiveInTitle,
|
hasNoLiveInTitle,
|
||||||
|
hasCloseDuration,
|
||||||
!video.isLive,
|
!video.isLive,
|
||||||
]) {
|
]) {
|
||||||
if (el) rate++;
|
if (el) rate++;
|
||||||
}
|
}
|
||||||
// can't let pass any non title matching track
|
// can't let pass any non title matching track
|
||||||
if (!hasTitle) rate = rate - 2;
|
if (!hasTitle) rate = rate - 2;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"video": video,
|
"video": video,
|
||||||
"points": rate,
|
"points": rate,
|
||||||
|
Loading…
Reference in New Issue
Block a user