{"id":308185,"date":"2020-08-08T15:00:26","date_gmt":"2020-08-08T15:00:26","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=308185"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=308185","title":{"rendered":"\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f offline \u0440\u0435\u0436\u0438\u043c\u0430 \u0434\u043b\u044f Yandex.Music"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/514342\/\">\n<h1 id=\"vvedenie\">\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h1>\n<p>  <\/p>\n<p>\u0421\u0435\u0433\u043e\u0434\u043d\u044f \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u0442\u0430\u043a\u043e\u0439 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0439 \u043c\u0443\u0437\u044b\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0438\u0441, \u043a\u0430\u043a Yandex.Music. \u0425\u043e\u0440\u043e\u0448\u0438\u0439 \u0432 \u0446\u0435\u043b\u043e\u043c \u0441\u0435\u0440\u0432\u0438\u0441, \u043d\u043e \u0441 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u043e\u043c \u2014 \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c\u044e \u0440\u0430\u0431\u043e\u0442\u044b \u043e\u0444\u0444\u043b\u0430\u0439\u043d. \u041c\u044b \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u044d\u0442\u043e \u0434\u043e\u0441\u0430\u0434\u043d\u043e\u0435 \u043d\u0435\u0434\u043e\u0440\u0430\u0437\u0443\u043c\u0435\u043d\u0438\u0435, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043f\u043e\u0434\u0440\u0443\u0447\u043d\u044b\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b.<\/p>\n<p>  <\/p>\n<h1 id=\"instrumentariy\">\u0418\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0439<\/h1>\n<p>  <\/p>\n<p>\u0418\u0442\u0430\u043a, \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u041e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u0432\u0435\u0436\u0438\u0439 <a href=\"https:\/\/www.python.org\/downloads\/\">python<\/a>: 3.7 \u0438 \u0432\u044b\u0448\u0435<\/li>\n<li>\u0412\u0441\u044f\u043a\u0430\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0449\u0438\u043d\u0430: <a href=\"https:\/\/docs.aiohttp.org\">aiohttp<\/a> \u0438 <a href=\"https:\/\/pypi.org\/project\/aiofile\/\">aiofile<\/a><\/li>\n<li>\u041a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 html-API: <a href=\"https:\/\/www.crummy.com\/software\/BeautifulSoup\/bs4\/doc\/\">BeautifulSoup<\/a><\/li>\n<li>\u0414\u043b\u044f \u0440\u0430\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430: <a href=\"https:\/\/tqdm.github.io\/\">tqdm<\/a><\/li>\n<li>\u0414\u043b\u044f \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0442\u044d\u0433\u043e\u0432: <a href=\"https:\/\/mutagen.readthedocs.io\">mutagen<\/a><\/li>\n<\/ul>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<h1 id=\"avtorizaciya\">\u0410\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f<\/h1>\n<p>  <\/p>\n<p>\u041d\u0435\u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0442\u0440\u0435\u0437\u043a\u0438 \u043f\u0435\u0441\u0435\u043d \u0434\u043b\u0438\u043d\u043d\u043e\u0439 \u0434\u043e 30 \u0441\u0435\u043a\u0443\u043d\u0434. \u042d\u0442\u043e\u0433\u043e \u044f\u0432\u043d\u043e \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0434\u043b\u044f \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0441\u043b\u0443\u0448\u0438\u0432\u0430\u043d\u0438\u044f. \u0410\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0441\u0430\u043c\u044b\u043c \u0447\u0442\u043e \u043d\u0438 \u043d\u0430 \u0435\u0441\u0442\u044c \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c, \u0447\u0435\u0440\u0435\u0437 \u0432\u0435\u0431-\u0444\u043e\u0440\u043c\u0443 \u0441 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435\u043c \u043f\u0435\u0447\u0435\u043d\u044e\u0448\u0435\u043a. \u0412 \u044d\u0442\u043e\u043c \u043d\u0430\u043c \u043f\u043e\u043c\u043e\u0436\u0435\u0442 <a href=\"https:\/\/docs.python.org\/3\/library\/urllib.request.html#urllib.request.OpenerDirector\">opener<\/a> \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0438 <a href=\"https:\/\/docs.python.org\/3\/library\/html.parser.html\">HTMLParser<\/a> \u0434\u043b\u044f \u043f\u0430\u0440\u0441\u0438\u043d\u0433\u0430 \u0444\u043e\u0440\u043c.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">def resolve_cookie(login: str, password: str) -&gt; str:     cookies = CookieJar()     opener = urllib.request.build_opener(         urllib.request.HTTPCookieProcessor(cookies),         urllib.request.HTTPRedirectHandler())     response = opener.open(&quot;https:\/\/passport.yandex.ru&quot;)     doc = response.read()     parser = FormParser()     parser.feed(doc.decode(&quot;utf-8&quot;))     parser.close()     parser.params[&quot;login&quot;] = login     response = opener.open(parser.url or response.url, urllib.parse.urlencode(parser.params).encode(&quot;utf-8&quot;))     doc = response.read()     parser = FormParser()     parser.feed(doc.decode(&quot;utf-8&quot;))     parser.close()     parser.params[&quot;login&quot;] = login     parser.params[&quot;passwd&quot;] = password     response = opener.open(parser.url or response.url, urllib.parse.urlencode(parser.params).encode(&quot;utf-8&quot;))     cookie_data = {}     for item in cookies:         if item.domain == &quot;.yandex.ru&quot;:             cookie_data[item.name] = item.value     if &quot;yandex_login&quot; not in cookie_data:         keys = &quot;, &quot;.join(cookie_data.keys())         raise Exception(f&quot;Invalid cookie_data {keys}&quot;)     return &quot;; &quot;.join(map(lambda v: f&quot;{v[0]}={v[1]}&quot;, cookie_data.items()))<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u043e \u0430\u0434\u0440\u0435\u0441\u0443 <code>https:\/\/passport.yandex.ru<\/code> \u043d\u0430\u0441 \u043e\u0436\u0438\u0434\u0430\u0435\u0442 \u043f\u0435\u0440\u0432\u0430\u044f \u0444\u043e\u0440\u043c\u0430 \u0441 \u043f\u043e\u043b\u0435\u043c <code>login<\/code>. \u0415\u0441\u043b\u0438 \u0431\u0443\u0434\u0435\u0442 \u0443\u043a\u0430\u0437\u0430\u043d \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0439 \u043b\u043e\u0433\u0438\u043d, \u0442\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0444\u043e\u0440\u043c\u0430 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0438\u0442 \u0432\u0432\u0435\u0441\u0442\u0438 \u043f\u0430\u0440\u043e\u043b\u044c, \u0447\u0442\u043e \u043c\u044b \u043d\u0435\u0437\u0430\u043c\u0435\u0434\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0435\u043c. \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0444\u043e\u0440\u043c\u044b \u043d\u0430\u0441 \u043e\u0441\u043e\u0431\u043e \u043d\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442. \u041d\u0430\u0448\u0430 \u0446\u0435\u043b\u044c \u2014 \u043a\u0443\u043a\u0438\u0441\u044b. \u0415\u0441\u043b\u0438 \u0441\u0440\u0435\u0434\u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u044b\u0445 \u043a\u0443\u043a \u043e\u043a\u0430\u0436\u0435\u0442\u0441\u044f <code>yandex_login<\/code>, \u0442\u043e \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u0440\u043e\u0448\u043b\u0430 \u0443\u0441\u043f\u0435\u0448\u043d\u043e. \u0412\u0430\u0440\u0438\u0430\u043d\u0442 \u0441 \u0434\u0432\u0443\u0445\u0444\u0430\u043a\u0442\u043e\u0440\u043d\u043e\u0439 \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0435\u0439 \u043c\u044b \u043f\u043e\u043a\u0430 \u043d\u0435 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u043c.<\/p>\n<p>  <\/p>\n<h1 id=\"yandex-music-html-api\">Yandex Music (HTML) API<\/h1>\n<p>  <\/p>\n<p>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043d\u0430\u0448\u0438\u043c \u0448\u0430\u0433\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0441\u043f\u0438\u0441\u043a\u0430 \u0438\u0437\u0431\u0440\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u0435\u0439. \u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u043d\u0430\u0448 \u0441\u0442\u0438\u043b\u044c \u0438 \u043c\u043e\u043b\u043e\u0434\u0451\u0436\u043d\u043e\u0441\u0442\u044c, \u0434\u043b\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c <a href=\"https:\/\/docs.aiohttp.org\">aiohttp<\/a>. \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 html \u0440\u0430\u0441\u043f\u0430\u0440\u0441\u0438\u043c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/www.crummy.com\/software\/BeautifulSoup\/bs4\/doc\/\">BeautifulSoup<\/a>. \u042d\u0442\u043e \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u0440\u0435\u0431\u044f\u0442\u0430, \u0437\u0430\u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0432 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0438 \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430 \u0441 \u0447\u0443\u0436\u0438\u0445 \u0432\u0435\u0431-\u0441\u0442\u0440\u0430\u043d\u0438\u0446.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">class YandexMusicApi:     host = &quot;music.yandex.ru&quot;     base_url = f&quot;https:\/\/{host}&quot;      def __init__(self, cookie: str):         self.headers = Headers(self.host, cookie)      async def _request(self, end_point: str):         async with aiohttp.ClientSession() as session:             url = f&quot;{self.base_url}\/{end_point}&quot;             async with session.request(method=&quot;GET&quot;, url=url) as response:                 return await response.read()      async def get_favorite_artists(self, login: str) -&gt; List[Artist]:         body = await self._request(f&quot;users\/{login}\/artists&quot;)         soup = BeautifulSoup(body, &quot;lxml&quot;)         artists_soup = soup.find(&quot;div&quot;, class_=&quot;page-users__artists&quot;)         if artists_soup is None:             caption = soup.find(&quot;div&quot;, class_=&quot;page-users__caption&quot;)             if caption:                 raise Exception(caption.contents[0])         result = []         for artist_soup in artists_soup.find_all(&quot;div&quot;, class_=&quot;artist&quot;):             title_soup = artist_soup.find(&quot;div&quot;, class_=&quot;artist__name&quot;)             title = title_soup.attrs[&quot;title&quot;]             title_href_soup = title_soup.find(&quot;a&quot;)             id_ = int(title_href_soup.attrs[&quot;href&quot;].split(&quot;\/&quot;)[-1])             result.append(Artist(id_, title))         return result<\/code><\/pre>\n<p>  <\/p>\n<p>\u0417\u0434\u0435\u0441\u044c \u0432\u0441\u0451 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e, \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 <code>https:\/\/music.yandex.ru\/users\/&lt;login&gt;\/artists<\/code> \u0432 \u0431\u043b\u043e\u043a\u0435 <code>page-users__artists<\/code> \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u0442\u0441\u044f \u0442\u0440\u0435\u0431\u0443\u0435\u043c\u044b\u0439 \u043d\u0430\u043c \u0441\u043f\u0438\u0441\u043e\u043a. \u0418\u043c\u044f \u0438\u0441\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044f \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u0442\u044c \u0432 \u0430\u0442\u0442\u0440\u0438\u0431\u0443\u0442\u0435 <code>title<\/code> \u0431\u043b\u043e\u043a\u0430 <code>artist__name<\/code>. Id \u0438\u0441\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044f \u043b\u0451\u0433\u043a\u0438\u043c \u0434\u0432\u0438\u0436\u0435\u043d\u0438\u0435\u043c <code>split<\/code> \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u0442\u0441\u044f \u0438\u0437 \u0430\u0434\u0440\u0435\u0441\u0430 \u0441\u0441\u044b\u043b\u043a\u0438.<br \/>  \u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0442 \u043d\u0430\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u043f\u0438\u0441\u043e\u043a \u0430\u043b\u044c\u0431\u043e\u043c\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044f, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0441\u043f\u0438\u0441\u043e\u043a \u0442\u0440\u0435\u043a\u043e\u0432 \u0432 \u0430\u043b\u044c\u0431\u043e\u043c\u0435.<\/p>\n<p>  <\/p>\n<h1 id=\"proniknovenie-v-hranilische\">\u041f\u0440\u043e\u043d\u0438\u043a\u043d\u043e\u0432\u0435\u043d\u0438\u0435 \u0432 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435<\/h1>\n<p>  <\/p>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043c\u0435\u0441\u0442\u0435 \u043c\u044b \u0443\u0436\u0435 \u043f\u043e\u0442\u0438\u0440\u0430\u0435\u043c \u043d\u0430\u0448\u0438 \u0448\u0430\u043b\u043e\u0432\u043b\u0438\u0432\u044b\u0435 \u0440\u0443\u0447\u043a\u0438 \u0432 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u0438 \u043f\u0440\u043e\u0441\u043b\u0443\u0448\u0438\u0432\u0430\u043d\u0438\u044f \u0441\u0432\u043e\u0435\u0439 \u043c\u0443\u0437\u044b\u043a\u0430\u043b\u044c\u043d\u043e\u0439 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438. \u041d\u043e \u0435\u0441\u043b\u0438 \u0431\u044b \u0432\u0441\u0451 \u0431\u044b\u043b\u043e \u0442\u0430\u043a \u043f\u0440\u043e\u0441\u0442\u043e, \u0442\u043e \u044f \u0431\u044b \u043d\u0435 \u043f\u0438\u0441\u0430\u043b \u044d\u0442\u0443 \u0441\u0442\u0430\u0442\u044c\u044e. \u041d\u0430\u0441 \u043e\u0436\u0438\u0434\u0430\u0435\u0442 \u043d\u043e\u0432\u044b\u0439 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u0438\u043a \u2014 yandex-\u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435. \u0414\u043b\u044f \u043f\u0440\u043e\u043d\u0438\u043a\u043d\u043e\u0432\u0435\u043d\u0438\u044f \u0432 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0432\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0441\u0442\u0438 \u0436\u043e\u043d\u0433\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u0441\u044b\u043b\u043a\u0430\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430\u0445 \u043c\u0443\u0437\u044b\u043a\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0440\u0435\u0441\u0443\u0440\u0441\u0430. \u041f\u0440\u0438 \u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u043c \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u0438 \u0432\u043a\u043b\u0430\u0434\u043a\u0438 <code>Network<\/code> \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u043d\u043e\u0433\u043e \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f \u0432\u044b\u044f\u0441\u043d\u0438\u043b\u043e\u0441\u044c, \u0447\u0442\u043e \u0432\u0441\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043b\u0435\u0433\u043a\u043e \u0432\u044b\u0432\u043e\u0434\u044f\u0442\u0441\u044f \u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u043e\u0434\u043d\u043e\u0433\u043e \u0443\u0447\u0430\u0441\u0442\u043a\u0430 \u0432 \u0430\u0434\u0440\u0435\u0441\u0435 <code>https:\/\/{host}\/get-mp3\/{sign}\/{ts}\/{path}<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0441\u043b\u0435 \u043d\u0435\u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0433\u0443\u0433\u043b\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u0443\u0447\u0438\u043b \u0438\u043c\u044f <code>sign<\/code>. \u0421\u043e\u043b\u044c \u0434\u043b\u044f \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u044b (<code>XGRlBW9FXlekgbPrRHuSiA<\/code>) \u0442\u043e\u0436\u0435 \u0431\u044b\u043b\u0430 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u0430 \u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u043e\u0440\u0430\u0445 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0430. \u0421\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e \u043d\u0435 \u0441\u043e\u0441\u0442\u0430\u0432\u0438\u0442 \u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u0442\u0440\u0443\u0434\u0430 \u0438\u0437\u0432\u043b\u0435\u0447\u044c \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438\u0437 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u043e\u0432 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b, \u043d\u043e \u044d\u0442\u043e \u0443\u0436\u0435 \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">    async def get_track_url(self, album_id: int, track_id: int) -&gt; str:         async with aiohttp.ClientSession() as session:             url = f&quot;{self.base_url}\/api\/v2.1\/handlers\/track\/{track_id}:{album_id}\/&quot; \\                   f&quot;web-album-track-track-main\/download\/m?hq=0&amp;external-domain={self.host}&amp;overembed=no&amp;__t={timestamp()}&quot;             page = f&quot;album\/{album_id}&quot;             headers = self.headers.build(page)             async with session.request(method=&quot;GET&quot;, url=url, headers=headers) as response:                 body = await response.json()                 src = body[&quot;src&quot;]                 src += f&quot;&amp;format=json&amp;external-domain={self.host}&amp;overembed=no&amp;__t={timestamp()}&quot;                 result = parse.urlparse(src)                 headers = self.headers.build(page, {                     &quot;:authority&quot;: &quot;storage.mds.yandex.net&quot;,                     &quot;:method&quot;: &quot;GET&quot;,                     &quot;:path&quot;: f&quot;{result.path}\/{result.query}&quot;,                     &quot;:scheme&quot;: &quot;https&quot;,                 }, True)                 async with session.request(method=&quot;GET&quot;, url=src, headers=headers) as response:                     body = await response.json()                     host = body[&quot;host&quot;]                     path = body[&quot;path&quot;]                     s = body[&quot;s&quot;]                     ts = body[&quot;ts&quot;]                     sign = md5(f&quot;XGRlBW9FXlekgbPrRHuSiA{path[1::]}{s}&quot;.encode(&quot;utf-8&quot;)).hexdigest()                     url = f&quot;https:\/\/{host}\/get-mp3\/{sign}\/{ts}\/{path}&quot;                     return url<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u0440\u0435\u043c\u044f \u0436\u0438\u0437\u043d\u0438 \u0441\u0441\u044b\u043b\u043a\u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043e, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0443\u0436\u043d\u043e \u043d\u0435\u0437\u0430\u043c\u0435\u0434\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043a \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u043d\u0438\u044e.<\/p>\n<p>  <\/p>\n<h1 id=\"skachivanie\">\u0421\u043a\u0430\u0447\u0438\u0432\u0430\u043d\u0438\u0435<\/h1>\n<p>  <\/p>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u0443\u0436\u0435 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043d\u0430\u0434\u043e\u0435\u0434\u0430\u0435\u0442 \u0432\u0441\u0451 \u044d\u0442\u043e \u0434\u0435\u043b\u043e, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0431\u0435\u0440\u0451\u043c \u0432 \u043e\u0434\u043d\u0443 \u0440\u0443\u043a\u0443 \u0440\u0430\u043d\u0435\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u043e\u0435 \u043d\u0430\u043c\u0438 <a href=\"https:\/\/docs.aiohttp.org\">aiohttp<\/a>, \u0432 \u0434\u0440\u0443\u0433\u0443\u044e \u2014 <a href=\"https:\/\/pypi.org\/project\/aiofile\/\">aiofile<\/a> \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u043d\u0438\u0435 \u0432 \u043b\u043e\u0431.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">    async def download_file(cls, url: str, filename: str):         async with aiohttp.ClientSession() as session:             async with session.request(method=&quot;GET&quot;, url=url) as response:                 data = await response.read()                 async with AIOFile(filename, &quot;wb&quot;) as afp:                     await afp.write(data)                     await afp.fsync()<\/code><\/pre>\n<p>  <\/p>\n<p>\u041e\u043f\u044b\u0442\u043d\u044b\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u044b \u043c\u043e\u0433\u0443\u0442 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0438\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u043d\u0438\u0435 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0431\u0443\u0444\u0435\u0440\u0430 \u0438 \u0437\u0430\u043f\u0438\u0441\u044c\u044e \u0432\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0439 \u0444\u0430\u0439\u043b. \u041d\u043e \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u044f, \u0447\u0442\u043e \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0440\u0430\u0437\u043c\u0435\u0440 mp3, \u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u0443\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u0443\u044e \u043f\u0430\u043c\u044f\u0442\u044c, \u0442\u043e \u043f\u0440\u0438 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0431\u044b\u0441\u0442\u0440\u043e\u043c \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0435 \u043c\u043e\u0436\u043d\u043e \u044d\u0442\u0438\u043c \u043d\u0435 \u0437\u0430\u043c\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0442\u044c\u0441\u044f. \u041b\u0430\u0434\u043d\u043e, \u043d\u0435 \u043d\u0430\u0434\u043e \u043a\u0438\u0434\u0430\u0442\u044c \u0432 \u043c\u0435\u043d\u044f \u043f\u043e\u0434\u0440\u0443\u0447\u043d\u044b\u043c\u0438 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0430\u043c\u0438, \u044f \u0432\u0441\u0451 \u043f\u043e\u043d\u044f\u043b. \u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u044d\u0442\u043e \u043e\u0434\u043d\u043e \u0438\u0437 \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0445 \u043c\u0435\u0441\u0442 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u0430\u0434\u0435\u043a\u0432\u0430\u0442\u043d\u043e\u043c\u0443 \u0432\u0438\u0434\u0443. \u0412 \u0438\u0434\u0435\u0430\u043b\u0435 \u0435\u0449\u0451 \u0441\u0442\u043e\u0438\u0442 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043f\u0440\u0438 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u043e\u0432\u0435\u043d\u0438\u0438 \u0441\u0435\u0442\u0435\u0432\u044b\u0445 \u043e\u0448\u0438\u0431\u043e\u043a.<\/p>\n<p>  <\/p>\n<h1 id=\"raskruchivaem-sharmanku\">\u0420\u0430\u0441\u043a\u0440\u0443\u0447\u0438\u0432\u0430\u0435\u043c \u0448\u0430\u0440\u043c\u0430\u043d\u043a\u0443<\/h1>\n<p>  <\/p>\n<p>\u0414\u0430\u043b\u0435\u0435, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0437\u0430\u043a\u0430\u0447\u043a\u0443 \u043d\u0430 \u043f\u043e\u0442\u043e\u043a. \u041c\u0435\u0442\u043e\u0434\u0438\u0447\u043d\u043e \u043f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u0435\u0439, \u0430\u043b\u044c\u0431\u043e\u043c\u044b, \u0442\u0440\u0435\u043a\u0438. \u0421\u043e\u0437\u0434\u0430\u0451\u043c \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438, \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u0430\u043b\u044c\u0431\u043e\u043c\u043d\u044b\u0439 \u0430\u0440\u0442, \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u0441\u0430\u043c\u0438 \u0442\u0440\u0435\u043a\u0438. \u041f\u0440\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0442\u044d\u0433\u0438 (\u043f\u043e\u0447\u0435\u043c\u0443-\u0442\u043e \u0443 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0445 mp3 \u043e\u043d\u0438 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u043b\u0438).<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">    async def download_artist(self, artist: Artist, depth: Depth = Depth.NORMAL):         artist_progress = tqdm(total=0, desc=artist.title, position=1, ascii=True)         albums = await self.api.get_artist_albums(artist.id)         artist_progress.total = len(albums)         artist_progress.refresh()         for album in albums:             album_dir = os.path.join(self.target_dir, normalize(artist.title), f&quot;{album.year} - {normalize(album.title)}&quot;)             if depth &lt; Depth.ALBUMS and os.path.exists(album_dir):                 artist_progress.update()                 continue             album_progress = tqdm(total=0, desc=f&quot;&gt; {album.title}&quot;, position=0, ascii=True)             tracks = await self.api.get_album_tracks(album.id)             album_progress.total = len(tracks)             album_progress.refresh()             os.makedirs(album_dir, exist_ok=True)             if album.cover:                 album_progress.total += 1                 cover_filename = os.path.join(album_dir, &quot;cover.jpg&quot;)                 if not os.path.exists(cover_filename):                     await self.download_file(album.cover, cover_filename)                 album_progress.update()             for track in tracks:                 target_filename = os.path.join(album_dir, f&quot;{track.num:02d}. {normalize(track.title)}.mp3&quot;)                 if depth &gt;= Depth.TRACKS or not os.path.exists(target_filename):                     url = await self.api.get_track_url(track.album_id, track.id)                     await self.download_file(url, target_filename)                     self.write_tags(target_filename, {                         &quot;title&quot;: track.title,                         &quot;tracknumber&quot;: str(track.num),                         &quot;artist&quot;: artist.title,                         &quot;album&quot;: album.title,                         &quot;date&quot;: str(album.year),                     })                 album_progress.update()             album_progress.close()             artist_progress.update()         artist_progress.close()<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u043f\u0435\u0440\u0432\u043e\u0439 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438, \u044f \u0441 \u0443\u0434\u0438\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u043b, \u0447\u0442\u043e \u043b\u044e\u0431\u0438\u043c\u0430\u044f \u043c\u043d\u043e\u044e \u0433\u0440\u0443\u043f\u043f\u0430 <code>AC\/DC<\/code> \u043e\u043a\u0430\u0437\u0430\u043b\u0430\u0441\u044c \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0430 \u043d\u0430 \u0434\u0432\u0435 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438. \u042d\u0442\u043e \u043f\u043e\u0441\u043b\u0443\u0436\u0438\u043b\u043e \u043f\u043e\u0432\u043e\u0434\u043e\u043c \u043a \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u0435\u0442\u043e\u0434\u0430 <code>normalize<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">def normalize(name: str) -&gt; str:     return name.replace(&quot;\/&quot;, &quot;-&quot;)<\/code><\/pre>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u043d\u0435\u0441\u043b\u043e\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c, \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u043d\u0438\u044f \u043c\u043e\u0436\u043d\u043e (\u0442\u043e\u0447\u043d\u0435\u0435 \u043d\u0443\u0436\u043d\u043e) \u0440\u0430\u0441\u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0442\u044c. \u041f\u043e\u0447\u0432\u0430 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d\u0430 \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u0434\u043b\u044f \u0441\u0435\u0442\u0435\u0432\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0438 \u0437\u0430\u043f\u0438\u0441\u0438 \u0432 \u0444\u0430\u0439\u043b\u044b. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <a href=\"https:\/\/docs.python.org\/3\/library\/asyncio-sync.html#asyncio.Semaphore\">asyncio.Semaphore<\/a> \u0432 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0438 \u0441 <a href=\"https:\/\/docs.python.org\/3\/library\/asyncio-task.html#running-tasks-concurrently\">asyncio.gather<\/a>.<br \/>  \u041d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0439 \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u0435\u0434\u043c\u0435\u0442\u043e\u043c \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u043e\u043a\u0430 \u0438 \u0442\u0430\u043a \u0441\u043e\u0439\u0434\u0451\u0442.<\/p>\n<p>  <\/p>\n<h1 id=\"zapusk\">\u0417\u0430\u043f\u0443\u0441\u043a<\/h1>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c, \u043a\u043e\u0433\u0434\u0430 \u0443 \u043d\u0430\u0441 \u0432\u0441\u0451 \u0443\u0436\u0435 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0433\u043e\u0442\u043e\u0432\u043e, \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u0434\u0443\u043c\u0430\u0442\u044c \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u044d\u0442\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c. \u042f\u0432\u043a\u0438 \u0438 \u043f\u0430\u0440\u043e\u043b\u0438 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0432\u044b\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u0438\u0437 \u0444\u0430\u0439\u043b\u0430 <code>.credentials<\/code>, \u043d\u0435\u043d\u0430\u0432\u044f\u0437\u0447\u0438\u0432\u043e \u0431\u0440\u043e\u0441\u0430\u044f \u044d\u043a\u0441\u0435\u043f\u0448\u0435\u043d \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0435\u0433\u043e \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u044f. \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u0443\u044e \u043a\u0443\u043a\u0443 \u0431\u0435\u0440\u0435\u0436\u043d\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043c \u0432 \u0444\u0430\u0439\u043b <code>.cookie<\/code> \u0434\u043b\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">def resolve_cookie() -&gt; str:     base_dir = os.path.normpath(os.path.join(os.path.dirname(__file__), os.path.pardir))     cookie_file = os.path.join(base_dir, &quot;.cookie&quot;)     if os.path.exists(cookie_file):         with open(cookie_file, &quot;rt&quot;) as file:             return file.read()     credentials_file = os.path.join(base_dir, &quot;.credentials&quot;)     if os.path.exists(credentials_file):         config = configparser.ConfigParser()         config.read(credentials_file)         login = config[&quot;yandex&quot;][&quot;login&quot;]         password = config[&quot;yandex&quot;][&quot;password&quot;]     else:         raise Exception(f&quot;&quot;&quot;Create \\&quot;{credentials_file}\\&quot; with content  [yandex] login=&lt;user_login&gt; password=&lt;user_password&gt; &quot;&quot;&quot;)     cookie = auth.resolve_cookie(login, password)     with open(cookie_file, &quot;wt&quot;) as file:         file.write(cookie)     return cookie<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043c\u0435\u0441\u0442\u0435 \u0441\u0442\u043e\u0438\u0442 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0443\u043a\u0440\u0430\u0441\u0438\u0442\u044c \u0436\u0438\u0437\u043d\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0432 \u0435\u043c\u0443 \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043c\u0443\u0437\u044b\u043a\u0430\u043b\u044c\u043d\u043e\u0439 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438, \u0430 \u0442\u0430\u043a \u0436\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u043d\u0438\u044f \u0442\u0440\u0435\u043a\u043e\u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044f. \u0414\u043b\u044f \u0440\u0430\u0437\u0431\u043e\u0440\u0430 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u043a\u043e\u043c\u0430\u043d\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 <a href=\"https:\/\/docs.python.org\/3\/library\/argparse.html\">argparse<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u043e\u0439 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438.<br \/>  \u041e\u043f\u0438\u0448\u0435\u043c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043e\u043f\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432:<\/p>\n<p>  <\/p>\n<ul>\n<li>-a (&#8212;artist), Id \u0438\u0441\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044f, \u0435\u0441\u043b\u0438 \u0443\u043a\u0430\u0437\u0430\u043d, \u0442\u043e \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0440\u0435\u043a\u0438 \u044d\u0442\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044f<\/li>\n<li>-o (&#8212;output), \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044f \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043c\u0443\u0437\u044b\u043a\u0430\u043b\u044c\u043d\u043e\u0439 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438, \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u2014 <code>Music<\/code> \u0432 \u0434\u043e\u043c\u0430\u0448\u043d\u0435\u0439 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<\/li>\n<li>-d (&#8212;depth), \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0440\u043e\u0434\u0438\u043b\u0441\u044f \u043a\u0430\u043a \u043a\u043e\u0441\u0442\u044b\u043b\u044c, \u0432\u044b\u0437\u0432\u0430\u043d\u043d\u044b\u0439 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u043c \u043f\u0440\u0435\u0440\u044b\u0432\u0430\u043d\u0438\u0435\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430<br \/> \n<ul>\n<li>\u041f\u0440\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0438 \u043f\u043e-\u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e <code>0 (NORMAL)<\/code> \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442\u0441\u044f \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 \u0441 \u0430\u043b\u044c\u0431\u043e\u043c\u043e\u043c, \u0438, \u0435\u0441\u043b\u0438 \u043e\u043d\u0430 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442, \u0442\u043e \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0430\u043b\u044c\u0431\u043e\u043c\u0430 \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f<\/li>\n<li>\u0417\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>1 (ALBUMS)<\/code> \u043f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0435\u0442 \u0432\u0441\u0435 \u0442\u0440\u0435\u043a\u0438 \u0432 \u0430\u043b\u044c\u0431\u043e\u043c\u0435 \u0438 \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u0435\u0442 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u044e\u0449\u0438\u0435<\/li>\n<li>\u0417\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>2 (TRACKS)<\/code> \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u0435\u0442 \u0438 \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u0442\u0440\u0435\u043a\u0438, \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u043e\u043d\u0438 \u0443\u0436\u0435 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u0432 \u0444\u0430\u0439\u043b\u043e\u0432\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>  <\/p>\n<pre><code class=\"python\">async def main():     parser = argparse.ArgumentParser()     parser.add_argument(&quot;-a&quot;, &quot;--artist&quot;, help=&quot;Artist ID&quot;)     parser.add_argument(&quot;-o&quot;, &quot;--output&quot;, default=f&quot;{Path.home()}\/Music&quot;,                         help=f&quot;Output directory, default {Path.home()}\/Music&quot;)     parser.add_argument(&quot;-d&quot;, &quot;--depth&quot;, default=0, type=int,                         help=f&quot;Exists files check depth, {enum_print(Depth)}&quot;)     args = parser.parse_args()     cookie = resolve_cookie()     api = YandexMusicApi(cookie)     agent = YandexMusicAgent(api, args.output)     if args.artist:         artist = await api.get_artist(args.artist)         await agent.download_artist(artist, args.depth)     else:         email = re.compile(&quot;.*?yandex_login=(.*?);.*?&quot;, re.M).match(cookie).group(1)         await agent.download_favorites(email, args.depth)<\/code><\/pre>\n<p>  <\/p>\n<p>\u0418 \u0432\u043e\u0442, \u043d\u0430\u043a\u043e\u043d\u0435\u0446-\u0442\u043e, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0432\u0441\u0451 \u044d\u0442\u043e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">if __name__ == &quot;__main__&quot;:     asyncio.run(main())<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435. \u0422\u0435\u043f\u0435\u0440\u044c \u0432\u044b \u0437\u043d\u0430\u0435\u0442\u0435, \u043a\u0430\u043a \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c API \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043d\u0435\u0442, \u0441\u043a\u0430\u0447\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u0430\u0447\u0438\u0432\u0430\u0435\u043c\u043e\u0435 \u0438 \u0441\u0442\u0430\u0442\u044c \u0441\u0447\u0430\u0441\u0442\u043b\u0438\u0432\u044b\u043c \u043e\u0431\u043b\u0430\u0434\u0430\u0442\u0435\u043b\u0435\u043c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0439 \u043c\u0443\u0437\u044b\u043a\u0430\u043b\u044c\u043d\u043e\u0439 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438.<\/p>\n<p>  <\/p>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0432 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438 <a href=\"https:\/\/bitbucket.org\/shmyga\/yandex.music.agent\">yandex.music.agent<\/a><\/p>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/514342\/\"> https:\/\/habr.com\/ru\/post\/514342\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/514342\/\">\n<h1 id=\"vvedenie\">\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h1>\n<p>  <\/p>\n<p>\u0421\u0435\u0433\u043e\u0434\u043d\u044f \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u0442\u0430\u043a\u043e\u0439 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0439 \u043c\u0443\u0437\u044b\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0438\u0441, \u043a\u0430\u043a Yandex.Music. \u0425\u043e\u0440\u043e\u0448\u0438\u0439 \u0432 \u0446\u0435\u043b\u043e\u043c \u0441\u0435\u0440\u0432\u0438\u0441, \u043d\u043e \u0441 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u043e\u043c \u2014 \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c\u044e \u0440\u0430\u0431\u043e\u0442\u044b \u043e\u0444\u0444\u043b\u0430\u0439\u043d. \u041c\u044b \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u044d\u0442\u043e \u0434\u043e\u0441\u0430\u0434\u043d\u043e\u0435 \u043d\u0435\u0434\u043e\u0440\u0430\u0437\u0443\u043c\u0435\u043d\u0438\u0435, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043f\u043e\u0434\u0440\u0443\u0447\u043d\u044b\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b.<\/p>\n<p>  <\/p>\n<h1 id=\"instrumentariy\">\u0418\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0439<\/h1>\n<p>  <\/p>\n<p>\u0418\u0442\u0430\u043a, \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u041e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u0432\u0435\u0436\u0438\u0439 <a href=\"https:\/\/www.python.org\/downloads\/\">python<\/a>: 3.7 \u0438 \u0432\u044b\u0448\u0435<\/li>\n<li>\u0412\u0441\u044f\u043a\u0430\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0449\u0438\u043d\u0430: <a href=\"https:\/\/docs.aiohttp.org\">aiohttp<\/a> \u0438 <a href=\"https:\/\/pypi.org\/project\/aiofile\/\">aiofile<\/a><\/li>\n<li>\u041a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 html-API: <a href=\"https:\/\/www.crummy.com\/software\/BeautifulSoup\/bs4\/doc\/\">BeautifulSoup<\/a><\/li>\n<li>\u0414\u043b\u044f \u0440\u0430\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430: <a href=\"https:\/\/tqdm.github.io\/\">tqdm<\/a><\/li>\n<li>\u0414\u043b\u044f \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0442\u044d\u0433\u043e\u0432: <a href=\"https:\/\/mutagen.readthedocs.io\">mutagen<\/a><\/li>\n<\/ul>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-308185","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/308185","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=308185"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/308185\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=308185"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=308185"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=308185"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}