]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/musicplayon.py
Update changelog.
[youtubedl] / youtube_dl / extractor / musicplayon.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..compat import compat_urlparse
6 from ..utils import (
7 int_or_none,
8 js_to_json,
9 mimetype2ext,
10 )
11
12
13 class MusicPlayOnIE(InfoExtractor):
14 _VALID_URL = r'https?://(?:.+?\.)?musicplayon\.com/play(?:-touch)?\?(?:v|pl=\d+&play)=(?P<id>\d+)'
15
16 _TESTS = [{
17 'url': 'http://en.musicplayon.com/play?v=433377',
18 'md5': '00cdcdea1726abdf500d1e7fd6dd59bb',
19 'info_dict': {
20 'id': '433377',
21 'ext': 'mp4',
22 'title': 'Rick Ross - Interview On Chelsea Lately (2014)',
23 'description': 'Rick Ross Interview On Chelsea Lately',
24 'duration': 342,
25 'uploader': 'ultrafish',
26 },
27 }, {
28 'url': 'http://en.musicplayon.com/play?pl=102&play=442629',
29 'only_matching': True,
30 }]
31
32 _URL_TEMPLATE = 'http://en.musicplayon.com/play?v=%s'
33
34 def _real_extract(self, url):
35 video_id = self._match_id(url)
36 url = self._URL_TEMPLATE % video_id
37
38 page = self._download_webpage(url, video_id)
39
40 title = self._og_search_title(page)
41 description = self._og_search_description(page)
42 thumbnail = self._og_search_thumbnail(page)
43 duration = self._html_search_meta('video:duration', page, 'duration', fatal=False)
44 view_count = self._og_search_property('count', page, fatal=False)
45 uploader = self._html_search_regex(
46 r'<div>by&nbsp;<a href="[^"]+" class="purple">([^<]+)</a></div>', page, 'uploader', fatal=False)
47
48 sources = self._parse_json(
49 self._search_regex(r'setup\[\'_sources\'\]\s*=\s*([^;]+);', page, 'video sources'),
50 video_id, transform_source=js_to_json)
51 formats = [{
52 'url': compat_urlparse.urljoin(url, source['src']),
53 'ext': mimetype2ext(source.get('type')),
54 'format_note': source.get('data-res'),
55 } for source in sources]
56
57 return {
58 'id': video_id,
59 'title': title,
60 'description': description,
61 'thumbnail': thumbnail,
62 'uploader': uploader,
63 'duration': int_or_none(duration),
64 'view_count': int_or_none(view_count),
65 'formats': formats,
66 }