]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/gab.py
[test/cookies] Improve logging
[yt-dlp.git] / yt_dlp / extractor / gab.py
CommitLineData
2acf2ce5
A
1# coding: utf-8
2from __future__ import unicode_literals
3
4import re
5
6from .common import InfoExtractor
7from ..utils import (
8 clean_html,
9 str_to_int,
10)
11
12
13class GabTVIE(InfoExtractor):
14 _VALID_URL = r'(?:https?://)tv.gab.com/channel/[^/]+/view/(?P<id>[a-z0-9-]+)'
15 _TESTS = [{
16 'url': 'https://tv.gab.com/channel/wurzelroot/view/why-was-america-in-afghanistan-61217eacea5665de450d0488',
17 'info_dict': {
18 'id': '61217eacea5665de450d0488',
19 'ext': 'mp4',
20 'title': 'WHY WAS AMERICA IN AFGHANISTAN - AMERICA FIRST AGAINST AMERICAN OLIGARCHY',
21 'description': None,
22 'uploader': 'Wurzelroot',
23 'uploader_id': '608fb0a85738fd1974984f7d',
24 'thumbnail': 'https://tv.gab.com/image/61217eacea5665de450d0488',
25 }
26 }]
27
28 def _real_extract(self, url):
29 id = self._match_id(url).split('-')[-1]
30 webpage = self._download_webpage(url, id)
31 channel_id = self._search_regex(r'data-channel-id=\"(?P<channel_id>[^\"]+)', webpage, 'channel_id')
32 channel_name = self._search_regex(r'data-channel-name=\"(?P<channel_id>[^\"]+)', webpage, 'channel_name')
33 title = self._search_regex(r'data-episode-title=\"(?P<channel_id>[^\"]+)', webpage, 'title')
34 view_key = self._search_regex(r'data-view-key=\"(?P<channel_id>[^\"]+)', webpage, 'view_key')
35 description = clean_html(self._html_search_regex(self._meta_regex('description'), webpage, 'description', group='content')) or None
36 available_resolutions = re.findall(r'<a\ data-episode-id=\"%s\"\ data-resolution=\"(?P<resolution>[^\"]+)' % id, webpage)
37
38 formats = []
39 for resolution in available_resolutions:
40 frmt = {
41 'url': f'https://tv.gab.com/media/{id}?viewKey={view_key}&r={resolution}',
42 'format_id': resolution,
43 'vcodec': 'h264',
44 'acodec': 'aac',
45 'ext': 'mp4'
46 }
47 if 'audio-' in resolution:
48 frmt['abr'] = str_to_int(resolution.replace('audio-', ''))
49 frmt['height'] = 144
50 frmt['quality'] = -10
51 else:
52 frmt['height'] = str_to_int(resolution.replace('p', ''))
53 formats.append(frmt)
54 self._sort_formats(formats)
55
56 return {
57 'id': id,
58 'title': title,
59 'formats': formats,
60 'description': description,
61 'uploader': channel_name,
62 'uploader_id': channel_id,
63 'thumbnail': f'https://tv.gab.com/image/{id}',
64 }