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:
Demizo 2022-09-03 12:29:23 -05:00
parent 0fce2c6347
commit b2f20d458d
3 changed files with 7 additions and 25 deletions

View File

@ -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,

View File

@ -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 {

View File

@ -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,