]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/nuvid.py
debian/changelog: Finalize release.
[youtubedl] / 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 unified_strdate,
9 compat_urllib_request,
10 )
11
12
13 class NuvidIE(InfoExtractor):
14 _VALID_URL = r'^https?://(?:www|m)\.nuvid\.com/video/(?P<id>[0-9]+)'
15 _TEST = {
16 'url': 'http://m.nuvid.com/video/1310741/',
17 'md5': 'eab207b7ac4fccfb4e23c86201f11277',
18 'info_dict': {
19 'id': '1310741',
20 'ext': 'mp4',
21 'title': 'Horny babes show their awesome bodeis and',
22 'duration': 129,
23 'upload_date': '20140508',
24 'age_limit': 18,
25 }
26 }
27
28 def _real_extract(self, url):
29 mobj = re.match(self._VALID_URL, url)
30 video_id = mobj.group('id')
31
32 formats = []
33
34 for dwnld_speed, format_id in [(0, '3gp'), (5, 'mp4')]:
35 request = compat_urllib_request.Request(
36 'http://m.nuvid.com/play/%s' % video_id)
37 request.add_header('Cookie', 'skip_download_page=1; dwnld_speed=%d; adv_show=1' % dwnld_speed)
38 webpage = self._download_webpage(
39 request, video_id, 'Downloading %s page' % format_id)
40 video_url = self._html_search_regex(
41 r'<a href="([^"]+)"\s*>Continue to watch video', webpage, '%s video URL' % format_id, fatal=False)
42 if not video_url:
43 continue
44 formats.append({
45 'url': video_url,
46 'format_id': format_id,
47 })
48
49 webpage = self._download_webpage(
50 'http://m.nuvid.com/video/%s' % video_id, video_id, 'Downloading video page')
51 title = self._html_search_regex(
52 r'<div class="title">\s+<h2[^>]*>([^<]+)</h2>', webpage, 'title').strip()
53 thumbnail = self._html_search_regex(
54 r'href="(/thumbs/[^"]+)"[^>]*data-link_type="thumbs"',
55 webpage, 'thumbnail URL', fatal=False)
56 duration = parse_duration(self._html_search_regex(
57 r'Length:\s*<span>(\d{2}:\d{2})</span>',webpage, 'duration', fatal=False))
58 upload_date = unified_strdate(self._html_search_regex(
59 r'Added:\s*<span>(\d{4}-\d{2}-\d{2})</span>', webpage, 'upload date', fatal=False))
60
61 return {
62 'id': video_id,
63 'title': title,
64 'thumbnail': 'http://m.nuvid.com%s' % thumbnail,
65 'duration': duration,
66 'upload_date': upload_date,
67 'age_limit': 18,
68 'formats': formats,
69 }