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.

91 lines
3.0KB

  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|shows)/(?P<display_id>[^/]+)/(?P<id>\d+-\d+)'
  13. _TESTS = [{
  14. 'url': 'http://www.giantbomb.com/videos/quick-look-destiny-the-dark-below/2300-9782/',
  15. 'md5': '132f5a803e7e0ab0e274d84bda1e77ae',
  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. 'url': 'https://www.giantbomb.com/shows/ben-stranding/2970-20212',
  27. 'only_matching': True,
  28. }]
  29. def _real_extract(self, url):
  30. mobj = re.match(self._VALID_URL, url)
  31. video_id = mobj.group('id')
  32. display_id = mobj.group('display_id')
  33. webpage = self._download_webpage(url, display_id)
  34. title = self._og_search_title(webpage)
  35. description = self._og_search_description(webpage)
  36. thumbnail = self._og_search_thumbnail(webpage)
  37. video = json.loads(unescapeHTML(self._search_regex(
  38. r'data-video="([^"]+)"', webpage, 'data-video')))
  39. duration = int_or_none(video.get('lengthSeconds'))
  40. quality = qualities([
  41. 'f4m_low', 'progressive_low', 'f4m_high',
  42. 'progressive_high', 'f4m_hd', 'progressive_hd'])
  43. formats = []
  44. for format_id, video_url in video['videoStreams'].items():
  45. if format_id == 'f4m_stream':
  46. continue
  47. ext = determine_ext(video_url)
  48. if ext == 'f4m':
  49. f4m_formats = self._extract_f4m_formats(video_url + '?hdcore=3.3.1', display_id)
  50. if f4m_formats:
  51. f4m_formats[0]['quality'] = quality(format_id)
  52. formats.extend(f4m_formats)
  53. elif ext == 'm3u8':
  54. formats.extend(self._extract_m3u8_formats(
  55. video_url, display_id, ext='mp4', entry_protocol='m3u8_native',
  56. m3u8_id='hls', fatal=False))
  57. else:
  58. formats.append({
  59. 'url': video_url,
  60. 'format_id': format_id,
  61. 'quality': quality(format_id),
  62. })
  63. if not formats:
  64. youtube_id = video.get('youtubeID')
  65. if youtube_id:
  66. return self.url_result(youtube_id, 'Youtube')
  67. self._sort_formats(formats)
  68. return {
  69. 'id': video_id,
  70. 'display_id': display_id,
  71. 'title': title,
  72. 'description': description,
  73. 'thumbnail': thumbnail,
  74. 'duration': duration,
  75. 'formats': formats,
  76. }