]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/xminus.py
[ie/orf:on] Improve extraction (#9677)
[yt-dlp.git] / yt_dlp / extractor / xminus.py
CommitLineData
81028ff9 1import re
51762e1a 2import time
81028ff9 3
1cdedfee 4from .common import InfoExtractor
be64b5b0 5from ..compat import (
be64b5b0
PH
6 compat_ord,
7)
8from ..utils import (
9 int_or_none,
51762e1a 10 parse_duration,
be64b5b0 11)
1cdedfee 12
13
14class XMinusIE(InfoExtractor):
df773c3d 15 _WORKING = False
1cdedfee 16 _VALID_URL = r'https?://(?:www\.)?x-minus\.org/track/(?P<id>[0-9]+)'
17 _TEST = {
18 'url': 'http://x-minus.org/track/4542/%D0%BF%D0%B5%D1%81%D0%B5%D0%BD%D0%BA%D0%B0-%D1%88%D0%BE%D1%84%D0%B5%D1%80%D0%B0.html',
19 'md5': '401a15f2d2dcf6d592cb95528d72a2a8',
20 'info_dict': {
21 'id': '4542',
22 'ext': 'mp3',
51762e1a 23 'title': 'Леонид Агутин-Песенка шофёра',
1cdedfee 24 'duration': 156,
be64b5b0
PH
25 'tbr': 320,
26 'filesize_approx': 5900000,
27 'view_count': int,
81028ff9 28 'description': 'md5:03238c5b663810bc79cf42ef3c03e371',
1cdedfee 29 }
30 }
31
32 def _real_extract(self, url):
33 video_id = self._match_id(url)
1cdedfee 34 webpage = self._download_webpage(url, video_id)
be64b5b0 35
1cdedfee 36 artist = self._html_search_regex(
51762e1a 37 r'<a[^>]+href="/artist/\d+">([^<]+)</a>', webpage, 'artist')
1cdedfee 38 title = artist + '-' + self._html_search_regex(
51762e1a
YCH
39 r'<span[^>]+class="minustrack-full-title(?:\s+[^"]+)?"[^>]*>([^<]+)', webpage, 'title')
40 duration = parse_duration(self._html_search_regex(
41 r'<span[^>]+class="player-duration(?:\s+[^"]+)?"[^>]*>([^<]+)',
be64b5b0 42 webpage, 'duration', fatal=False))
51762e1a
YCH
43 mobj = re.search(
44 r'<div[^>]+class="dw-info(?:\s+[^"]+)?"[^>]*>(?P<tbr>\d+)\s*кбит/c\s+(?P<filesize>[0-9.]+)\s*мб</div>',
45 webpage)
46 tbr = filesize_approx = None
47 if mobj:
48 filesize_approx = float(mobj.group('filesize')) * 1000000
49 tbr = float(mobj.group('tbr'))
be64b5b0 50 view_count = int_or_none(self._html_search_regex(
51762e1a 51 r'<span><[^>]+class="icon-chart-bar".*?>(\d+)</span>',
be64b5b0 52 webpage, 'view count', fatal=False))
81028ff9 53 description = self._html_search_regex(
51762e1a 54 r'(?s)<pre[^>]+id="lyrics-original"[^>]*>(.*?)</pre>',
81028ff9
PH
55 webpage, 'song lyrics', fatal=False)
56 if description:
57 description = re.sub(' *\r *', '\n', description)
be64b5b0 58
51762e1a
YCH
59 k = self._search_regex(
60 r'<div[^>]+id="player-bottom"[^>]+data-k="([^"]+)">', webpage,
61 'encoded data')
62 h = time.time() / 3600
63 a = sum(map(int, [compat_ord(c) for c in k])) + int(video_id) + h
64 video_url = 'http://x-minus.me/dl/minus?id=%s&tkn2=%df%d' % (video_id, a, h)
1cdedfee 65
66 return {
67 'id': video_id,
68 'title': title,
be64b5b0 69 'url': video_url,
51762e1a
YCH
70 # The extension is unknown until actual downloading
71 'ext': 'mp3',
1cdedfee 72 'duration': duration,
be64b5b0
PH
73 'filesize_approx': filesize_approx,
74 'tbr': tbr,
75 'view_count': view_count,
81028ff9 76 'description': description,
1cdedfee 77 }