]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/biqle.py
af21e3ee5e53fbfdfafa5ee219c541ee6ca97de3
[youtubedl] / youtube_dl / extractor / biqle.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from .vk import VKIE
6 from ..utils import (
7 HEADRequest,
8 int_or_none,
9 )
10
11
12 class BIQLEIE(InfoExtractor):
13 _VALID_URL = r'https?://(?:www\.)?biqle\.(?:com|org|ru)/watch/(?P<id>-?\d+_\d+)'
14 _TESTS = [{
15 # Youtube embed
16 'url': 'https://biqle.ru/watch/-115995369_456239081',
17 'md5': '97af5a06ee4c29bbf9c001bdb1cf5c06',
18 'info_dict': {
19 'id': '8v4f-avW-VI',
20 'ext': 'mp4',
21 'title': "PASSE-PARTOUT - L'ete c'est fait pour jouer",
22 'description': 'Passe-Partout',
23 'uploader_id': 'mrsimpsonstef3',
24 'uploader': 'Phanolito',
25 'upload_date': '20120822',
26 },
27 }, {
28 'url': 'http://biqle.org/watch/-44781847_168547604',
29 'md5': '7f24e72af1db0edf7c1aaba513174f97',
30 'info_dict': {
31 'id': '-44781847_168547604',
32 'ext': 'mp4',
33 'title': 'Ребенок в шоке от автоматической мойки',
34 'timestamp': 1396633454,
35 'uploader': 'Dmitry Kotov',
36 'upload_date': '20140404',
37 'uploader_id': '47850140',
38 },
39 }]
40
41 def _real_extract(self, url):
42 video_id = self._match_id(url)
43 webpage = self._download_webpage(url, video_id)
44 embed_url = self._proto_relative_url(self._search_regex(
45 r'<iframe.+?src="((?:https?:)?//(?:daxab\.com|dxb\.to|[^/]+/player)/[^"]+)".*?></iframe>',
46 webpage, 'embed url'))
47 if VKIE.suitable(embed_url):
48 return self.url_result(embed_url, VKIE.ie_key(), video_id)
49
50 self._request_webpage(
51 HEADRequest(embed_url), video_id, headers={'Referer': url})
52 video_id, sig, _, access_token = self._get_cookies(embed_url)['video_ext'].value.split('%3A')
53 item = self._download_json(
54 'https://api.vk.com/method/video.get', video_id,
55 headers={'User-Agent': 'okhttp/3.4.1'}, query={
56 'access_token': access_token,
57 'sig': sig,
58 'v': 5.44,
59 'videos': video_id,
60 })['response']['items'][0]
61 title = item['title']
62
63 formats = []
64 for f_id, f_url in item.get('files', {}).items():
65 if f_id == 'external':
66 return self.url_result(f_url)
67 ext, height = f_id.split('_')
68 formats.append({
69 'format_id': height + 'p',
70 'url': f_url,
71 'height': int_or_none(height),
72 'ext': ext,
73 })
74 self._sort_formats(formats)
75
76 thumbnails = []
77 for k, v in item.items():
78 if k.startswith('photo_') and v:
79 width = k.replace('photo_', '')
80 thumbnails.append({
81 'id': width,
82 'url': v,
83 'width': int_or_none(width),
84 })
85
86 return {
87 'id': video_id,
88 'title': title,
89 'formats': formats,
90 'comment_count': int_or_none(item.get('comments')),
91 'description': item.get('description'),
92 'duration': int_or_none(item.get('duration')),
93 'thumbnails': thumbnails,
94 'timestamp': int_or_none(item.get('date')),
95 'uploader': item.get('owner_id'),
96 'view_count': int_or_none(item.get('views')),
97 }