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.

114 lines
3.9 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. _TESTS = [{
  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. 'url': 'http://channel.pandora.tv/channel/video.ptv?ch_userid=gogoucc&prgid=54721744',
  36. 'info_dict': {
  37. 'id': '54721744',
  38. 'ext': 'flv',
  39. 'title': '[HD] JAPAN COUNTDOWN 170423',
  40. 'description': '[HD] JAPAN COUNTDOWN 170423',
  41. 'thumbnail': r're:^https?://.*\.jpg$',
  42. 'duration': 1704.9,
  43. 'upload_date': '20170423',
  44. 'uploader': 'GOGO_UCC',
  45. 'uploader_id': 'gogoucc',
  46. 'view_count': int,
  47. 'like_count': int,
  48. },
  49. 'params': {
  50. # Test metadata only
  51. 'skip_download': True,
  52. },
  53. }]
  54. def _real_extract(self, url):
  55. qs = compat_urlparse.parse_qs(compat_urlparse.urlparse(url).query)
  56. video_id = qs.get('prgid', [None])[0]
  57. user_id = qs.get('ch_userid', [None])[0]
  58. if any(not f for f in (video_id, user_id,)):
  59. raise ExtractorError('Invalid URL', expected=True)
  60. data = self._download_json(
  61. 'http://m.pandora.tv/?c=view&m=viewJsonApi&ch_userid=%s&prgid=%s'
  62. % (user_id, video_id), video_id)
  63. info = data['data']['rows']['vod_play_info']['result']
  64. formats = []
  65. for format_id, format_url in info.items():
  66. if not format_url:
  67. continue
  68. height = self._search_regex(
  69. r'^v(\d+)[Uu]rl$', format_id, 'height', default=None)
  70. if not height:
  71. continue
  72. play_url = self._download_json(
  73. 'http://m.pandora.tv/?c=api&m=play_url', video_id,
  74. data=urlencode_postdata({
  75. 'prgid': video_id,
  76. 'runtime': info.get('runtime'),
  77. 'vod_url': format_url,
  78. }),
  79. headers={
  80. 'Origin': url,
  81. 'Content-Type': 'application/x-www-form-urlencoded',
  82. })
  83. format_url = play_url.get('url')
  84. if not format_url:
  85. continue
  86. formats.append({
  87. 'format_id': '%sp' % height,
  88. 'url': format_url,
  89. 'height': int(height),
  90. })
  91. self._sort_formats(formats)
  92. return {
  93. 'id': video_id,
  94. 'title': info['subject'],
  95. 'description': info.get('body'),
  96. 'thumbnail': info.get('thumbnail') or info.get('poster'),
  97. 'duration': float_or_none(info.get('runtime'), 1000) or parse_duration(info.get('time')),
  98. 'upload_date': info['fid'].split('/')[-1][:8] if isinstance(info.get('fid'), compat_str) else None,
  99. 'uploader': info.get('nickname'),
  100. 'uploader_id': info.get('upload_userid'),
  101. 'view_count': str_to_int(info.get('hit')),
  102. 'like_count': str_to_int(info.get('likecnt')),
  103. 'formats': formats,
  104. }