329bf61e0f1b2f361a4b4e20e71e21d05ef64978
[youtube-dl] / youtube_dl / extractor / musicvault.py
1 from __future__ import unicode_literals
2
3 import json
4 import re
5
6 from .common import InfoExtractor
7 from ..utils import (
8     strip_jsonp,
9     parse_duration,
10     unified_strdate,
11 )
12
13
14 class MusicVaultIE(InfoExtractor):
15     _VALID_URL = r'https?://www\.musicvault\.com/(?P<uploader_id>[^/?#]*)/video/(?P<display_id>[^/?#]*)_(?P<id>[0-9]+)\.html'
16     _TEST = {
17         'url': 'http://www.musicvault.com/the-allman-brothers-band/video/straight-from-the-heart_1010863.html',
18         'md5': '2cdbb3ae75f7fb3519821507d2fb3c15',
19         'info_dict': {
20             'id': '1010863',
21             'ext': 'mp4',
22             'uploader_id': 'the-allman-brothers-band',
23             'title': 'Straight from the Heart',
24             'duration': 244,
25             'uploader': 'The Allman Brothers Band',
26             'thumbnail': 're:^https?://.*/thumbnail/.*',
27             'upload_date': '19811216',
28             'location': 'Capitol Theatre (Passaic, NJ)',
29             'description': 'Listen to The Allman Brothers Band perform Straight from the Heart at Capitol Theatre (Passaic, NJ) on Dec 16, 1981',
30         }
31     }
32
33     def _real_extract(self, url):
34         mobj = re.match(self._VALID_URL, url)
35         display_id = mobj.group('display_id')
36         webpage = self._download_webpage(url, display_id)
37
38         thumbnail = self._search_regex(
39             r'<meta itemprop="thumbnail" content="([^"]+)"',
40             webpage, 'thumbnail', fatal=False)
41
42         data_div = self._search_regex(
43             r'(?s)<div class="data">(.*?)</div>', webpage, 'data fields')
44         uploader = self._html_search_regex(
45             r'<h1.*?>(.*?)</h1>', data_div, 'uploader', fatal=False)
46         title = self._html_search_regex(
47             r'<h2.*?>(.*?)</h2>', data_div, 'title')
48         upload_date = unified_strdate(self._html_search_regex(
49             r'<h3.*?>(.*?)</h3>', data_div, 'uploader', fatal=False))
50         location = self._html_search_regex(
51             r'<h4.*?>(.*?)</h4>', data_div, 'location', fatal=False)
52
53         duration = parse_duration(self._html_search_meta('duration', webpage))
54
55         VIDEO_URL_TEMPLATE = 'http://cdnapi.kaltura.com/p/%(uid)s/sp/%(wid)s/playManifest/entryId/%(entry_id)s/format/url/protocol/http'
56         kaltura_id = self._search_regex(
57             r'<div id="video-detail-player" data-kaltura-id="([^"]+)"',
58             webpage, 'kaltura ID')
59         video_url = VIDEO_URL_TEMPLATE % {
60             'entry_id': kaltura_id,
61             'wid': self._search_regex(r'/wid/_([0-9]+)/', webpage, 'wid'),
62             'uid': self._search_regex(r'uiconf_id/([0-9]+)/', webpage, 'uid'),
63         }
64
65         return {
66             'id': mobj.group('id'),
67             'url': video_url,
68             'ext': 'mp4',
69             'display_id': display_id,
70             'uploader_id': mobj.group('uploader_id'),
71             'thumbnail': thumbnail,
72             'description': self._html_search_meta('description', webpage),
73             'upload_date': upload_date,
74             'location': location,
75             'title': title,
76             'uploader': uploader,
77             'duration': duration,
78         }