]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/pandoratv.py
Fix "invalid escape sequences" error on Python 3.6
[yt-dlp.git] / youtube_dl / extractor / pandoratv.py
CommitLineData
dcdb292f 1# coding: utf-8
9accfed4 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,
7441915b 14 urlencode_postdata,
9accfed4 15)
16
17
18class PandoraTVIE(InfoExtractor):
72528252
S
19 IE_NAME = 'pandora.tv'
20 IE_DESC = '판도라TV'
e4bd63f9
S
21 _VALID_URL = r'https?://(?:.+?\.)?channel\.pandora\.tv/channel/video\.ptv\?'
22 _TEST = {
9accfed4 23 'url': 'http://jp.channel.pandora.tv/channel/video.ptv?c1=&prgid=53294230&ch_userid=mikakim&ref=main&lot=cate_01_2',
24 'info_dict': {
9accfed4 25 'id': '53294230',
e4bd63f9
S
26 'ext': 'flv',
27 'title': '頭を撫でてくれる?',
28 'description': '頭を撫でてくれる?',
ec85ded8 29 'thumbnail': r're:^https?://.*\.jpg$',
e4bd63f9 30 'duration': 39,
9accfed4 31 'upload_date': '20151218',
e4bd63f9
S
32 'uploader': 'カワイイ動物まとめ',
33 'uploader_id': 'mikakim',
34 'view_count': int,
35 'like_count': int,
9accfed4 36 }
e4bd63f9 37 }
9accfed4 38
39 def _real_extract(self, url):
40 qs = compat_urlparse.parse_qs(compat_urlparse.urlparse(url).query)
41 video_id = qs.get('prgid', [None])[0]
42 user_id = qs.get('ch_userid', [None])[0]
43 if any(not f for f in (video_id, user_id,)):
44 raise ExtractorError('Invalid URL', expected=True)
45
e4bd63f9
S
46 data = self._download_json(
47 'http://m.pandora.tv/?c=view&m=viewJsonApi&ch_userid=%s&prgid=%s'
48 % (user_id, video_id), video_id)
49
9accfed4 50 info = data['data']['rows']['vod_play_info']['result']
51
52 formats = []
e4bd63f9
S
53 for format_id, format_url in info.items():
54 if not format_url:
55 continue
56 height = self._search_regex(
57 r'^v(\d+)[Uu]rl$', format_id, 'height', default=None)
58 if not height:
59 continue
7441915b 60
f43795e5
S
61 play_url = self._download_json(
62 'http://m.pandora.tv/?c=api&m=play_url', video_id,
63 data=urlencode_postdata({
64 'prgid': video_id,
65 'runtime': info.get('runtime'),
66 'vod_url': format_url,
67 }),
7441915b
S
68 headers={
69 'Origin': url,
f43795e5
S
70 'Content-Type': 'application/x-www-form-urlencoded',
71 })
7441915b
S
72 format_url = play_url.get('url')
73 if not format_url:
74 continue
75
9accfed4 76 formats.append({
e4bd63f9
S
77 'format_id': '%sp' % height,
78 'url': format_url,
79 'height': int(height),
9accfed4 80 })
e4bd63f9 81 self._sort_formats(formats)
9accfed4 82
83 return {
9accfed4 84 'id': video_id,
85 'title': info['subject'],
e4bd63f9
S
86 'description': info.get('body'),
87 'thumbnail': info.get('thumbnail') or info.get('poster'),
88 'duration': float_or_none(info.get('runtime'), 1000) or parse_duration(info.get('time')),
89 'upload_date': info['fid'][:8] if isinstance(info.get('fid'), compat_str) else None,
90 'uploader': info.get('nickname'),
91 'uploader_id': info.get('upload_userid'),
92 'view_count': str_to_int(info.get('hit')),
93 'like_count': str_to_int(info.get('likecnt')),
94 'formats': formats,
9accfed4 95 }