]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/beeg.py
61bc2f7445a6fe115746b8f33b92421c2ab7e32c
[youtubedl] / youtube_dl / extractor / beeg.py
1 from __future__ import unicode_literals
2
3 from .common import InfoExtractor
4 from ..utils import (
5 int_or_none,
6 parse_iso8601,
7 )
8
9
10 class BeegIE(InfoExtractor):
11 _VALID_URL = r'https?://(?:www\.)?beeg\.com/(?P<id>\d+)'
12 _TEST = {
13 'url': 'http://beeg.com/5416503',
14 'md5': '46c384def73b33dbc581262e5ee67cef',
15 'info_dict': {
16 'id': '5416503',
17 'ext': 'mp4',
18 'title': 'Sultry Striptease',
19 'description': 'md5:d22219c09da287c14bed3d6c37ce4bc2',
20 'timestamp': 1391813355,
21 'upload_date': '20140207',
22 'duration': 383,
23 'tags': list,
24 'age_limit': 18,
25 }
26 }
27
28 def _real_extract(self, url):
29 video_id = self._match_id(url)
30
31 video = self._download_json(
32 'http://beeg.com/api/v1/video/%s' % video_id, video_id)
33
34 formats = []
35 for format_id, video_url in video.items():
36 if not video_url:
37 continue
38 height = self._search_regex(
39 r'^(\d+)[pP]$', format_id, 'height', default=None)
40 if not height:
41 continue
42 formats.append({
43 'url': self._proto_relative_url(video_url.replace('{DATA_MARKERS}', ''), 'http:'),
44 'format_id': format_id,
45 'height': int(height),
46 })
47 self._sort_formats(formats)
48
49 title = video['title']
50 video_id = video.get('id') or video_id
51 display_id = video.get('code')
52 description = video.get('desc')
53
54 timestamp = parse_iso8601(video.get('date'), ' ')
55 duration = int_or_none(video.get('duration'))
56
57 tags = [tag.strip() for tag in video['tags'].split(',')] if video.get('tags') else None
58
59 return {
60 'id': video_id,
61 'display_id': display_id,
62 'title': title,
63 'description': description,
64 'timestamp': timestamp,
65 'duration': duration,
66 'tags': tags,
67 'formats': formats,
68 'age_limit': 18,
69 }