]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/biqle.py
[cleanup] Use `_html_extract_title`
[yt-dlp.git] / yt_dlp / extractor / biqle.py
CommitLineData
04e88ca2 1# coding: utf-8
2from __future__ import unicode_literals
3
4from .common import InfoExtractor
e7e3ec82 5from .vk import VKIE
5625e607
B
6from ..compat import compat_b64decode
7from ..utils import (
8 int_or_none,
9 js_to_json,
10 traverse_obj,
11 unified_timestamp,
e7e3ec82 12)
04e88ca2 13
14
15class BIQLEIE(InfoExtractor):
16 _VALID_URL = r'https?://(?:www\.)?biqle\.(?:com|org|ru)/watch/(?P<id>-?\d+_\d+)'
17 _TESTS = [{
5625e607
B
18 'url': 'https://biqle.ru/watch/-2000421746_85421746',
19 'md5': 'ae6ef4f04d19ac84e4658046d02c151c',
04e88ca2 20 'info_dict': {
5625e607 21 'id': '-2000421746_85421746',
04e88ca2 22 'ext': 'mp4',
5625e607
B
23 'title': 'Forsaken By Hope Studio Clip',
24 'description': 'Forsaken By Hope Studio Clip — Смотреть онлайн',
25 'upload_date': '19700101',
26 'thumbnail': r're:https://[^/]+/impf/7vN3ACwSTgChP96OdOfzFjUCzFR6ZglDQgWsIw/KPaACiVJJxM\.jpg\?size=800x450&quality=96&keep_aspect_ratio=1&background=000000&sign=b48ea459c4d33dbcba5e26d63574b1cb&type=video_thumb',
27 'timestamp': 0,
e7e3ec82 28 },
04e88ca2 29 }, {
e7e3ec82 30 'url': 'http://biqle.org/watch/-44781847_168547604',
04e88ca2 31 'md5': '7f24e72af1db0edf7c1aaba513174f97',
32 'info_dict': {
220828f2 33 'id': '-44781847_168547604',
04e88ca2 34 'ext': 'mp4',
35 'title': 'Ребенок в шоке от автоматической мойки',
5625e607 36 'description': 'Ребенок в шоке от автоматической мойки — Смотреть онлайн',
e7e3ec82 37 'timestamp': 1396633454,
e7e3ec82 38 'upload_date': '20140404',
5625e607 39 'thumbnail': r're:https://[^/]+/c535507/u190034692/video/l_b84df002\.jpg',
d7120712 40 },
04e88ca2 41 }]
42
43 def _real_extract(self, url):
44 video_id = self._match_id(url)
45 webpage = self._download_webpage(url, video_id)
5625e607
B
46
47 title = self._html_search_meta('name', webpage, 'Title', fatal=False)
48 timestamp = unified_timestamp(self._html_search_meta('uploadDate', webpage, 'Upload Date', default=None))
49 description = self._html_search_meta('description', webpage, 'Description', default=None)
50
51 global_embed_url = self._search_regex(
52 r'<script[^<]+?window.globEmbedUrl\s*=\s*\'((?:https?:)?//(?:daxab\.com|dxb\.to|[^/]+/player)/[^\']+)\'',
53 webpage, 'global Embed url')
54 hash = self._search_regex(
55 r'<script id="data-embed-video[^<]+?hash: "([^"]+)"[^<]*</script>', webpage, 'Hash')
56
57 embed_url = global_embed_url + hash
58
e7e3ec82
RA
59 if VKIE.suitable(embed_url):
60 return self.url_result(embed_url, VKIE.ie_key(), video_id)
61
f5863a3e 62 embed_page = self._download_webpage(
5625e607
B
63 embed_url, video_id, 'Downloading embed webpage', headers={'Referer': url})
64
65 glob_params = self._parse_json(self._search_regex(
66 r'<script id="globParams">[^<]*window.globParams = ([^;]+);[^<]+</script>',
67 embed_page, 'Global Parameters'), video_id, transform_source=js_to_json)
68 host_name = compat_b64decode(glob_params['server'][::-1]).decode()
69
e7e3ec82 70 item = self._download_json(
5625e607
B
71 f'https://{host_name}/method/video.get/{video_id}', video_id,
72 headers={'Referer': url}, query={
73 'token': glob_params['video']['access_token'],
e7e3ec82 74 'videos': video_id,
5625e607
B
75 'ckey': glob_params['c_key'],
76 'credentials': glob_params['video']['credentials'],
e7e3ec82 77 })['response']['items'][0]
e7e3ec82
RA
78
79 formats = []
80 for f_id, f_url in item.get('files', {}).items():
81 if f_id == 'external':
82 return self.url_result(f_url)
83 ext, height = f_id.split('_')
5625e607
B
84 height_extra_key = traverse_obj(glob_params, ('video', 'partial', 'quality', height))
85 if height_extra_key:
86 formats.append({
87 'format_id': f'{height}p',
88 'url': f'https://{host_name}/{f_url[8:]}&videos={video_id}&extra_key={height_extra_key}',
89 'height': int_or_none(height),
90 'ext': ext,
91 })
e7e3ec82
RA
92 self._sort_formats(formats)
93
94 thumbnails = []
95 for k, v in item.items():
96 if k.startswith('photo_') and v:
97 width = k.replace('photo_', '')
98 thumbnails.append({
99 'id': width,
100 'url': v,
101 'width': int_or_none(width),
102 })
04e88ca2 103
104 return {
e7e3ec82
RA
105 'id': video_id,
106 'title': title,
107 'formats': formats,
108 'comment_count': int_or_none(item.get('comments')),
5625e607 109 'description': description,
e7e3ec82
RA
110 'duration': int_or_none(item.get('duration')),
111 'thumbnails': thumbnails,
5625e607 112 'timestamp': timestamp,
e7e3ec82 113 'view_count': int_or_none(item.get('views')),
04e88ca2 114 }