ytdl-org / youtube-dl

Command-line program to download videos from YouTube.com and other video sites
http://ytdl-org.github.io/youtube-dl/
The Unlicense
132.75k stars 10.07k forks source link

Yandex music returns only 30 seconds (with cookies provided) #30842

Open ant0nk opened 2 years ago

ant0nk commented 2 years ago

Checklist

Verbose log

.\youtube-dl.exe --rm-cache-dir --verbose --cookies ./yandex.ru_cookies.txt https://music.yandex.ru/album/9503961/track/61099558     [debug] System config: []
[debug] User config: []
[debug] Custom config: []
[debug] Command-line args: ['--rm-cache-dir', '--verbose', '--cookies', './yandex.ru_cookies.txt', 'https://music.yandex.ru/album/9503961/track/61099558']
[debug] Encodings: locale cp1251, fs mbcs, out cp866, pref cp1251
[debug] youtube-dl version 2021.12.17
[debug] Python version 3.4.4 (CPython) - Windows-10-10.0.19041
[debug] exe versions: none
[debug] Proxy map: {}
Removing cache dir C:\Users\User/.cache\youtube-dl ..
[yandexmusic:track] 61099558: Downloading track JSON
[yandexmusic:track] 61099558: Downloading track location url JSON
[yandexmusic:track] 61099558: Downloading track location JSON
[debug] Default format spec: best/bestvideo+bestaudio
[debug] Invoking downloader on 'http://s59iva.storage.yandex.net/get-mp3/02ce833e3bba62f06cb0207301402faa/0005dc4e986137ea/rmusic/U2FsdGVkX1-43sBjg4JTiPgKCzNiVTCog69b4EeHpTyTcjUIJ76ZdycmmUPtQRbG9Dh9Ip1zv8KVaS4dA59SG8sw7P6MFPD4D98JhKKjo-c/0319eb4aa7ad66c62923d55009f0deb46a82663868a84f424e0d763e8b28c753?track-id=61099558 '
[download] Destination: Галина Кузнецова, Мария Урбанович, Модест Петрович Мусоргский - Детская - III. Жук-61099558.mp3
[download] 100% of 469.84KiB in 00:00

Description

Attempt to download from Yandex music gives only 30 seconds even with cookies provided. Cookies file have proper format:

# Netscape HTTP Cookie File
# This file is generated by youtube-dl.  Do not edit.

.an.yandex.ru   TRUE    /   TRUE    0   yabs-dsp    criteo.***
***
dirkf commented 2 years ago

Presumably there is a preview track as well as the wanted track, and the extractor is incorrectly finding the first instead of the second.

Please use --write-pages, zip and attach.

ant0nk commented 2 years ago

Please find attached 61099558http-_storage.mds.yandex.net_file-download-info_1766897_d11315d5.90864038.5.61099558_previewformat=json_ts=6253b87d_sign=a29ee6e874a643f5c6e06c0786d82b163bd342c2c05365f91e356ac1830ff238.zip

nartes commented 2 years ago

https://music.yandex.com/api/v2.1/handlers/track/%s:%s/web-artist_tracks-track-track-saved/download/m there a bit different url, as well as, seems like using yandex.com provides full tracks, whilst yandex.ru provides only previews. not sure about cookies being useful here or not. but this fix makes it work for me. @ant0nk, @dirkf

Spaider commented 2 years ago

but this fix makes it work for me. @nartes I'm sorry but which fix are you referring to?

cndctr commented 1 year ago

@nartes I'm sorry but which fix are you referring to? Suppose, that changing to .com in url is that fix. Because neither .ru nor .by domains worked normally for me. After logging to music.yandex.com and using cookies I've finally got full tracks

dirkf commented 1 year ago

The dump shows this:

{
  's': '8281c523dc2d6608ceeb6903a083d93eb410ded7e451fa8bdb17924c12f84378',
  'ts': '0005dc5accde8223',
  'path': '/rmusic/U2FsdGVkX1-JUGfdZkhlizJD4ezmxa7Ct0GSiKV5hx30aGSA7W76LO8_hrcRtH6a_b9wV62vqk8b179F0K48NsbYbiDmtyE0Mkstaj1Jtg4/8281c523dc2d6608ceeb6903a083d93eb410ded7e451fa8bdb17924c12f84378',
  'host': 's59iva.storage.yandex.net'
}

And this:

{
  'codec': 'mp3',
  'bitrate': 128,
  'src': '//storage.mds.yandex.net/file-download-info/1766897_d11315d5.90864038.5.61099558/preview?sign=a29ee6e874a643f5c6e06c0786d82b163bd342c2c05365f91e356ac1830ff238&ts=6253b87d',
  'gain': false,
  'preview': true
}

Plus a JSON with artists data and data for track 61099558, but no media links.

I tried the proposed work-around but had 403 either way: maybe an account from --cookies ... is needed:

--- old/youtube_dl/extractor/yandexmusic.py
+++ new/youtube_dl/extractor/yandexmusic.py
@@ -118,7 +118,7 @@
         track_title = track['title']

         download_data = self._download_json(
-            'https://music.yandex.ru/api/v2.1/handlers/track/%s:%s/web-album_track-track-track-main/download/m' % (track_id, album_id),
+            'https://music.yandex.com/api/v2.1/handlers/track/%s:%s/web-artist_tracks-track-track-saved/download/m' % (track_id, album_id),
             track_id, 'Downloading track location url JSON',
             headers={'X-Retpath-Y': url})
amper128 commented 1 year ago
--- old/youtube_dl/extractor/yandexmusic.py
+++ new/youtube_dl/extractor/yandexmusic.py
@@ -114,7 +114,7 @@
         track_title = track['title']

         download_data = self._download_json(
-            'https://music.yandex.ru/api/v2.1/handlers/track/%s:%s/web-album_track-track-track-main/download/m' % (track_id, album_id),
+            'https://music.yandex.ru/api/v2.1/handlers/track/%s:%s/web-label_albums-album-track-fridge/download/m' % (track_id, album_id),
             track_id, 'Downloading track location url JSON', query={'hq': 1}, headers={'X-Retpath-Y': url})

         fd_data = self._download_json(

This patch works for me

dirkf commented 1 year ago

Cookie(s) required?

amper128 commented 1 year ago

Yes cookies requred. Without cookies only 30sec demo.