pandoratv.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # encoding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..compat import (
  5. compat_urlparse,
  6. )
  7. from ..utils import (
  8. ExtractorError,
  9. )
  10. class PandoraTVIE(InfoExtractor):
  11. _VALID_URL = r'http://(?:.+?\.)?channel.pandora.tv/channel/video.ptv\?'
  12. _TESTS = [{
  13. 'url': 'http://jp.channel.pandora.tv/channel/video.ptv?c1=&prgid=53294230&ch_userid=mikakim&ref=main&lot=cate_01_2',
  14. 'info_dict': {
  15. 'description': '\u982d\u3092\u64ab\u3067\u3066\u304f\u308c\u308b\uff1f',
  16. 'ext': 'mp4',
  17. 'id': '53294230',
  18. 'title': '\u982d\u3092\u64ab\u3067\u3066\u304f\u308c\u308b\uff1f',
  19. 'upload_date': '20151218',
  20. }
  21. }]
  22. def _real_extract(self, url):
  23. qs = compat_urlparse.parse_qs(compat_urlparse.urlparse(url).query)
  24. video_id = qs.get('prgid', [None])[0]
  25. user_id = qs.get('ch_userid', [None])[0]
  26. if any(not f for f in (video_id, user_id,)):
  27. raise ExtractorError('Invalid URL', expected=True)
  28. data_url ='http://m.pandora.tv/?c=view&m=viewJsonApi&ch_userid={userid}&prgid={prgid}'.format(userid=user_id,prgid=video_id)
  29. data = self._download_json(data_url, video_id)
  30. info = data['data']['rows']['vod_play_info']['result']
  31. formats = []
  32. for format_id in sorted([k for k in info if k.startswith('v') and k.endswith('Url') and info[k]]):
  33. formats.append({
  34. 'format_id': format_id,
  35. 'url': info[format_id],
  36. 'ext': 'mp4',
  37. 'height': int(format_id[1:-3]),
  38. })
  39. return {
  40. 'description': info['body'],
  41. 'thumbnail': info['thumbnail'],
  42. 'formats': formats,
  43. 'id': video_id,
  44. 'title': info['subject'],
  45. 'upload_date': info['fid'][:8],
  46. 'view_count': info['hit'],
  47. }