]> jfr.im git - yt-dlp.git/blame - youtube_dlc/extractor/nuvid.py
#72 Fix issue with unicode filenames in aria2c (Closes #71)
[yt-dlp.git] / youtube_dlc / extractor / nuvid.py
CommitLineData
87724af7
PH
1from __future__ import unicode_literals
2
749fe60c 3import re
4
5from .common import InfoExtractor
3048e82a
S
6from ..utils import (
7 parse_duration,
3048e82a 8)
749fe60c 9
87724af7 10
749fe60c 11class NuvidIE(InfoExtractor):
1cc79574 12 _VALID_URL = r'https?://(?:www|m)\.nuvid\.com/video/(?P<id>[0-9]+)'
749fe60c 13 _TEST = {
87724af7
PH
14 'url': 'http://m.nuvid.com/video/1310741/',
15 'md5': 'eab207b7ac4fccfb4e23c86201f11277',
16 'info_dict': {
17 'id': '1310741',
18 'ext': 'mp4',
3048e82a
S
19 'title': 'Horny babes show their awesome bodeis and',
20 'duration': 129,
3048e82a 21 'age_limit': 18,
749fe60c 22 }
23 }
24
25 def _real_extract(self, url):
1cc79574 26 video_id = self._match_id(url)
749fe60c 27
0cbcbdd8
YCH
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')
87724af7 37
0cbcbdd8
YCH
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:
3048e82a 45 formats.append({
0cbcbdd8 46 'url': mp4_video_url,
3048e82a 47 })
87724af7 48
3048e82a 49 title = self._html_search_regex(
394df6d7 50 [r'<span title="([^"]+)">',
0cbcbdd8
YCH
51 r'<div class="thumb-holder video">\s*<h5[^>]*>([^<]+)</h5>',
52 r'<span[^>]+class="title_thumb">([^<]+)</span>'], webpage, 'title').strip()
394df6d7
S
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
3048e82a 59 duration = parse_duration(self._html_search_regex(
0cbcbdd8
YCH
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))
87724af7
PH
62
63 return {
64 'id': video_id,
87724af7 65 'title': title,
394df6d7
S
66 'thumbnails': thumbnails,
67 'thumbnail': thumbnail,
3048e82a 68 'duration': duration,
87724af7 69 'age_limit': 18,
3048e82a 70 'formats': formats,
5f6a1245 71 }