]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/pandoratv.py
2b07958bb1f5815a162dadadff4f450f7ea0e97d
[youtubedl] / youtube_dl / extractor / pandoratv.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..compat import (
6 compat_str,
7 compat_urlparse,
8 )
9 from ..utils import (
10 ExtractorError,
11 float_or_none,
12 parse_duration,
13 str_to_int,
14 )
15
16
17 class PandoraTVIE(InfoExtractor):
18 IE_NAME = 'pandora.tv'
19 IE_DESC = '판도라TV'
20 _VALID_URL = r'https?://(?:.+?\.)?channel\.pandora\.tv/channel/video\.ptv\?'
21 _TEST = {
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': {
24 'id': '53294230',
25 'ext': 'flv',
26 'title': '頭を撫でてくれる?',
27 'description': '頭を撫でてくれる?',
28 'thumbnail': 're:^https?://.*\.jpg$',
29 'duration': 39,
30 'upload_date': '20151218',
31 'uploader': 'カワイイ動物まとめ',
32 'uploader_id': 'mikakim',
33 'view_count': int,
34 'like_count': int,
35 }
36 }
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
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
49 info = data['data']['rows']['vod_play_info']['result']
50
51 formats = []
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
59 formats.append({
60 'format_id': '%sp' % height,
61 'url': format_url,
62 'height': int(height),
63 })
64 self._sort_formats(formats)
65
66 return {
67 'id': video_id,
68 'title': info['subject'],
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,
78 }