]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/youjizz.py
Update changelog.
[youtubedl] / youtube_dl / extractor / youjizz.py
1 from __future__ import unicode_literals
2
3 import re
4
5 from .common import InfoExtractor
6 from ..utils import (
7 ExtractorError,
8 )
9
10
11 class YouJizzIE(InfoExtractor):
12 _VALID_URL = r'https?://(?:\w+\.)?youjizz\.com/videos/(?:[^/#?]+)?-(?P<id>[0-9]+)\.html(?:$|[?#])'
13 _TESTS = [{
14 'url': 'http://www.youjizz.com/videos/zeichentrick-1-2189178.html',
15 'md5': '07e15fa469ba384c7693fd246905547c',
16 'info_dict': {
17 'id': '2189178',
18 'ext': 'flv',
19 'title': 'Zeichentrick 1',
20 'age_limit': 18,
21 }
22 }, {
23 'url': 'http://www.youjizz.com/videos/-2189178.html',
24 'only_matching': True,
25 }]
26
27 def _real_extract(self, url):
28 video_id = self._match_id(url)
29 webpage = self._download_webpage(url, video_id)
30 age_limit = self._rta_search(webpage)
31 video_title = self._html_search_regex(
32 r'<title>\s*(.*)\s*</title>', webpage, 'title')
33
34 embed_page_url = self._search_regex(
35 r'(https?://www.youjizz.com/videos/embed/[0-9]+)',
36 webpage, 'embed page')
37 webpage = self._download_webpage(
38 embed_page_url, video_id, note='downloading embed page')
39
40 # Get the video URL
41 m_playlist = re.search(r'so.addVariable\("playlist", ?"(?P<playlist>.+?)"\);', webpage)
42 if m_playlist is not None:
43 playlist_url = m_playlist.group('playlist')
44 playlist_page = self._download_webpage(playlist_url, video_id,
45 'Downloading playlist page')
46 m_levels = list(re.finditer(r'<level bitrate="(\d+?)" file="(.*?)"', playlist_page))
47 if len(m_levels) == 0:
48 raise ExtractorError('Unable to extract video url')
49 videos = [(int(m.group(1)), m.group(2)) for m in m_levels]
50 (_, video_url) = sorted(videos)[0]
51 video_url = video_url.replace('%252F', '%2F')
52 else:
53 video_url = self._search_regex(r'so.addVariable\("file",encodeURIComponent\("(?P<source>[^"]+)"\)\);',
54 webpage, 'video URL')
55
56 return {
57 'id': video_id,
58 'url': video_url,
59 'title': video_title,
60 'ext': 'flv',
61 'format': 'flv',
62 'player_url': embed_page_url,
63 'age_limit': age_limit,
64 }