]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/rbmaradio.py
Initiate release.
[youtubedl] / youtube_dl / extractor / rbmaradio.py
1 # encoding: utf-8
2 from __future__ import unicode_literals
3
4 import json
5 import re
6
7 from .common import InfoExtractor
8 from ..utils import (
9 ExtractorError,
10 )
11
12
13 class RBMARadioIE(InfoExtractor):
14 _VALID_URL = r'https?://(?:www\.)?rbmaradio\.com/shows/(?P<videoID>[^/]+)$'
15 _TEST = {
16 'url': 'http://www.rbmaradio.com/shows/ford-lopatin-live-at-primavera-sound-2011',
17 'md5': '6bc6f9bcb18994b4c983bc3bf4384d95',
18 'info_dict': {
19 'id': 'ford-lopatin-live-at-primavera-sound-2011',
20 'ext': 'mp3',
21 "uploader_id": "ford-lopatin",
22 "location": "Spain",
23 "description": "Joel Ford and Daniel ’Oneohtrix Point Never’ Lopatin fly their midified pop extravaganza to Spain. Live at Primavera Sound 2011.",
24 "uploader": "Ford & Lopatin",
25 "title": "Live at Primavera Sound 2011",
26 },
27 }
28
29 def _real_extract(self, url):
30 m = re.match(self._VALID_URL, url)
31 video_id = m.group('videoID')
32
33 webpage = self._download_webpage(url, video_id)
34
35 json_data = self._search_regex(r'window\.gon.*?gon\.show=(.+?);$',
36 webpage, 'json data', flags=re.MULTILINE)
37
38 try:
39 data = json.loads(json_data)
40 except ValueError as e:
41 raise ExtractorError('Invalid JSON: ' + str(e))
42
43 video_url = data['akamai_url'] + '&cbr=256'
44
45 return {
46 'id': video_id,
47 'url': video_url,
48 'title': data['title'],
49 'description': data.get('teaser_text'),
50 'location': data.get('country_of_origin'),
51 'uploader': data.get('host', {}).get('name'),
52 'uploader_id': data.get('host', {}).get('slug'),
53 'thumbnail': data.get('image', {}).get('large_url_2x'),
54 'duration': data.get('duration'),
55 }