]>
Commit | Line | Data |
---|---|---|
9accfed4 | 1 | # encoding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
4 | from .common import InfoExtractor | |
9accfed4 | 5 | from ..compat import ( |
e4bd63f9 | 6 | compat_str, |
9accfed4 | 7 | compat_urlparse, |
8 | ) | |
9 | from ..utils import ( | |
10 | ExtractorError, | |
e4bd63f9 S |
11 | float_or_none, |
12 | parse_duration, | |
13 | str_to_int, | |
9accfed4 | 14 | ) |
15 | ||
16 | ||
17 | class PandoraTVIE(InfoExtractor): | |
72528252 S |
18 | IE_NAME = 'pandora.tv' |
19 | IE_DESC = '판도라TV' | |
e4bd63f9 S |
20 | _VALID_URL = r'https?://(?:.+?\.)?channel\.pandora\.tv/channel/video\.ptv\?' |
21 | _TEST = { | |
9accfed4 | 22 | 'url': 'http://jp.channel.pandora.tv/channel/video.ptv?c1=&prgid=53294230&ch_userid=mikakim&ref=main&lot=cate_01_2', |
23 | 'info_dict': { | |
9accfed4 | 24 | 'id': '53294230', |
e4bd63f9 S |
25 | 'ext': 'flv', |
26 | 'title': '頭を撫でてくれる?', | |
27 | 'description': '頭を撫でてくれる?', | |
28 | 'thumbnail': 're:^https?://.*\.jpg$', | |
29 | 'duration': 39, | |
9accfed4 | 30 | 'upload_date': '20151218', |
e4bd63f9 S |
31 | 'uploader': 'カワイイ動物まとめ', |
32 | 'uploader_id': 'mikakim', | |
33 | 'view_count': int, | |
34 | 'like_count': int, | |
9accfed4 | 35 | } |
e4bd63f9 | 36 | } |
9accfed4 | 37 | |
38 | def _real_extract(self, url): | |
39 | qs = compat_urlparse.parse_qs(compat_urlparse.urlparse(url).query) | |
40 | video_id = qs.get('prgid', [None])[0] | |
41 | user_id = qs.get('ch_userid', [None])[0] | |
42 | if any(not f for f in (video_id, user_id,)): | |
43 | raise ExtractorError('Invalid URL', expected=True) | |
44 | ||
e4bd63f9 S |
45 | data = self._download_json( |
46 | 'http://m.pandora.tv/?c=view&m=viewJsonApi&ch_userid=%s&prgid=%s' | |
47 | % (user_id, video_id), video_id) | |
48 | ||
9accfed4 | 49 | info = data['data']['rows']['vod_play_info']['result'] |
50 | ||
51 | formats = [] | |
e4bd63f9 S |
52 | for format_id, format_url in info.items(): |
53 | if not format_url: | |
54 | continue | |
55 | height = self._search_regex( | |
56 | r'^v(\d+)[Uu]rl$', format_id, 'height', default=None) | |
57 | if not height: | |
58 | continue | |
9accfed4 | 59 | formats.append({ |
e4bd63f9 S |
60 | 'format_id': '%sp' % height, |
61 | 'url': format_url, | |
62 | 'height': int(height), | |
9accfed4 | 63 | }) |
e4bd63f9 | 64 | self._sort_formats(formats) |
9accfed4 | 65 | |
66 | return { | |
9accfed4 | 67 | 'id': video_id, |
68 | 'title': info['subject'], | |
e4bd63f9 S |
69 | 'description': info.get('body'), |
70 | 'thumbnail': info.get('thumbnail') or info.get('poster'), | |
71 | 'duration': float_or_none(info.get('runtime'), 1000) or parse_duration(info.get('time')), | |
72 | 'upload_date': info['fid'][:8] if isinstance(info.get('fid'), compat_str) else None, | |
73 | 'uploader': info.get('nickname'), | |
74 | 'uploader_id': info.get('upload_userid'), | |
75 | 'view_count': str_to_int(info.get('hit')), | |
76 | 'like_count': str_to_int(info.get('likecnt')), | |
77 | 'formats': formats, | |
9accfed4 | 78 | } |