]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/mofosex.py
Initiate a new release.
[youtubedl] / youtube_dl / extractor / mofosex.py
1 from __future__ import unicode_literals
2
3 import os
4 import re
5
6 from .common import InfoExtractor
7 from ..compat import (
8 compat_urllib_parse_urlparse,
9 compat_urllib_request,
10 compat_urllib_parse,
11 )
12
13
14 class MofosexIE(InfoExtractor):
15 _VALID_URL = r'https?://(?:www\.)?(?P<url>mofosex\.com/videos/(?P<id>[0-9]+)/.*?\.html)'
16 _TEST = {
17 'url': 'http://www.mofosex.com/videos/5018/japanese-teen-music-video.html',
18 'md5': '1b2eb47ac33cc75d4a80e3026b613c5a',
19 'info_dict': {
20 'id': '5018',
21 'ext': 'mp4',
22 'title': 'Japanese Teen Music Video',
23 'age_limit': 18,
24 }
25 }
26
27 def _real_extract(self, url):
28 mobj = re.match(self._VALID_URL, url)
29 video_id = mobj.group('id')
30 url = 'http://www.' + mobj.group('url')
31
32 req = compat_urllib_request.Request(url)
33 req.add_header('Cookie', 'age_verified=1')
34 webpage = self._download_webpage(req, video_id)
35
36 video_title = self._html_search_regex(r'<h1>(.+?)<', webpage, 'title')
37 video_url = compat_urllib_parse.unquote(self._html_search_regex(r'flashvars.video_url = \'([^\']+)', webpage, 'video_url'))
38 path = compat_urllib_parse_urlparse(video_url).path
39 extension = os.path.splitext(path)[1][1:]
40 format = path.split('/')[5].split('_')[:2]
41 format = "-".join(format)
42
43 age_limit = self._rta_search(webpage)
44
45 return {
46 'id': video_id,
47 'title': video_title,
48 'url': video_url,
49 'ext': extension,
50 'format': format,
51 'format_id': format,
52 'age_limit': age_limit,
53 }