]> gitweb @ CieloNegro.org - youtube-dl.git/blob - youtube_dl/extractor/gamersyde.py
5c68a689145c5efbab5e2cd15632d99423cc16ae
[youtube-dl.git] / 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         'url': 'http://www.gamersyde.com/hqstream_bloodborne_birth_of_a_hero-34371_en.html',
12         'md5': 'f38d400d32f19724570040d5ce3a505f',
13         'info_dict': {
14             'id': '34371',
15             'ext': 'mp4',
16             'title': 'Bloodborne - Birth of a hero',
17             'thumbnail': 're:^https?://.*\.jpg$',
18         }
19     },
20     {
21         'url': 'http://www.gamersyde.com/hqstream_dark_souls_ii_scholar_of_the_first_sin_gameplay_part_1-34417_en.html',
22         'info_dict': {
23             'ext': 'mp4',
24     }
25
26     def _calculateDuration(self, durationString):
27         duration = time.strptime(durationString, "%M minutes %S seconds")
28         return duration.tm_min * 60 + duration.tm_sec
29
30     def _fixJsonSyntax(self, json):
31
32         json = re.sub(r"{\s*(\w)", r'{"\1', json)
33         json = re.sub(r",\s*(\w)", r',"\1', json)
34         json = re.sub(r",\s*}", "}", json, flags=re.DOTALL)
35         json = re.sub(r",\s*]", "]", json, flags=re.DOTALL)
36
37         return json
38
39     def _real_extract(self, url):
40
41         video_id = self._search_regex(r'-(.*?)_[a-z]{2}.html$', url, 'video_id')
42         webpage = self._download_webpage(url, video_id)
43
44         filesJson = self._search_regex(r'playlist: (.*?)\}\);', webpage, 'files', flags=re.DOTALL)
45         filesJson = self._fixJsonSyntax(filesJson)
46         data = json.loads(filesJson)
47         playlist = data[0]
48
49         formats = []
50
51         title = re.sub(r"[0-9]+ - ", "", playlist['title'])
52
53         for playlistEntry in playlist['sources']:
54             format = {
55                 'url': playlistEntry['file'],
56                 'format_id': playlistEntry['label']
57             }
58
59             formats.append(format)
60
61         return {
62             'id': video_id,
63             'title': title,
64             'formats': formats,
65             'thumbnail': playlist['image']
66             }