[yinyuetai] Add test for h5/ part in _VALID_URL
[youtube-dl] / youtube_dl / extractor / yinyuetai.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..utils import ExtractorError
6
7
8 class YinYueTaiIE(InfoExtractor):
9     IE_NAME = 'yinyuetai:video'
10     _VALID_URL = r'https?://v\.yinyuetai\.com/video(/h5)?/(?P<id>[0-9]+)'
11     _TESTS = [{
12         'url': 'http://v.yinyuetai.com/video/2322376',
13         'md5': '6e3abe28d38e3a54b591f9f040595ce0',
14         'info_dict': {
15             'id': '2322376',
16             'ext': 'mp4',
17             'title': '少女时代_PARTY_Music Video Teaser',
18             'creator': '少女时代',
19         },
20     }, {
21         'url': 'http://v.yinyuetai.com/video/h5/2322376',
22         'only_matching': True,
23     }]
24
25     def _real_extract(self, url):
26         video_id = self._match_id(url)
27
28         info = self._download_json(
29             'http://ext.yinyuetai.com/main/get-h-mv-info?json=true&videoId=%s' % video_id, video_id,
30             'Downloading mv info')['videoInfo']['coreVideoInfo']
31
32         if info['error']:
33             raise ExtractorError(info['errorMsg'], expected=True)
34
35         formats = [
36             {'url': format_info['videoUrl'], 'format_id': format_info['qualityLevel'],
37              'format': format_info['qualityLevelName'], 'filesize': format_info['fileSize'],
38              'ext': 'mp4', 'preference': format_info['bitrate']}
39             for format_info in info['videoUrlModels']
40         ]
41         self._sort_formats(formats)
42
43         return {
44             'id': video_id,
45             'title': info['videoName'],
46             'thumbnail': info['bigHeadImage'],
47             'creator': info['artistNames'],
48             'duration': info['duration'],
49             'formats': formats,
50         }