mirror of
https://github.com/Alexander-D-Karpov/akarpov
synced 2024-11-22 00:26:36 +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)
|
return str(song)
|
||||||
|
|
||||||
|
|
||||||
def load_playlist(link: str, user_id: int):
|
def load_url(link: str, user_id: int):
|
||||||
author = link.split("/")[4]
|
|
||||||
playlist_id = link.split("/")[-1]
|
|
||||||
|
|
||||||
client = login()
|
client = login()
|
||||||
playlist = client.users_playlists(int(playlist_id), author) # type: Playlist
|
if "/playlists/" in link:
|
||||||
for track in playlist.fetch_tracks():
|
author = link.split("/")[4]
|
||||||
|
playlist_id = link.split("/")[-1]
|
||||||
|
|
||||||
|
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(
|
tasks.load_ym_file_meta.apply_async(
|
||||||
kwargs={"track": track.track.id, "user_id": user_id}
|
kwargs={"track": track_id, "user_id": user_id}
|
||||||
)
|
)
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
logger = structlog.get_logger(__name__)
|
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):
|
def list_tracks(url, user_id):
|
||||||
if "music.youtube.com" in url or "youtu.be" in url:
|
if "music.youtube.com" in url or "youtu.be" in url:
|
||||||
url = url.replace("music.youtube.com", "youtube.com")
|
url = url.replace("music.youtube.com", "youtube.com")
|
||||||
|
@ -37,7 +37,7 @@ def list_tracks(url, user_id):
|
||||||
if "spotify.com" in url:
|
if "spotify.com" in url:
|
||||||
spotify.download_url(url, user_id)
|
spotify.download_url(url, user_id)
|
||||||
elif "music.yandex.ru" in url:
|
elif "music.yandex.ru" in url:
|
||||||
yandex.load_playlist(url, user_id)
|
yandex.load_url(url, user_id)
|
||||||
if "youtube.com" in url:
|
if "youtube.com" in url:
|
||||||
if "channel" in url or "/c/" in url:
|
if "channel" in url or "/c/" in url:
|
||||||
ytmusic = ytmusicapi.YTMusic()
|
ytmusic = ytmusicapi.YTMusic()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user