]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/gamespot.py
Merge remote-tracking branch 'lenaten/8tracks'
[yt-dlp.git] / youtube_dl / extractor / gamespot.py
CommitLineData
c1195541
PH
1from __future__ import unicode_literals
2
bf64ff72 3import re
c45aa560 4import json
bf64ff72
YK
5
6from .common import InfoExtractor
1cc79574 7from ..compat import (
ebdf2af7 8 compat_urllib_parse,
c45aa560 9 compat_urlparse,
1cc79574
PH
10)
11from ..utils import (
c45aa560 12 unescapeHTML,
bf64ff72
YK
13)
14
c45aa560 15
bf64ff72 16class GameSpotIE(InfoExtractor):
a32f2531 17 _VALID_URL = r'(?:http://)?(?:www\.)?gamespot\.com/.*-(?P<id>\d+)/?'
bf64ff72 18 _TEST = {
a2d5a4ee
S
19 'url': 'http://www.gamespot.com/videos/arma-3-community-guide-sitrep-i/2300-6410818/',
20 'md5': 'b2a30deaa8654fcccd43713a6b6a4825',
21 'info_dict': {
22 'id': 'gs-2300-6410818',
23 'ext': 'mp4',
24 'title': 'Arma 3 - Community Guide: SITREP I',
c1195541 25 'description': 'Check out this video where some of the basics of Arma 3 is explained.',
bf64ff72
YK
26 }
27 }
28
bf64ff72 29 def _real_extract(self, url):
a32f2531 30 page_id = self._match_id(url)
ebdf2af7 31 webpage = self._download_webpage(url, page_id)
a32f2531
PH
32 data_video_json = self._search_regex(
33 r'data-video=["\'](.*?)["\']', webpage, 'data video')
c45aa560 34 data_video = json.loads(unescapeHTML(data_video_json))
bf64ff72 35
c45aa560
JMF
36 # Transform the manifest url to a link to the mp4 files
37 # they are used in mobile devices.
38 f4m_url = data_video['videoStreams']['f4m_stream']
39 f4m_path = compat_urlparse.urlparse(f4m_url).path
40 QUALITIES_RE = r'((,\d+)+,?)'
12ed5741 41 qualities = self._search_regex(QUALITIES_RE, f4m_path, 'qualities').strip(',').split(',')
c45aa560
JMF
42 http_path = f4m_path[1:].split('/', 1)[1]
43 http_template = re.sub(QUALITIES_RE, r'%s', http_path)
44 http_template = http_template.replace('.csmil/manifest.f4m', '')
a32f2531
PH
45 http_template = compat_urlparse.urljoin(
46 'http://video.gamespotcdn.com/', http_template)
c45aa560
JMF
47 formats = []
48 for q in qualities:
49 formats.append({
50 'url': http_template % q,
51 'ext': 'mp4',
52 'format_id': q,
53 })
bf64ff72 54
fb7abb31 55 return {
c45aa560 56 'id': data_video['guid'],
a32f2531 57 'display_id': page_id,
c45aa560
JMF
58 'title': compat_urllib_parse.unquote(data_video['title']),
59 'formats': formats,
a32f2531 60 'description': self._html_search_meta('description', webpage),
c45aa560
JMF
61 'thumbnail': self._og_search_thumbnail(webpage),
62 }