giantbomb.py 2.9 KB

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