]> git.bitcoin.ninja Git - youtube-dl/blob - youtube_dl/extractor/gamersyde.py
[Gamersyde] Add new extractor
[youtube-dl] / youtube_dl / extractor / gamersyde.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3 import re
4 import json
5 import time
6 from .common import InfoExtractor
7
8
9 class GamersydeIE(InfoExtractor):
10     _VALID_URL = r'https?://(?:www\.)?gamersyde\.com/hqstream_'
11     _TEST = {
12         'url': 'http://www.gamersyde.com/hqstream_bloodborne_birth_of_a_hero-34371_en.html',
13         'md5': 'f38d400d32f19724570040d5ce3a505f',
14         'info_dict': {
15             'id': '34371',
16             'ext': 'mp4',
17             'title': 'Bloodborne - Birth of a hero',
18             'thumbnail': 're:^https?://.*\.jpg$',
19         }
20     }
21
22     def _calculateDuration(self, durationString):
23         duration = time.strptime(durationString, "%M minutes %S seconds")
24         return duration.tm_min * 60 + duration.tm_sec
25
26     def _fixJsonSyntax(self, json):
27
28         json = re.sub(r"{\s*(\w)", r'{"\1', json)
29         json = re.sub(r",\s*(\w)", r',"\1', json)
30         json = re.sub(r"(\w): ", r'\1":', json)
31         json = re.sub(r",\s*}", "}", json, flags=re.DOTALL)
32         json = re.sub(r",\s*]", "]", json, flags=re.DOTALL)
33
34         return json
35
36     def _real_extract(self, url):
37
38         video_id = self._search_regex(r'-(.*?)_[a-z]{2}.html$', url, 'video_id')
39         webpage = self._download_webpage(url, video_id)
40
41         filesJson = self._search_regex(r'playlist: (.*?)\}\);', webpage, 'files', flags=re.DOTALL)
42         filesJson = self._fixJsonSyntax(filesJson)
43
44         data = json.loads(filesJson)
45         playlist = data[0]
46
47         formats = []
48
49         title = re.sub(r"[0-9]+ - ", "", playlist['title'])
50
51         for playlistEntry in playlist['sources']:
52             format = {
53                 'url': playlistEntry['file'],
54                 'format_id': playlistEntry['label']
55             }
56
57             formats.append(format)
58
59         return {
60             'id': video_id,
61             'title': title,
62             'formats': formats,
63             'thumbnail': playlist['image']
64             }