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