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()
|
||||
song_list = mk.cache.get_custom_track([])
|
||||
print(mk.cache, len(song_list))
|
||||
#recording/694bfd3c-9d2d-4d67-9bfc-cee5bf77166e
|
||||
id_="694bfd3c-9d2d-4d67-9bfc-cee5bf77166e"
|
||||
id_="5cc28584-10c6-40e2-b6d4-6891e7e7c575"
|
||||
mk.fetch_metadata(id_=id_, type_="recording")
|
||||
|
||||
song = mk.cache.get_track_metadata(musicbrainz_releasetrackid=id_)
|
||||
print(song)
|
||||
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
|
||||
MAX_TRIES = 3
|
||||
|
||||
def youtube_length_to_mp3_length(youtube_len: float) -> int:
|
||||
return int(youtube_len * 1000)
|
||||
|
||||
|
||||
class Youtube(AudioSource):
|
||||
@classmethod
|
||||
@ -31,7 +34,8 @@ class Youtube(AudioSource):
|
||||
|
||||
return [{
|
||||
'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]
|
||||
|
||||
@classmethod
|
||||
@ -51,8 +55,10 @@ class Youtube(AudioSource):
|
||||
match, distance = phonetic_compares.match_titles(video_title, real_title)
|
||||
|
||||
if match:
|
||||
# logger.warning(
|
||||
# f"dont downloading {result['url']} cuz the phonetic distance ({distance}) between {real_title} and {video_title} is to high.")
|
||||
continue
|
||||
|
||||
if not phonetic_compares.match_length(song.length, result['length']):
|
||||
logger.warning(f"{song.length} doesn't match with {result}")
|
||||
continue
|
||||
|
||||
final_result = result
|
||||
|
@ -4,6 +4,8 @@ import string
|
||||
TITLE_THRESHOLD_LEVENSHTEIN = 1
|
||||
UNIFY_TO = " "
|
||||
|
||||
ALLOWED_LENGTH_DISTANCE = 20
|
||||
|
||||
|
||||
def unify_punctuation(to_unify: str) -> str:
|
||||
for char in string.punctuation:
|
||||
@ -46,3 +48,6 @@ def match_artists(artist_1, artist_2: str):
|
||||
distances.append(distance)
|
||||
return True, min(distances)
|
||||
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