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