]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/pandoratv.py
[ie/box] Fix formats extraction (#8649)
[yt-dlp.git] / yt_dlp / extractor / pandoratv.py
CommitLineData
9accfed4 1from .common import InfoExtractor
9accfed4 2from ..compat import (
e4bd63f9 3 compat_str,
9accfed4 4)
5from ..utils import (
6 ExtractorError,
e4bd63f9
S
7 float_or_none,
8 parse_duration,
4dfbf869 9 parse_qs,
e4bd63f9 10 str_to_int,
7441915b 11 urlencode_postdata,
9accfed4 12)
13
14
15class PandoraTVIE(InfoExtractor):
72528252
S
16 IE_NAME = 'pandora.tv'
17 IE_DESC = '판도라TV'
64287560
S
18 _VALID_URL = r'''(?x)
19 https?://
20 (?:
21 (?:www\.)?pandora\.tv/view/(?P<user_id>[^/]+)/(?P<id>\d+)| # new format
609850ac
S
22 (?:.+?\.)?channel\.pandora\.tv/channel/video\.ptv\?| # old format
23 m\.pandora\.tv/?\? # mobile
64287560
S
24 )
25 '''
cc2ffe5a 26 _TESTS = [{
9accfed4 27 'url': 'http://jp.channel.pandora.tv/channel/video.ptv?c1=&prgid=53294230&ch_userid=mikakim&ref=main&lot=cate_01_2',
28 'info_dict': {
9accfed4 29 'id': '53294230',
e4bd63f9
S
30 'ext': 'flv',
31 'title': '頭を撫でてくれる?',
32 'description': '頭を撫でてくれる?',
ec85ded8 33 'thumbnail': r're:^https?://.*\.jpg$',
e4bd63f9 34 'duration': 39,
9accfed4 35 'upload_date': '20151218',
e4bd63f9
S
36 'uploader': 'カワイイ動物まとめ',
37 'uploader_id': 'mikakim',
38 'view_count': int,
39 'like_count': int,
9accfed4 40 }
cc2ffe5a
YCH
41 }, {
42 'url': 'http://channel.pandora.tv/channel/video.ptv?ch_userid=gogoucc&prgid=54721744',
43 'info_dict': {
44 'id': '54721744',
45 'ext': 'flv',
46 'title': '[HD] JAPAN COUNTDOWN 170423',
47 'description': '[HD] JAPAN COUNTDOWN 170423',
48 'thumbnail': r're:^https?://.*\.jpg$',
49 'duration': 1704.9,
50 'upload_date': '20170423',
51 'uploader': 'GOGO_UCC',
52 'uploader_id': 'gogoucc',
53 'view_count': int,
54 'like_count': int,
55 },
56 'params': {
57 # Test metadata only
58 'skip_download': True,
59 },
64287560
S
60 }, {
61 'url': 'http://www.pandora.tv/view/mikakim/53294230#36797454_new',
62 'only_matching': True,
609850ac
S
63 }, {
64 'url': 'http://m.pandora.tv/?c=view&ch_userid=mikakim&prgid=54600346',
65 'only_matching': True,
cc2ffe5a 66 }]
9accfed4 67
68 def _real_extract(self, url):
5ad28e7f 69 mobj = self._match_valid_url(url)
64287560
S
70 user_id = mobj.group('user_id')
71 video_id = mobj.group('id')
72
73 if not user_id or not video_id:
4dfbf869 74 qs = parse_qs(url)
64287560
S
75 video_id = qs.get('prgid', [None])[0]
76 user_id = qs.get('ch_userid', [None])[0]
77 if any(not f for f in (video_id, user_id,)):
78 raise ExtractorError('Invalid URL', expected=True)
9accfed4 79
e4bd63f9
S
80 data = self._download_json(
81 'http://m.pandora.tv/?c=view&m=viewJsonApi&ch_userid=%s&prgid=%s'
82 % (user_id, video_id), video_id)
83
9accfed4 84 info = data['data']['rows']['vod_play_info']['result']
85
86 formats = []
e4bd63f9
S
87 for format_id, format_url in info.items():
88 if not format_url:
89 continue
90 height = self._search_regex(
91 r'^v(\d+)[Uu]rl$', format_id, 'height', default=None)
92 if not height:
93 continue
7441915b 94
f43795e5
S
95 play_url = self._download_json(
96 'http://m.pandora.tv/?c=api&m=play_url', video_id,
97 data=urlencode_postdata({
98 'prgid': video_id,
99 'runtime': info.get('runtime'),
100 'vod_url': format_url,
101 }),
7441915b
S
102 headers={
103 'Origin': url,
f43795e5
S
104 'Content-Type': 'application/x-www-form-urlencoded',
105 })
7441915b
S
106 format_url = play_url.get('url')
107 if not format_url:
108 continue
109
9accfed4 110 formats.append({
e4bd63f9
S
111 'format_id': '%sp' % height,
112 'url': format_url,
113 'height': int(height),
9accfed4 114 })
115
116 return {
9accfed4 117 'id': video_id,
118 'title': info['subject'],
e4bd63f9
S
119 'description': info.get('body'),
120 'thumbnail': info.get('thumbnail') or info.get('poster'),
121 'duration': float_or_none(info.get('runtime'), 1000) or parse_duration(info.get('time')),
cc2ffe5a 122 'upload_date': info['fid'].split('/')[-1][:8] if isinstance(info.get('fid'), compat_str) else None,
e4bd63f9
S
123 'uploader': info.get('nickname'),
124 'uploader_id': info.get('upload_userid'),
125 'view_count': str_to_int(info.get('hit')),
126 'like_count': str_to_int(info.get('likecnt')),
127 'formats': formats,
9accfed4 128 }