]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/youjizz.py
6f022670cb9ef076a002c387e6357d99ec87d402
[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 }
18 }
19
20 def _real_extract(self, url):
21 mobj = re.match(self._VALID_URL, url)
22
23 video_id = mobj.group('videoid')
24
25 # Get webpage content
26 webpage = self._download_webpage(url, video_id)
27
28 # Get the video title
29 video_title = self._html_search_regex(r'<title>(?P<title>.*)</title>',
30 webpage, u'title').strip()
31
32 # Get the embed page
33 result = re.search(r'https?://www.youjizz.com/videos/embed/(?P<videoid>[0-9]+)', webpage)
34 if result is None:
35 raise ExtractorError(u'ERROR: unable to extract embed page')
36
37 embed_page_url = result.group(0).strip()
38 video_id = result.group('videoid')
39
40 webpage = self._download_webpage(embed_page_url, video_id)
41
42 # Get the video URL
43 video_url = self._search_regex(r'so.addVariable\("file",encodeURIComponent\("(?P<source>[^"]+)"\)\);',
44 webpage, u'video URL')
45
46 info = {'id': video_id,
47 'url': video_url,
48 'title': video_title,
49 'ext': 'flv',
50 'format': 'flv',
51 'player_url': embed_page_url}
52
53 return [info]