mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-13 07:55: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,
|
||||
),
|
||||
DropdownMenuItem(
|
||||
child: Text("Match Song Duration"),
|
||||
value: SpotubeTrackMatchAlgorithm.duration,
|
||||
),
|
||||
DropdownMenuItem(
|
||||
child: Text("YouTube's Top choice"),
|
||||
value: SpotubeTrackMatchAlgorithm.youtube,
|
||||
|
@ -10,8 +10,6 @@ enum SpotubeTrackMatchAlgorithm {
|
||||
popular,
|
||||
// selects the most popular one from the author of the track
|
||||
authenticPopular,
|
||||
// selects song that most closely matches the actual song's duration
|
||||
duration,
|
||||
}
|
||||
|
||||
class SpotubeTrack extends Track {
|
||||
|
@ -382,25 +382,7 @@ class Playback extends PersistedChangeNotifier {
|
||||
} else {
|
||||
VideoSearchList videos =
|
||||
await raceMultiple(() => youtube.search.search(queryString));
|
||||
|
||||
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) {
|
||||
if (matchAlgorithm != SpotubeTrackMatchAlgorithm.youtube) {
|
||||
List<Map> ratedRankedVideos = videos
|
||||
.map((video) {
|
||||
// the find should be lazy thus everything case insensitive
|
||||
@ -416,6 +398,10 @@ class Playback extends PersistedChangeNotifier {
|
||||
|
||||
final bool hasNoLiveInTitle =
|
||||
!PrimitiveUtils.containsTextInBracket(ytTitle, "live");
|
||||
final bool hasCloseDuration =
|
||||
(track.duration!.inSeconds - video.duration!.inSeconds)
|
||||
.abs() <=
|
||||
10; //Duration matching threshold
|
||||
|
||||
int rate = 0;
|
||||
for (final el in [
|
||||
@ -425,12 +411,14 @@ class Playback extends PersistedChangeNotifier {
|
||||
SpotubeTrackMatchAlgorithm.authenticPopular)
|
||||
authorIsArtist,
|
||||
hasNoLiveInTitle,
|
||||
hasCloseDuration,
|
||||
!video.isLive,
|
||||
]) {
|
||||
if (el) rate++;
|
||||
}
|
||||
// can't let pass any non title matching track
|
||||
if (!hasTitle) rate = rate - 2;
|
||||
|
||||
return {
|
||||
"video": video,
|
||||
"points": rate,
|
||||
|
Loading…
Reference in New Issue
Block a user