mirror of
https://github.com/Alexander-D-Karpov/akarpov
synced 2024-11-21 23:16:33 +03:00
updated music fetching
This commit is contained in:
parent
2b2c16db2d
commit
00668b6f18
|
@ -75,13 +75,38 @@ def load_file_meta(track: int, user_id: int) -> str:
|
|||
return str(song)
|
||||
|
||||
|
||||
def load_playlist(link: str, user_id: int):
|
||||
def load_url(link: str, user_id: int):
|
||||
client = login()
|
||||
if "/playlists/" in link:
|
||||
author = link.split("/")[4]
|
||||
playlist_id = link.split("/")[-1]
|
||||
|
||||
client = login()
|
||||
playlist = client.users_playlists(int(playlist_id), author) # type: Playlist
|
||||
for track in playlist.fetch_tracks():
|
||||
tasks.load_ym_file_meta.apply_async(
|
||||
kwargs={"track": track.track.id, "user_id": user_id}
|
||||
)
|
||||
elif "/album/" in link:
|
||||
album_id = link.split("/")[-1]
|
||||
album = client.albums_with_tracks(int(album_id))
|
||||
tracks = []
|
||||
for volume in album.volumes:
|
||||
for track in volume:
|
||||
tracks.append(track)
|
||||
|
||||
for track in tracks:
|
||||
tasks.load_ym_file_meta.apply_async(
|
||||
kwargs={"track": track.track.id, "user_id": user_id}
|
||||
)
|
||||
elif "/artist/" in link:
|
||||
author = link.split("/")[-1]
|
||||
artist = client.artists([int(author)])[0]
|
||||
for track in artist.popular_tracks:
|
||||
tasks.load_ym_file_meta.apply_async(
|
||||
kwargs={"track": track.id, "user_id": user_id}
|
||||
)
|
||||
else:
|
||||
track_id = link.split("/")[-1]
|
||||
tasks.load_ym_file_meta.apply_async(
|
||||
kwargs={"track": track_id, "user_id": user_id}
|
||||
)
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
logger = structlog.get_logger(__name__)
|
||||
|
||||
|
||||
@shared_task(soft_time_limit=60 * 20, time_limit=60 * 30)
|
||||
@shared_task(soft_time_limit=60 * 60, time_limit=60 * 120)
|
||||
def list_tracks(url, user_id):
|
||||
if "music.youtube.com" in url or "youtu.be" in url:
|
||||
url = url.replace("music.youtube.com", "youtube.com")
|
||||
|
@ -37,7 +37,7 @@ def list_tracks(url, user_id):
|
|||
if "spotify.com" in url:
|
||||
spotify.download_url(url, user_id)
|
||||
elif "music.yandex.ru" in url:
|
||||
yandex.load_playlist(url, user_id)
|
||||
yandex.load_url(url, user_id)
|
||||
if "youtube.com" in url:
|
||||
if "channel" in url or "/c/" in url:
|
||||
ytmusic = ytmusicapi.YTMusic()
|
||||
|
|
Loading…
Reference in New Issue
Block a user