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