import base64
import re
import urllib.parse
from .common import InfoExtractor
from ..utils import (
int_or_none,
parse_duration,
parse_iso8601,
str_or_none,
str_to_int,
try_get,
unified_timestamp,
url_or_none,
)
class FourTubeBaseIE(InfoExtractor):
def _extract_formats(self, url, video_id, media_id, sources):
token_url = 'https://{}/{}/desktop/{}'.format(
self._TKN_HOST, media_id, '+'.join(sources))
parsed_url = urllib.parse.urlparse(url)
tokens = self._download_json(token_url, video_id, data=b'', headers={
'Origin': f'{parsed_url.scheme}://{parsed_url.hostname}',
'Referer': url,
})
return [{
'url': tokens[res]['token'],
'format_id': res + 'p',
'resolution': res + 'p',
'quality': int(res),
} for res in sources]
def _real_extract(self, url):
mobj = self._match_valid_url(url)
kind, video_id, display_id = mobj.group('kind', 'id', 'display_id')
if kind == 'm' or not display_id:
url = self._URL_TEMPLATE % video_id
webpage = self._download_webpage(url, video_id)
title = self._html_search_meta('name', webpage)
timestamp = parse_iso8601(self._html_search_meta(
'uploadDate', webpage))
thumbnail = self._html_search_meta('thumbnailUrl', webpage)
uploader_id = self._html_search_regex(
r'',
webpage, 'uploader id', fatal=False)
uploader = self._html_search_regex(
r'',
webpage, 'uploader', fatal=False)
categories_html = self._search_regex(
r'(?s)>\s*Categories / Tags\s*.*?',
webpage, 'categories', fatal=False)
categories = None
if categories_html:
categories = [
c.strip() for c in re.findall(
r'(?s)(.*?)', categories_html)]
view_count = str_to_int(self._search_regex(
r']+itemprop="interactionCount"[^>]+content="UserPlays:([0-9,]+)">',
webpage, 'view count', default=None))
like_count = str_to_int(self._search_regex(
r']+itemprop="interactionCount"[^>]+content="UserLikes:([0-9,]+)">',
webpage, 'like count', default=None))
duration = parse_duration(self._html_search_meta('duration', webpage))
media_id = self._search_regex(
r'