]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/radiojavan.py
[extractor] Deprecate `_sort_formats`
[yt-dlp.git] / yt_dlp / extractor / radiojavan.py
CommitLineData
7cf97daf
S
1import re
2
185a7e25 3from .common import InfoExtractor
6c83e583 4from ..utils import (
93284ff2 5 parse_resolution,
7cf97daf 6 str_to_int,
93284ff2 7 unified_strdate,
0a9a8118 8 urlencode_postdata,
93284ff2 9 urljoin,
185a7e25
MTP
10)
11
7cf97daf 12
185a7e25
MTP
13class RadioJavanIE(InfoExtractor):
14 _VALID_URL = r'https?://(?:www\.)?radiojavan\.com/videos/video/(?P<id>[^/]+)/?'
15 _TEST = {
16 'url': 'http://www.radiojavan.com/videos/video/chaartaar-ashoobam',
17 'md5': 'e85208ffa3ca8b83534fca9fe19af95b',
18 'info_dict': {
19 'id': 'chaartaar-ashoobam',
20 'ext': 'mp4',
21 'title': 'Chaartaar - Ashoobam',
ec85ded8 22 'thumbnail': r're:^https?://.*\.jpe?g$',
7cf97daf
S
23 'upload_date': '20150215',
24 'view_count': int,
25 'like_count': int,
26 'dislike_count': int,
185a7e25
MTP
27 }
28 }
29
30 def _real_extract(self, url):
7cf97daf 31 video_id = self._match_id(url)
185a7e25 32
0a9a8118 33 download_host = self._download_json(
93284ff2 34 'https://www.radiojavan.com/videos/video_host', video_id,
0a9a8118
H
35 data=urlencode_postdata({'id': video_id}),
36 headers={
37 'Content-Type': 'application/x-www-form-urlencoded',
38 'Referer': url,
93284ff2
S
39 }).get('host', 'https://host1.rjmusicmedia.com')
40
41 webpage = self._download_webpage(url, video_id)
42
43 formats = []
44 for format_id, _, video_path in re.findall(
45 r'RJ\.video(?P<format_id>\d+[pPkK])\s*=\s*(["\'])(?P<url>(?:(?!\2).)+)\2',
46 webpage):
47 f = parse_resolution(format_id)
48 f.update({
49 'url': urljoin(download_host, video_path),
50 'format_id': format_id,
51 })
52 formats.append(f)
185a7e25
MTP
53
54 title = self._og_search_title(webpage)
55 thumbnail = self._og_search_thumbnail(webpage)
185a7e25 56
7cf97daf
S
57 upload_date = unified_strdate(self._search_regex(
58 r'class="date_added">Date added: ([^<]+)<',
59 webpage, 'upload date', fatal=False))
185a7e25 60
7cf97daf
S
61 view_count = str_to_int(self._search_regex(
62 r'class="views">Plays: ([\d,]+)',
63 webpage, 'view count', fatal=False))
64 like_count = str_to_int(self._search_regex(
65 r'class="rating">([\d,]+) likes',
66 webpage, 'like count', fatal=False))
67 dislike_count = str_to_int(self._search_regex(
68 r'class="rating">([\d,]+) dislikes',
69 webpage, 'dislike count', fatal=False))
185a7e25
MTP
70
71 return {
7cf97daf 72 'id': video_id,
185a7e25 73 'title': title,
185a7e25 74 'thumbnail': thumbnail,
7cf97daf
S
75 'upload_date': upload_date,
76 'view_count': view_count,
77 'like_count': like_count,
78 'dislike_count': dislike_count,
79 'formats': formats,
80 }