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.

78 lines
2.7 KiB

  1. # encoding: 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. )
  14. class PandoraTVIE(InfoExtractor):
  15. IE_NAME = 'pandora.tv'
  16. IE_DESC = '판도라TV'
  17. _VALID_URL = r'https?://(?:.+?\.)?channel\.pandora\.tv/channel/video\.ptv\?'
  18. _TEST = {
  19. 'url': 'http://jp.channel.pandora.tv/channel/video.ptv?c1=&prgid=53294230&ch_userid=mikakim&ref=main&lot=cate_01_2',
  20. 'info_dict': {
  21. 'id': '53294230',
  22. 'ext': 'flv',
  23. 'title': '頭を撫でてくれる?',
  24. 'description': '頭を撫でてくれる?',
  25. 'thumbnail': 're:^https?://.*\.jpg$',
  26. 'duration': 39,
  27. 'upload_date': '20151218',
  28. 'uploader': 'カワイイ動物まとめ',
  29. 'uploader_id': 'mikakim',
  30. 'view_count': int,
  31. 'like_count': int,
  32. }
  33. }
  34. def _real_extract(self, url):
  35. qs = compat_urlparse.parse_qs(compat_urlparse.urlparse(url).query)
  36. video_id = qs.get('prgid', [None])[0]
  37. user_id = qs.get('ch_userid', [None])[0]
  38. if any(not f for f in (video_id, user_id,)):
  39. raise ExtractorError('Invalid URL', expected=True)
  40. data = self._download_json(
  41. 'http://m.pandora.tv/?c=view&m=viewJsonApi&ch_userid=%s&prgid=%s'
  42. % (user_id, video_id), video_id)
  43. info = data['data']['rows']['vod_play_info']['result']
  44. formats = []
  45. for format_id, format_url in info.items():
  46. if not format_url:
  47. continue
  48. height = self._search_regex(
  49. r'^v(\d+)[Uu]rl$', format_id, 'height', default=None)
  50. if not height:
  51. continue
  52. formats.append({
  53. 'format_id': '%sp' % height,
  54. 'url': format_url,
  55. 'height': int(height),
  56. })
  57. self._sort_formats(formats)
  58. return {
  59. 'id': video_id,
  60. 'title': info['subject'],
  61. 'description': info.get('body'),
  62. 'thumbnail': info.get('thumbnail') or info.get('poster'),
  63. 'duration': float_or_none(info.get('runtime'), 1000) or parse_duration(info.get('time')),
  64. 'upload_date': info['fid'][:8] if isinstance(info.get('fid'), compat_str) else None,
  65. 'uploader': info.get('nickname'),
  66. 'uploader_id': info.get('upload_userid'),
  67. 'view_count': str_to_int(info.get('hit')),
  68. 'like_count': str_to_int(info.get('likecnt')),
  69. 'formats': formats,
  70. }