You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

95 lines
3.2 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..compat import (
  5. compat_str,
  6. compat_urlparse,
  7. )
  8. from ..utils import (
  9. ExtractorError,
  10. float_or_none,
  11. parse_duration,
  12. str_to_int,
  13. urlencode_postdata,
  14. )
  15. class PandoraTVIE(InfoExtractor):
  16. IE_NAME = 'pandora.tv'
  17. IE_DESC = '판도라TV'
  18. _VALID_URL = r'https?://(?:.+?\.)?channel\.pandora\.tv/channel/video\.ptv\?'
  19. _TEST = {
  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': {
  22. 'id': '53294230',
  23. 'ext': 'flv',
  24. 'title': '頭を撫でてくれる?',
  25. 'description': '頭を撫でてくれる?',
  26. 'thumbnail': r're:^https?://.*\.jpg$',
  27. 'duration': 39,
  28. 'upload_date': '20151218',
  29. 'uploader': 'カワイイ動物まとめ',
  30. 'uploader_id': 'mikakim',
  31. 'view_count': int,
  32. 'like_count': int,
  33. }
  34. }
  35. def _real_extract(self, url):
  36. qs = compat_urlparse.parse_qs(compat_urlparse.urlparse(url).query)
  37. video_id = qs.get('prgid', [None])[0]
  38. user_id = qs.get('ch_userid', [None])[0]
  39. if any(not f for f in (video_id, user_id,)):
  40. raise ExtractorError('Invalid URL', expected=True)
  41. data = self._download_json(
  42. 'http://m.pandora.tv/?c=view&m=viewJsonApi&ch_userid=%s&prgid=%s'
  43. % (user_id, video_id), video_id)
  44. info = data['data']['rows']['vod_play_info']['result']
  45. formats = []
  46. for format_id, format_url in info.items():
  47. if not format_url:
  48. continue
  49. height = self._search_regex(
  50. r'^v(\d+)[Uu]rl$', format_id, 'height', default=None)
  51. if not height:
  52. continue
  53. play_url = self._download_json(
  54. 'http://m.pandora.tv/?c=api&m=play_url', video_id,
  55. data=urlencode_postdata({
  56. 'prgid': video_id,
  57. 'runtime': info.get('runtime'),
  58. 'vod_url': format_url,
  59. }),
  60. headers={
  61. 'Origin': url,
  62. 'Content-Type': 'application/x-www-form-urlencoded',
  63. })
  64. format_url = play_url.get('url')
  65. if not format_url:
  66. continue
  67. formats.append({
  68. 'format_id': '%sp' % height,
  69. 'url': format_url,
  70. 'height': int(height),
  71. })
  72. self._sort_formats(formats)
  73. return {
  74. 'id': video_id,
  75. 'title': info['subject'],
  76. 'description': info.get('body'),
  77. 'thumbnail': info.get('thumbnail') or info.get('poster'),
  78. 'duration': float_or_none(info.get('runtime'), 1000) or parse_duration(info.get('time')),
  79. 'upload_date': info['fid'][:8] if isinstance(info.get('fid'), compat_str) else None,
  80. 'uploader': info.get('nickname'),
  81. 'uploader_id': info.get('upload_userid'),
  82. 'view_count': str_to_int(info.get('hit')),
  83. 'like_count': str_to_int(info.get('likecnt')),
  84. 'formats': formats,
  85. }