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.

88 lines
3.1 KiB

9 years ago
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. dict_get,
  6. float_or_none,
  7. int_or_none,
  8. )
  9. from ..compat import compat_urllib_parse_urlencode
  10. class VLiveIE(InfoExtractor):
  11. IE_NAME = 'vlive'
  12. _VALID_URL = r'https?://(?:(?:www|m)\.)?vlive\.tv/video/(?P<id>[0-9]+)'
  13. _TEST = {
  14. 'url': 'http://www.vlive.tv/video/1326',
  15. 'md5': 'cc7314812855ce56de70a06a27314983',
  16. 'info_dict': {
  17. 'id': '1326',
  18. 'ext': 'mp4',
  19. 'title': "[V] Girl's Day's Broadcast",
  20. 'creator': "Girl's Day",
  21. 'view_count': int,
  22. },
  23. }
  24. def _real_extract(self, url):
  25. video_id = self._match_id(url)
  26. webpage = self._download_webpage(
  27. 'http://www.vlive.tv/video/%s' % video_id, video_id)
  28. long_video_id = self._search_regex(
  29. r'vlive\.tv\.video\.ajax\.request\.handler\.init\(\s*"[0-9]+"\s*,\s*"[^"]*"\s*,\s*"([^"]+)"',
  30. webpage, 'long video id')
  31. key = self._search_regex(
  32. r'vlive\.tv\.video\.ajax\.request\.handler\.init\(\s*"[0-9]+"\s*,\s*"[^"]*"\s*,\s*"[^"]+"\s*,\s*"([^"]+)"',
  33. webpage, 'key')
  34. title = self._og_search_title(webpage)
  35. playinfo = self._download_json(
  36. 'http://global.apis.naver.com/rmcnmv/rmcnmv/vod_play_videoInfo.json?%s'
  37. % compat_urllib_parse_urlencode({
  38. 'videoId': long_video_id,
  39. 'key': key,
  40. 'ptc': 'http',
  41. 'doct': 'json', # document type (xml or json)
  42. 'cpt': 'vtt', # captions type (vtt or ttml)
  43. }), video_id)
  44. formats = [{
  45. 'url': vid['source'],
  46. 'format_id': vid.get('encodingOption', {}).get('name'),
  47. 'abr': float_or_none(vid.get('bitrate', {}).get('audio')),
  48. 'vbr': float_or_none(vid.get('bitrate', {}).get('video')),
  49. 'width': int_or_none(vid.get('encodingOption', {}).get('width')),
  50. 'height': int_or_none(vid.get('encodingOption', {}).get('height')),
  51. 'filesize': int_or_none(vid.get('size')),
  52. } for vid in playinfo.get('videos', {}).get('list', []) if vid.get('source')]
  53. self._sort_formats(formats)
  54. thumbnail = self._og_search_thumbnail(webpage)
  55. creator = self._html_search_regex(
  56. r'<div[^>]+class="info_area"[^>]*>\s*<a\s+[^>]*>([^<]+)',
  57. webpage, 'creator', fatal=False)
  58. view_count = int_or_none(playinfo.get('meta', {}).get('count'))
  59. subtitles = {}
  60. for caption in playinfo.get('captions', {}).get('list', []):
  61. lang = dict_get(caption, ('language', 'locale', 'country', 'label'))
  62. if lang and caption.get('source'):
  63. subtitles[lang] = [{
  64. 'ext': 'vtt',
  65. 'url': caption['source']}]
  66. return {
  67. 'id': video_id,
  68. 'title': title,
  69. 'creator': creator,
  70. 'thumbnail': thumbnail,
  71. 'view_count': view_count,
  72. 'formats': formats,
  73. 'subtitles': subtitles,
  74. }