1
0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2025-09-03 00:25:08 +00:00

[cleanup] Add more ruff rules (#10149)

Authored by: seproDev

Reviewed-by: bashonly <88596187+bashonly@users.noreply.github.com>
Reviewed-by: Simon Sawicki <contact@grub4k.xyz>
This commit is contained in:
sepro
2024-06-12 01:09:58 +02:00
committed by GitHub
parent db50f19d76
commit add96eb9f8
915 changed files with 7027 additions and 7246 deletions

View File

@ -1,5 +1,4 @@
from .common import InfoExtractor
from ..compat import compat_str
from ..utils import (
ExtractorError,
int_or_none,
@ -21,8 +20,8 @@ class WhoWatchIE(InfoExtractor):
def _real_extract(self, url):
video_id = self._match_id(url)
self._download_webpage(url, video_id)
metadata = self._download_json('https://api.whowatch.tv/lives/%s' % video_id, video_id)
live_data = self._download_json('https://api.whowatch.tv/lives/%s/play' % video_id, video_id)
metadata = self._download_json(f'https://api.whowatch.tv/lives/{video_id}', video_id)
live_data = self._download_json(f'https://api.whowatch.tv/lives/{video_id}/play', video_id)
title = try_call(
lambda: live_data['share_info']['live_title'][1:-1],
@ -37,7 +36,7 @@ class WhoWatchIE(InfoExtractor):
formats = []
for i, fmt in enumerate(live_data.get('streams') or []):
name = fmt.get('quality') or fmt.get('name') or compat_str(i)
name = fmt.get('quality') or fmt.get('name') or str(i)
hls_url = fmt.get('hls_url')
rtmp_url = fmt.get('rtmp_url')
audio_only = fmt.get('audio_only')
@ -45,7 +44,7 @@ class WhoWatchIE(InfoExtractor):
if hls_url:
hls_fmts = self._extract_m3u8_formats(
hls_url, video_id, ext='mp4', m3u8_id='hls-%s' % name, quality=quality)
hls_url, video_id, ext='mp4', m3u8_id=f'hls-{name}', quality=quality)
formats.extend(hls_fmts)
else:
hls_fmts = []
@ -54,7 +53,7 @@ class WhoWatchIE(InfoExtractor):
if rtmp_url and not audio_only:
formats.append({
'url': rtmp_url,
'format_id': 'rtmp-%s' % name,
'format_id': f'rtmp-{name}',
'ext': 'mp4',
'protocol': 'rtmp_ffmpeg', # ffmpeg can, while rtmpdump can't
'vcodec': 'h264',
@ -71,12 +70,12 @@ class WhoWatchIE(InfoExtractor):
hls_url, video_id, ext='mp4', m3u8_id='hls'))
self._remove_duplicate_formats(formats)
uploader_url = try_get(metadata, lambda x: x['live']['user']['user_path'], compat_str)
uploader_url = try_get(metadata, lambda x: x['live']['user']['user_path'], str)
if uploader_url:
uploader_url = 'https://whowatch.tv/profile/%s' % uploader_url
uploader_id = compat_str(try_get(metadata, lambda x: x['live']['user']['id'], int))
uploader = try_get(metadata, lambda x: x['live']['user']['name'], compat_str)
thumbnail = try_get(metadata, lambda x: x['live']['latest_thumbnail_url'], compat_str)
uploader_url = f'https://whowatch.tv/profile/{uploader_url}'
uploader_id = str(try_get(metadata, lambda x: x['live']['user']['id'], int))
uploader = try_get(metadata, lambda x: x['live']['user']['name'], str)
thumbnail = try_get(metadata, lambda x: x['live']['latest_thumbnail_url'], str)
timestamp = int_or_none(try_get(metadata, lambda x: x['live']['started_at'], int), scale=1000)
view_count = try_get(metadata, lambda x: x['live']['total_view_count'], int)
comment_count = try_get(metadata, lambda x: x['live']['comment_count'], int)