From 8063b142d98dca27cdd5eb104d13b312b8557897 Mon Sep 17 00:00:00 2001 From: 7x11x13 Date: Wed, 8 Jan 2025 15:00:02 -0500 Subject: [PATCH] Remove --filesystem-encoding option --- test/test_YoutubeDL.py | 15 ++++++++++----- yt_dlp/YoutubeDL.py | 4 ++-- yt_dlp/__init__.py | 8 -------- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/test/test_YoutubeDL.py b/test/test_YoutubeDL.py index d65cc1153..bb7d81484 100644 --- a/test/test_YoutubeDL.py +++ b/test/test_YoutubeDL.py @@ -2,6 +2,7 @@ # Allow direct execution import os +import platform import sys import unittest from unittest.mock import patch @@ -930,11 +931,15 @@ def gen(): # --trim-filenames test('%(title6)s.%(ext)s', 'あ' * 10 + '.mp4') test('%(title6)s.%(ext)s', 'あ' * 3 + '.mp4', trim_file_name='3c') - test('%(title6)s.%(ext)s', 'あ' * 3 + '.mp4', trim_file_name='9b', filesystem_encoding='utf-8') - test('%(title6)s.%(ext)s', 'あ' * 3 + '.mp4', trim_file_name='10b', filesystem_encoding='utf-8') - test('%(title6)s.%(ext)s', 'あ' * 3 + '.mp4', trim_file_name='11b', filesystem_encoding='utf-8') - test('%(title6)s.%(ext)s', 'あ' * 4 + '.mp4', trim_file_name='12b', filesystem_encoding='utf-8') - test('%(title6)s.%(ext)s', 'あ' * 6 + '.mp4', trim_file_name='12b', filesystem_encoding='utf-16le') + if sys.getfilesystemencoding() == 'utf-8' and platform.system() != 'Windows': + test('%(title6)s.%(ext)s', 'あ' * 3 + '.mp4', trim_file_name='9b') + test('%(title6)s.%(ext)s', 'あ' * 3 + '.mp4', trim_file_name='10b') + test('%(title6)s.%(ext)s', 'あ' * 3 + '.mp4', trim_file_name='11b') + test('%(title6)s.%(ext)s', 'あ' * 4 + '.mp4', trim_file_name='12b') + elif platform.system() == 'Windows': + test('%(title6)s.%(ext)s', 'あ' * 4 + '.mp4', trim_file_name='8b') + test('%(title6)s.%(ext)s', 'あ' * 4 + '.mp4', trim_file_name='9b') + test('%(title6)s.%(ext)s', 'あ' * 5 + '.mp4', trim_file_name='10b') test('folder/%(title6)s.%(ext)s', f'fol{os.path.sep}あああ.mp4', trim_file_name='3c') def test_format_note(self): diff --git a/yt_dlp/YoutubeDL.py b/yt_dlp/YoutubeDL.py index 287556075..2c8d54d86 100644 --- a/yt_dlp/YoutubeDL.py +++ b/yt_dlp/YoutubeDL.py @@ -13,6 +13,7 @@ import operator import os from pathlib import Path +import platform import random import re import shutil @@ -267,7 +268,6 @@ class YoutubeDL: outtmpl_na_placeholder: Placeholder for unavailable meta fields. restrictfilenames: Do not allow "&" and spaces in file names trim_file_name: Limit length of filename (extension excluded) - filesystem_encoding: Encoding to use when calculating filename length in bytes windowsfilenames: True: Force filenames to be Windows compatible False: Sanitize filenames only minimally This option has no effect when running on Windows @@ -1449,7 +1449,7 @@ def parse_trim_file_name(trim_file_name): # no maximum return filename + suffix - encoding = self.params.get('filesystem_encoding') or sys.getfilesystemencoding() + encoding = sys.getfilesystemencoding() if platform.system() != 'Windows' else 'utf-16-le' def trim_filename(name: str): if mode == 'b': diff --git a/yt_dlp/__init__.py b/yt_dlp/__init__.py index 69fb2c7e5..e49e73fef 100644 --- a/yt_dlp/__init__.py +++ b/yt_dlp/__init__.py @@ -1,4 +1,3 @@ -import codecs import sys if sys.version_info < (3, 9): @@ -432,12 +431,6 @@ def metadataparser_actions(f): # Other options validate_regex('trim filenames', opts.trim_file_name, r'(?:\d+[bc]?|notrim)') - if opts.filesystem_encoding is not None: - try: - codecs.lookup(opts.filesystem_encoding) - except LookupError: - raise ValueError(f'Invalid filesystem encoding: {opts.filesystem_encoding}') - if opts.playlist_items is not None: try: tuple(PlaylistEntries.parse_playlist_items(opts.playlist_items)) @@ -895,7 +888,6 @@ def parse_options(argv=None): 'max_downloads': opts.max_downloads, 'prefer_free_formats': opts.prefer_free_formats, 'trim_file_name': opts.trim_file_name, - 'filesystem_encoding': opts.filesystem_encoding, 'verbose': opts.verbose, 'dump_intermediate_pages': opts.dump_intermediate_pages, 'write_pages': opts.write_pages,