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