mirror of
https://gitlab.com/dstftw/youtube-dl.git
synced 2020-11-16 09:42:26 +00:00
[pandoratv] Improve extraction (Closes #7921)
This commit is contained in:
parent
9accfed4e7
commit
e4bd63f9c0
|
@ -2,28 +2,36 @@
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
|
|
||||||
from ..compat import (
|
from ..compat import (
|
||||||
|
compat_str,
|
||||||
compat_urlparse,
|
compat_urlparse,
|
||||||
)
|
)
|
||||||
from ..utils import (
|
from ..utils import (
|
||||||
ExtractorError,
|
ExtractorError,
|
||||||
|
float_or_none,
|
||||||
|
parse_duration,
|
||||||
|
str_to_int,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class PandoraTVIE(InfoExtractor):
|
class PandoraTVIE(InfoExtractor):
|
||||||
_VALID_URL = r'http://(?:.+?\.)?channel.pandora.tv/channel/video.ptv\?'
|
_VALID_URL = r'https?://(?:.+?\.)?channel\.pandora\.tv/channel/video\.ptv\?'
|
||||||
_TESTS = [{
|
_TEST = {
|
||||||
'url': 'http://jp.channel.pandora.tv/channel/video.ptv?c1=&prgid=53294230&ch_userid=mikakim&ref=main&lot=cate_01_2',
|
'url': 'http://jp.channel.pandora.tv/channel/video.ptv?c1=&prgid=53294230&ch_userid=mikakim&ref=main&lot=cate_01_2',
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'description': '\u982d\u3092\u64ab\u3067\u3066\u304f\u308c\u308b\uff1f',
|
|
||||||
'ext': 'mp4',
|
|
||||||
'id': '53294230',
|
'id': '53294230',
|
||||||
'title': '\u982d\u3092\u64ab\u3067\u3066\u304f\u308c\u308b\uff1f',
|
'ext': 'flv',
|
||||||
|
'title': '頭を撫でてくれる?',
|
||||||
|
'description': '頭を撫でてくれる?',
|
||||||
|
'thumbnail': 're:^https?://.*\.jpg$',
|
||||||
|
'duration': 39,
|
||||||
'upload_date': '20151218',
|
'upload_date': '20151218',
|
||||||
|
'uploader': 'カワイイ動物まとめ',
|
||||||
|
'uploader_id': 'mikakim',
|
||||||
|
'view_count': int,
|
||||||
|
'like_count': int,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}]
|
|
||||||
|
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
qs = compat_urlparse.parse_qs(compat_urlparse.urlparse(url).query)
|
qs = compat_urlparse.parse_qs(compat_urlparse.urlparse(url).query)
|
||||||
|
@ -32,25 +40,37 @@ class PandoraTVIE(InfoExtractor):
|
||||||
if any(not f for f in (video_id, user_id,)):
|
if any(not f for f in (video_id, user_id,)):
|
||||||
raise ExtractorError('Invalid URL', expected=True)
|
raise ExtractorError('Invalid URL', expected=True)
|
||||||
|
|
||||||
data_url ='http://m.pandora.tv/?c=view&m=viewJsonApi&ch_userid={userid}&prgid={prgid}'.format(userid=user_id,prgid=video_id)
|
data = self._download_json(
|
||||||
data = self._download_json(data_url, video_id)
|
'http://m.pandora.tv/?c=view&m=viewJsonApi&ch_userid=%s&prgid=%s'
|
||||||
|
% (user_id, video_id), video_id)
|
||||||
|
|
||||||
info = data['data']['rows']['vod_play_info']['result']
|
info = data['data']['rows']['vod_play_info']['result']
|
||||||
|
|
||||||
formats = []
|
formats = []
|
||||||
for format_id in sorted([k for k in info if k.startswith('v') and k.endswith('Url') and info[k]]):
|
for format_id, format_url in info.items():
|
||||||
|
if not format_url:
|
||||||
|
continue
|
||||||
|
height = self._search_regex(
|
||||||
|
r'^v(\d+)[Uu]rl$', format_id, 'height', default=None)
|
||||||
|
if not height:
|
||||||
|
continue
|
||||||
formats.append({
|
formats.append({
|
||||||
'format_id': format_id,
|
'format_id': '%sp' % height,
|
||||||
'url': info[format_id],
|
'url': format_url,
|
||||||
'ext': 'mp4',
|
'height': int(height),
|
||||||
'height': int(format_id[1:-3]),
|
|
||||||
})
|
})
|
||||||
|
self._sort_formats(formats)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'description': info['body'],
|
|
||||||
'thumbnail': info['thumbnail'],
|
|
||||||
'formats': formats,
|
|
||||||
'id': video_id,
|
'id': video_id,
|
||||||
'title': info['subject'],
|
'title': info['subject'],
|
||||||
'upload_date': info['fid'][:8],
|
'description': info.get('body'),
|
||||||
'view_count': info['hit'],
|
'thumbnail': info.get('thumbnail') or info.get('poster'),
|
||||||
|
'duration': float_or_none(info.get('runtime'), 1000) or parse_duration(info.get('time')),
|
||||||
|
'upload_date': info['fid'][:8] if isinstance(info.get('fid'), compat_str) else None,
|
||||||
|
'uploader': info.get('nickname'),
|
||||||
|
'uploader_id': info.get('upload_userid'),
|
||||||
|
'view_count': str_to_int(info.get('hit')),
|
||||||
|
'like_count': str_to_int(info.get('likecnt')),
|
||||||
|
'formats': formats,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue