gamespot.py 3.0 KB

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