]> gitweb @ CieloNegro.org - youtube-dl.git/blob - youtube_dl/extractor/nuvid.py
[techtalks] Relax _VALID_URL
[youtube-dl.git] / youtube_dl / extractor / nuvid.py
1 from __future__ import unicode_literals
2
3 import re
4
5 from .common import InfoExtractor
6 from ..utils import (
7     parse_duration,
8 )
9
10
11 class NuvidIE(InfoExtractor):
12     _VALID_URL = r'https?://(?:www|m)\.nuvid\.com/video/(?P<id>[0-9]+)'
13     _TEST = {
14         'url': 'http://m.nuvid.com/video/1310741/',
15         'md5': 'eab207b7ac4fccfb4e23c86201f11277',
16         'info_dict': {
17             'id': '1310741',
18             'ext': 'mp4',
19             'title': 'Horny babes show their awesome bodeis and',
20             'duration': 129,
21             'age_limit': 18,
22         }
23     }
24
25     def _real_extract(self, url):
26         video_id = self._match_id(url)
27
28         page_url = 'http://m.nuvid.com/video/%s' % video_id
29         webpage = self._download_webpage(
30             page_url, video_id, 'Downloading video page')
31         # When dwnld_speed exists and has a value larger than the MP4 file's
32         # bitrate, Nuvid returns the MP4 URL
33         # It's unit is 100bytes/millisecond, see mobile-nuvid-min.js for the algorithm
34         self._set_cookie('nuvid.com', 'dwnld_speed', '10.0')
35         mp4_webpage = self._download_webpage(
36             page_url, video_id, 'Downloading video page for MP4 format')
37
38         html5_video_re = r'(?s)<(?:video|audio)[^<]*(?:>.*?<source[^>]*)?\s+src=["\'](.*?)["\']',
39         video_url = self._html_search_regex(html5_video_re, webpage, video_id)
40         mp4_video_url = self._html_search_regex(html5_video_re, mp4_webpage, video_id)
41         formats = [{
42             'url': video_url,
43         }]
44         if mp4_video_url != video_url:
45             formats.append({
46                 'url': mp4_video_url,
47             })
48
49         title = self._html_search_regex(
50             [r'<span title="([^"]+)">',
51              r'<div class="thumb-holder video">\s*<h5[^>]*>([^<]+)</h5>',
52              r'<span[^>]+class="title_thumb">([^<]+)</span>'], webpage, 'title').strip()
53         thumbnails = [
54             {
55                 'url': thumb_url,
56             } for thumb_url in re.findall(r'<img src="([^"]+)" alt="" />', webpage)
57         ]
58         thumbnail = thumbnails[0]['url'] if thumbnails else None
59         duration = parse_duration(self._html_search_regex(
60             [r'<i class="fa fa-clock-o"></i>\s*(\d{2}:\d{2})',
61              r'<span[^>]+class="view_time">([^<]+)</span>'], webpage, 'duration', fatal=False))
62
63         return {
64             'id': video_id,
65             'title': title,
66             'thumbnails': thumbnails,
67             'thumbnail': thumbnail,
68             'duration': duration,
69             'age_limit': 18,
70             'formats': formats,
71         }