added checking against lenth for youtube videos
This commit is contained in:
parent
87f4e66148
commit
6b79d6a6ae
@ -4,10 +4,14 @@ print(mk.__file__)
|
|||||||
mk.clear_cache()
|
mk.clear_cache()
|
||||||
song_list = mk.cache.get_custom_track([])
|
song_list = mk.cache.get_custom_track([])
|
||||||
print(mk.cache, len(song_list))
|
print(mk.cache, len(song_list))
|
||||||
#recording/694bfd3c-9d2d-4d67-9bfc-cee5bf77166e
|
|
||||||
id_="694bfd3c-9d2d-4d67-9bfc-cee5bf77166e"
|
id_="694bfd3c-9d2d-4d67-9bfc-cee5bf77166e"
|
||||||
|
id_="5cc28584-10c6-40e2-b6d4-6891e7e7c575"
|
||||||
mk.fetch_metadata(id_=id_, type_="recording")
|
mk.fetch_metadata(id_=id_, type_="recording")
|
||||||
|
|
||||||
song = mk.cache.get_track_metadata(musicbrainz_releasetrackid=id_)
|
song = mk.cache.get_track_metadata(musicbrainz_releasetrackid=id_)
|
||||||
print(song)
|
print(song)
|
||||||
print(song.length)
|
print(song.length)
|
||||||
|
mk.set_targets(genre="test")
|
||||||
|
|
||||||
|
song = mk.cache.get_track_metadata(musicbrainz_releasetrackid=id_)
|
||||||
|
mk.fetch_sources([song])
|
||||||
|
@ -18,6 +18,9 @@ YOUTUBE_TITLE_KEY = 'title'
|
|||||||
WAIT_BETWEEN_BLOCK = 10
|
WAIT_BETWEEN_BLOCK = 10
|
||||||
MAX_TRIES = 3
|
MAX_TRIES = 3
|
||||||
|
|
||||||
|
def youtube_length_to_mp3_length(youtube_len: float) -> int:
|
||||||
|
return int(youtube_len * 1000)
|
||||||
|
|
||||||
|
|
||||||
class Youtube(AudioSource):
|
class Youtube(AudioSource):
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -31,7 +34,8 @@ class Youtube(AudioSource):
|
|||||||
|
|
||||||
return [{
|
return [{
|
||||||
'url': video[YOUTUBE_URL_KEY],
|
'url': video[YOUTUBE_URL_KEY],
|
||||||
'title': video[YOUTUBE_TITLE_KEY]
|
'title': video[YOUTUBE_TITLE_KEY],
|
||||||
|
'length': youtube_length_to_mp3_length(float(videos[0]['duration']))
|
||||||
} for video in videos]
|
} for video in videos]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -51,8 +55,10 @@ class Youtube(AudioSource):
|
|||||||
match, distance = phonetic_compares.match_titles(video_title, real_title)
|
match, distance = phonetic_compares.match_titles(video_title, real_title)
|
||||||
|
|
||||||
if match:
|
if match:
|
||||||
# logger.warning(
|
continue
|
||||||
# f"dont downloading {result['url']} cuz the phonetic distance ({distance}) between {real_title} and {video_title} is to high.")
|
|
||||||
|
if not phonetic_compares.match_length(song.length, result['length']):
|
||||||
|
logger.warning(f"{song.length} doesn't match with {result}")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
final_result = result
|
final_result = result
|
||||||
|
@ -4,6 +4,8 @@ import string
|
|||||||
TITLE_THRESHOLD_LEVENSHTEIN = 1
|
TITLE_THRESHOLD_LEVENSHTEIN = 1
|
||||||
UNIFY_TO = " "
|
UNIFY_TO = " "
|
||||||
|
|
||||||
|
ALLOWED_LENGTH_DISTANCE = 20
|
||||||
|
|
||||||
|
|
||||||
def unify_punctuation(to_unify: str) -> str:
|
def unify_punctuation(to_unify: str) -> str:
|
||||||
for char in string.punctuation:
|
for char in string.punctuation:
|
||||||
@ -46,3 +48,6 @@ def match_artists(artist_1, artist_2: str):
|
|||||||
distances.append(distance)
|
distances.append(distance)
|
||||||
return True, min(distances)
|
return True, min(distances)
|
||||||
return match_titles(artist_1, artist_2)
|
return match_titles(artist_1, artist_2)
|
||||||
|
|
||||||
|
def match_length(length_1: int, length_2: int) -> bool:
|
||||||
|
return abs(length_1 - length_2) <= ALLOWED_LENGTH_DISTANCE
|
||||||
|
Loading…
Reference in New Issue
Block a user