]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/beeg.py
debian/patches: Remove patch to disambiguate between ffmpeg and avconv.
[youtubedl] / youtube_dl / extractor / beeg.py
1 from __future__ import unicode_literals
2
3 from .common import InfoExtractor
4 from ..compat import compat_str
5 from ..utils import (
6 int_or_none,
7 unified_timestamp,
8 )
9
10
11 class BeegIE(InfoExtractor):
12 _VALID_URL = r'https?://(?:www\.)?beeg\.com/(?P<id>\d+)'
13 _TEST = {
14 'url': 'http://beeg.com/5416503',
15 'md5': 'a1a1b1a8bc70a89e49ccfd113aed0820',
16 'info_dict': {
17 'id': '5416503',
18 'ext': 'mp4',
19 'title': 'Sultry Striptease',
20 'description': 'md5:d22219c09da287c14bed3d6c37ce4bc2',
21 'timestamp': 1391813355,
22 'upload_date': '20140207',
23 'duration': 383,
24 'tags': list,
25 'age_limit': 18,
26 }
27 }
28
29 def _real_extract(self, url):
30 video_id = self._match_id(url)
31
32 webpage = self._download_webpage(url, video_id)
33
34 beeg_version = self._search_regex(
35 r'beeg_version\s*=\s*([\da-zA-Z_-]+)', webpage, 'beeg version',
36 default='1546225636701')
37
38 for api_path in ('', 'api.'):
39 video = self._download_json(
40 'https://%sbeeg.com/api/v6/%s/video/%s'
41 % (api_path, beeg_version, video_id), video_id,
42 fatal=api_path == 'api.')
43 if video:
44 break
45
46 formats = []
47 for format_id, video_url in video.items():
48 if not video_url:
49 continue
50 height = self._search_regex(
51 r'^(\d+)[pP]$', format_id, 'height', default=None)
52 if not height:
53 continue
54 formats.append({
55 'url': self._proto_relative_url(
56 video_url.replace('{DATA_MARKERS}', 'data=pc_XX__%s_0' % beeg_version), 'https:'),
57 'format_id': format_id,
58 'height': int(height),
59 })
60 self._sort_formats(formats)
61
62 title = video['title']
63 video_id = compat_str(video.get('id') or video_id)
64 display_id = video.get('code')
65 description = video.get('desc')
66 series = video.get('ps_name')
67
68 timestamp = unified_timestamp(video.get('date'))
69 duration = int_or_none(video.get('duration'))
70
71 tags = [tag.strip() for tag in video['tags'].split(',')] if video.get('tags') else None
72
73 return {
74 'id': video_id,
75 'display_id': display_id,
76 'title': title,
77 'description': description,
78 'series': series,
79 'timestamp': timestamp,
80 'duration': duration,
81 'tags': tags,
82 'formats': formats,
83 'age_limit': self._rta_search(webpage),
84 }