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.

87 lines
2.9 KiB

  1. from __future__ import unicode_literals
  2. import re
  3. import json
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. determine_ext,
  7. int_or_none,
  8. qualities,
  9. unescapeHTML,
  10. )
  11. class GiantBombIE(InfoExtractor):
  12. _VALID_URL = r'https?://(?:www\.)?giantbomb\.com/videos/(?P<display_id>[^/]+)/(?P<id>\d+-\d+)'
  13. _TEST = {
  14. 'url': 'http://www.giantbomb.com/videos/quick-look-destiny-the-dark-below/2300-9782/',
  15. 'md5': 'c8ea694254a59246a42831155dec57ac',
  16. 'info_dict': {
  17. 'id': '2300-9782',
  18. 'display_id': 'quick-look-destiny-the-dark-below',
  19. 'ext': 'mp4',
  20. 'title': 'Quick Look: Destiny: The Dark Below',
  21. 'description': 'md5:0aa3aaf2772a41b91d44c63f30dfad24',
  22. 'duration': 2399,
  23. 'thumbnail': r're:^https?://.*\.jpg$',
  24. }
  25. }
  26. def _real_extract(self, url):
  27. mobj = re.match(self._VALID_URL, url)
  28. video_id = mobj.group('id')
  29. display_id = mobj.group('display_id')
  30. webpage = self._download_webpage(url, display_id)
  31. title = self._og_search_title(webpage)
  32. description = self._og_search_description(webpage)
  33. thumbnail = self._og_search_thumbnail(webpage)
  34. video = json.loads(unescapeHTML(self._search_regex(
  35. r'data-video="([^"]+)"', webpage, 'data-video')))
  36. duration = int_or_none(video.get('lengthSeconds'))
  37. quality = qualities([
  38. 'f4m_low', 'progressive_low', 'f4m_high',
  39. 'progressive_high', 'f4m_hd', 'progressive_hd'])
  40. formats = []
  41. for format_id, video_url in video['videoStreams'].items():
  42. if format_id == 'f4m_stream':
  43. continue
  44. ext = determine_ext(video_url)
  45. if ext == 'f4m':
  46. f4m_formats = self._extract_f4m_formats(video_url + '?hdcore=3.3.1', display_id)
  47. if f4m_formats:
  48. f4m_formats[0]['quality'] = quality(format_id)
  49. formats.extend(f4m_formats)
  50. elif ext == 'm3u8':
  51. formats.extend(self._extract_m3u8_formats(
  52. video_url, display_id, ext='mp4', entry_protocol='m3u8_native',
  53. m3u8_id='hls', fatal=False))
  54. else:
  55. formats.append({
  56. 'url': video_url,
  57. 'format_id': format_id,
  58. 'quality': quality(format_id),
  59. })
  60. if not formats:
  61. youtube_id = video.get('youtubeID')
  62. if youtube_id:
  63. return self.url_result(youtube_id, 'Youtube')
  64. self._sort_formats(formats)
  65. return {
  66. 'id': video_id,
  67. 'display_id': display_id,
  68. 'title': title,
  69. 'description': description,
  70. 'thumbnail': thumbnail,
  71. 'duration': duration,
  72. 'formats': formats,
  73. }