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.

93 lines
3.2 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. import time
  5. from .common import InfoExtractor
  6. class GamersydeIE(InfoExtractor):
  7. _VALID_URL = r'https?://(?:www\.)?gamersyde\.com/hqstream_'
  8. _TESTS = [{
  9. 'url': 'http://www.gamersyde.com/hqstream_bloodborne_birth_of_a_hero-34371_en.html',
  10. 'md5': 'f38d400d32f19724570040d5ce3a505f',
  11. 'info_dict': {
  12. 'id': '34371',
  13. 'ext': 'mp4',
  14. 'duration': 372,
  15. 'title': 'Bloodborne - Birth of a hero',
  16. 'thumbnail': 're:^https?://.*\.jpg$',
  17. }
  18. }, {
  19. 'url': 'http://www.gamersyde.com/hqstream_dark_souls_ii_scholar_of_the_first_sin_gameplay_part_1-34417_en.html',
  20. 'md5': '94bd7c3feff3275576cf5cb6c8a3a720',
  21. 'info_dict': {
  22. 'id': '34417',
  23. 'ext': 'mp4',
  24. 'duration': 270,
  25. 'title': 'Dark Souls II: Scholar of the First Sin - Gameplay - Part 1',
  26. 'thumbnail': 're:^https?://.*\.jpg$',
  27. }
  28. }, {
  29. 'url': 'http://www.gamersyde.com/hqstream_grand_theft_auto_v_heists_trailer-33786_en.html',
  30. 'md5': '65e442f5f340d571ece8c80d50700369',
  31. 'info_dict': {
  32. 'id': '33786',
  33. 'ext': 'mp4',
  34. 'duration': 59,
  35. 'title': 'Grand Theft Auto V - Heists Trailer',
  36. 'thumbnail': 're:^https?://.*\.jpg$',
  37. }
  38. }
  39. ]
  40. def _calculateDuration(self, durationString):
  41. if (durationString.find("minutes") > -1):
  42. duration = time.strptime(durationString, "%M minutes %S seconds")
  43. else:
  44. duration = time.strptime(durationString, "%S seconds")
  45. return duration.tm_min * 60 + duration.tm_sec
  46. def _fixJsonSyntax(self, json):
  47. json = re.sub(r",\s*}", "}", json, flags=re.DOTALL)
  48. json = re.sub(r",\s*]", "]", json, flags=re.DOTALL)
  49. json = json.replace('file: "', '"file": "')
  50. json = json.replace('title: "', '"title": "')
  51. json = json.replace('label: "', '"label": "')
  52. json = json.replace('image: "', '"image": "')
  53. json = json.replace('sources: [', '"sources": [')
  54. return json
  55. def _real_extract(self, url):
  56. video_id = self._search_regex(r'-(.*?)_[a-z]{2}.html$', url, 'video_id')
  57. webpage = self._download_webpage(url, video_id)
  58. filesJson = self._search_regex(r'playlist: (.*?)\}\);', webpage, 'files', flags=re.DOTALL)
  59. data = self._parse_json(filesJson,video_id, transform_source=self._fixJsonSyntax)
  60. playlist = data[0]
  61. formats = []
  62. title = re.sub(r"[0-9]+ - ", "", playlist['title'])
  63. length = self._search_regex(r'(([0-9]{1,2} minutes ){0,1}[0-9]{1,2} seconds)', webpage, 'length')
  64. duration = self._calculateDuration(length)
  65. for playlistEntry in playlist['sources']:
  66. format = {
  67. 'url': playlistEntry['file'],
  68. 'format_id': playlistEntry['label']
  69. }
  70. formats.append(format)
  71. return {
  72. 'id': video_id,
  73. 'title': title,
  74. 'formats': formats,
  75. 'duration': duration,
  76. 'thumbnail': playlist['image']
  77. }