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.

81 lines
2.6 KiB

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