-
-
Save Refffy/3540689539e4cfcda779035fbf521b84 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from yandex_music import Client | |
import io | |
import subprocess | |
import requests | |
client = Client.from_token('') | |
def extract_direct_link_to_track(track_id): | |
track = client.tracks(track_id)[0] | |
track_download_info = track.get_download_info() | |
is_track_suitable = lambda info: all([ | |
info.codec == "mp3", | |
info.bitrate_in_kbps == 192 | |
]) | |
for info in track_download_info: | |
if is_track_suitable(info): | |
return info.get_direct_link() | |
def get_track_as_blob_by_url(url: str): | |
with requests.Session() as session: | |
with session.get(url) as res: | |
yield res.content | |
def get_memcached_track(blob_data): | |
cmd = [ | |
'ffmpeg', | |
'-i', 'pipe:', | |
'-acodec', 'libmp3lame', | |
'-f', 'mp3', | |
'lol.mp3' | |
] | |
with io.BytesIO(next(blob_data)) as blob: | |
blob.seek(0) | |
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stdin=subprocess.PIPE) | |
process.communicate(input=blob.read()) | |
process.wait() | |
if __name__ == '__main__': | |
url = extract_direct_link_to_track(37971706) | |
blob = get_track_as_blob_by_url(url) | |
get_memcached_track(blob) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment