Compare commits

...

5 Commits

Author SHA1 Message Date
Nikita Korolev
701b06adda
Merge 1974b2b332 into 4b5eec0aaa 2024-11-25 14:42:21 +05:30
Jakob Kruse
4b5eec0aaa
[ie/chaturbate] Fix support for non-public streams (#11624)
Fix bug in 720b3dc453

Closes #11623
Authored by: jkruse
2024-11-24 22:20:30 +00:00
ds
1974b2b332 do not strip whitespace characters 2023-09-06 09:55:51 +03:00
ds
46cebee490 restore previous join_nonempty() 2023-08-25 23:26:31 +03:00
ds
fcafc42927 fix for --trim-file-names bug (#5526) 2023-08-25 14:44:21 +03:00
3 changed files with 22 additions and 14 deletions

View File

@ -900,6 +900,15 @@ class TestYoutubeDL(unittest.TestCase):
# test('%(foo|)s.%(ext)s', ('.mp4', '_.mp4')) # FIXME: ? # test('%(foo|)s.%(ext)s', ('.mp4', '_.mp4')) # FIXME: ?
# test('%(foo|)s', ('', '_')) # FIXME: ? # test('%(foo|)s', ('', '_')) # FIXME: ?
# Trim filename
test('%(id)s.%(filesize)s.%(ext)s', ('1234.1024.mp4', '123.mp4'), trim_file_name=3)
test(
'%(id)s.%(filesize)s.%(ext)s',
('1234.1024.info.json', '123.info.json'),
info=dict(self.outtmpl_info, ext='info.json'), trim_file_name=3
)
test('12 34.%(filesize)s.%(ext)s', ('12 34.1024.mp4', '12 .mp4'), trim_file_name=3)
# Environment variable expansion for prepare_filename # Environment variable expansion for prepare_filename
os.environ['__yt_dlp_var'] = 'expanded' os.environ['__yt_dlp_var'] = 'expanded'
envvar = '%__yt_dlp_var%' if os.name == 'nt' else '$__yt_dlp_var' envvar = '%__yt_dlp_var%' if os.name == 'nt' else '$__yt_dlp_var'

View File

@ -1428,6 +1428,12 @@ class YoutubeDL:
if not filename: if not filename:
return None return None
trim_file_name = self.params.get('trim_file_name')
if trim_file_name:
# https://github.com/yt-dlp/yt-dlp/issues/5526#issuecomment-1312783517
no_ext, *ext = filename.rsplit('.', info_dict.get('ext', '').count('.') + 1)
filename = join_nonempty(no_ext[:trim_file_name], *ext, delim='.')
if tmpl_type in ('', 'temp'): if tmpl_type in ('', 'temp'):
final_ext, ext = self.params.get('final_ext'), info_dict.get('ext') final_ext, ext = self.params.get('final_ext'), info_dict.get('ext')
if final_ext and ext and final_ext != ext and filename.endswith(f'.{final_ext}'): if final_ext and ext and final_ext != ext and filename.endswith(f'.{final_ext}'):
@ -1437,12 +1443,6 @@ class YoutubeDL:
if force_ext: if force_ext:
filename = replace_extension(filename, force_ext, info_dict.get('ext')) filename = replace_extension(filename, force_ext, info_dict.get('ext'))
# https://github.com/blackjack4494/youtube-dlc/issues/85
trim_file_name = self.params.get('trim_file_name', False)
if trim_file_name:
no_ext, *ext = filename.rsplit('.', 2)
filename = join_nonempty(no_ext[:trim_file_name], *ext, delim='.')
return filename return filename
except ValueError as err: except ValueError as err:
self.report_error('Error in output template: ' + str(err) + ' (encoding: ' + repr(preferredencoding()) + ')') self.report_error('Error in output template: ' + str(err) + ' (encoding: ' + repr(preferredencoding()) + ')')

View File

@ -59,16 +59,15 @@ class ChaturbateIE(InfoExtractor):
'Accept': 'application/json', 'Accept': 'application/json',
}, fatal=False, impersonate=True) or {} }, fatal=False, impersonate=True) or {}
status = response.get('room_status')
if status != 'public':
if error := self._ERROR_MAP.get(status):
raise ExtractorError(error, expected=True)
self.report_warning('Falling back to webpage extraction')
return None
m3u8_url = response.get('url') m3u8_url = response.get('url')
if not m3u8_url: if not m3u8_url:
status = response.get('room_status')
if error := self._ERROR_MAP.get(status):
raise ExtractorError(error, expected=True)
if status == 'public':
self.raise_geo_restricted() self.raise_geo_restricted()
self.report_warning(f'Got status "{status}" from API; falling back to webpage extraction')
return None
return { return {
'id': video_id, 'id': video_id,