logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

gamespot.py (3156B)


  1. from __future__ import unicode_literals
  2. from .once import OnceIE
  3. from ..compat import compat_urllib_parse_unquote
  4. class GameSpotIE(OnceIE):
  5. _VALID_URL = r'https?://(?:www\.)?gamespot\.com/(?:video|article|review)s/(?:[^/]+/\d+-|embed/)(?P<id>\d+)'
  6. _TESTS = [{
  7. 'url': 'http://www.gamespot.com/videos/arma-3-community-guide-sitrep-i/2300-6410818/',
  8. 'md5': 'b2a30deaa8654fcccd43713a6b6a4825',
  9. 'info_dict': {
  10. 'id': 'gs-2300-6410818',
  11. 'ext': 'mp4',
  12. 'title': 'Arma 3 - Community Guide: SITREP I',
  13. 'description': 'Check out this video where some of the basics of Arma 3 is explained.',
  14. },
  15. 'skip': 'manifest URL give HTTP Error 404: Not Found',
  16. }, {
  17. 'url': 'http://www.gamespot.com/videos/the-witcher-3-wild-hunt-xbox-one-now-playing/2300-6424837/',
  18. 'md5': '173ea87ad762cf5d3bf6163dceb255a6',
  19. 'info_dict': {
  20. 'id': 'gs-2300-6424837',
  21. 'ext': 'mp4',
  22. 'title': 'Now Playing - The Witcher 3: Wild Hunt',
  23. 'description': 'Join us as we take a look at the early hours of The Witcher 3: Wild Hunt and more.',
  24. },
  25. }, {
  26. 'url': 'https://www.gamespot.com/videos/embed/6439218/',
  27. 'only_matching': True,
  28. }, {
  29. 'url': 'https://www.gamespot.com/articles/the-last-of-us-2-receives-new-ps4-trailer/1100-6454469/',
  30. 'only_matching': True,
  31. }, {
  32. 'url': 'https://www.gamespot.com/reviews/gears-of-war-review/1900-6161188/',
  33. 'only_matching': True,
  34. }]
  35. def _real_extract(self, url):
  36. page_id = self._match_id(url)
  37. webpage = self._download_webpage(url, page_id)
  38. data_video = self._parse_json(self._html_search_regex(
  39. r'data-video=(["\'])({.*?})\1', webpage,
  40. 'video data', group=2), page_id)
  41. title = compat_urllib_parse_unquote(data_video['title'])
  42. streams = data_video['videoStreams']
  43. formats = []
  44. m3u8_url = streams.get('adaptive_stream')
  45. if m3u8_url:
  46. m3u8_formats = self._extract_m3u8_formats(
  47. m3u8_url, page_id, 'mp4', 'm3u8_native',
  48. m3u8_id='hls', fatal=False)
  49. for f in m3u8_formats:
  50. formats.append(f)
  51. http_f = f.copy()
  52. del http_f['manifest_url']
  53. http_f.update({
  54. 'format_id': f['format_id'].replace('hls-', 'http-'),
  55. 'protocol': 'http',
  56. 'url': f['url'].replace('.m3u8', '.mp4'),
  57. })
  58. formats.append(http_f)
  59. mpd_url = streams.get('adaptive_dash')
  60. if mpd_url:
  61. formats.extend(self._extract_mpd_formats(
  62. mpd_url, page_id, mpd_id='dash', fatal=False))
  63. self._sort_formats(formats)
  64. return {
  65. 'id': data_video.get('guid') or page_id,
  66. 'display_id': page_id,
  67. 'title': title,
  68. 'formats': formats,
  69. 'description': self._html_search_meta('description', webpage),
  70. 'thumbnail': self._og_search_thumbnail(webpage),
  71. }