[beeg] PEP8 and additional tests
[youtube-dl] / youtube_dl / extractor / beeg.py
1 from __future__ import unicode_literals
2
3 import re
4
5 from .common import InfoExtractor
6
7
8 class BeegIE(InfoExtractor):
9     _VALID_URL = r'https?://(?:www\.)?beeg\.com/(?P<id>\d+)'
10     _TEST = {
11         'url': 'http://beeg.com/5416503',
12         'md5': '634526ae978711f6b748fe0dd6c11f57',
13         'info_dict': {
14             'id': '5416503',
15             'ext': 'mp4',
16             'title': 'Sultry Striptease',
17             'description': 'md5:6db3c6177972822aaba18652ff59c773',
18             'categories': list,  # NSFW
19             'thumbnail': 're:https?://.*\.jpg$',
20         }
21     }
22
23     def _real_extract(self, url):
24         mobj = re.match(self._VALID_URL, url)
25         video_id = mobj.group('id')
26
27         webpage = self._download_webpage(url, video_id)
28
29         video_url = self._html_search_regex(
30             r"'480p'\s*:\s*'([^']+)'", webpage, 'video URL')
31
32         title = self._html_search_regex(
33             r'<title>([^<]+)\s*-\s*beeg\.?</title>', webpage, 'title')
34         
35         description = self._html_search_regex(
36             r'<meta name="description" content="([^"]*)"',
37             webpage, 'description', fatal=False)
38         thumbnail = self._html_search_regex(
39             r'\'previewer.url\'\s*:\s*"([^"]*)"',
40             webpage, 'thumbnail', fatal=False)
41
42         categories_str = self._html_search_regex(
43             r'<meta name="keywords" content="([^"]+)"', webpage, 'categories', fatal=False)
44         categories = categories_str.split(',')
45
46         return {
47             'id': video_id,
48             'url': video_url,
49             'title': title,
50             'description': description,
51             'thumbnail': thumbnail,
52             'categories': categories,
53         }