[test_all_urls] Add support for distributed URL matching test definition
[youtube-dl] / youtube_dl / extractor / extremetube.py
1 import os
2 import re
3
4 from .common import InfoExtractor
5 from ..utils import (
6     compat_urllib_parse_urlparse,
7     compat_urllib_request,
8     compat_urllib_parse,
9 )
10
11 class ExtremeTubeIE(InfoExtractor):
12     _VALID_URL = r'^(?:https?://)?(?:www\.)?(?P<url>extremetube\.com/.*?video/.+?(?P<videoid>[0-9]+))(?:[/?&]|$)'
13     _TESTS = [{
14         u'url': u'http://www.extremetube.com/video/music-video-14-british-euro-brit-european-cumshots-swallow-652431',
15         u'file': u'652431.mp4',
16         u'md5': u'1fb9228f5e3332ec8c057d6ac36f33e0',
17         u'info_dict': {
18             u"title": u"Music Video 14 british euro brit european cumshots swallow",
19             u"uploader": u"unknown",
20             u"age_limit": 18,
21         }
22     }, {
23         'url': 'http://www.extremetube.com/gay/video/abcde-1234',
24         'only_matching': True,
25     }]
26
27     def _real_extract(self, url):
28         mobj = re.match(self._VALID_URL, url)
29         video_id = mobj.group('videoid')
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 [^>]*?title="([^"]+)"[^>]*>\1<', webpage, u'title')
37         uploader = self._html_search_regex(r'>Posted by:(?=<)(?:\s|<[^>]*>)*(.+?)\|', webpage, u'uploader', fatal=False)
38         video_url = compat_urllib_parse.unquote(self._html_search_regex(r'video_url=(.+?)&amp;', webpage, u'video_url'))
39         path = compat_urllib_parse_urlparse(video_url).path
40         extension = os.path.splitext(path)[1][1:]
41         format = path.split('/')[5].split('_')[:2]
42         format = "-".join(format)
43
44         return {
45             'id': video_id,
46             'title': video_title,
47             'uploader': uploader,
48             'url': video_url,
49             'ext': extension,
50             'format': format,
51             'format_id': format,
52             'age_limit': 18,
53         }