youtube-dl/test/test_postprocessors.py
辰言 1373b6dc11 Fix case-sensitivity bugs when handling uppercase file extensions
This fixes several bugs in youtube-dl where checking file extensions was case-sensitive, leading to double-extension output files (e.g. filename.MP4.mp4), postprocessor crashes when embedding thumbnails or converting formats, and failures to determine the format of trailing-slashed URLs. All checking logic is updated to compare extensions case-insensitively, and new unit tests are added to verify the fixes.
2026-06-30 16:02:53 +08:00

37 lines
1.2 KiB
Python

#!/usr/bin/env python
from __future__ import unicode_literals
# Allow direct execution
import os
import sys
import unittest
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from youtube_dl.postprocessor import MetadataFromTitlePP
class TestMetadataFromTitle(unittest.TestCase):
def test_format_to_regex(self):
pp = MetadataFromTitlePP(None, '%(title)s - %(artist)s')
self.assertEqual(pp._titleregex, r'(?P<title>.+)\ \-\ (?P<artist>.+)')
class TestEmbedThumbnail(unittest.TestCase):
def test_run_case_insensitive(self):
from youtube_dl.postprocessor import EmbedThumbnailPP
class DummyDownloader(object):
params = {}
def to_screen(self, msg):
pass
pp = EmbedThumbnailPP(DummyDownloader())
res_files, res_info = pp.run({'ext': 'MP3', 'filepath': 'file.mp3', 'thumbnails': []})
self.assertEqual(res_files, [])
self.assertEqual(res_info['ext'], 'MP3')
res_files, res_info = pp.run({'ext': 'MP4', 'filepath': 'file.mp4', 'thumbnails': []})
self.assertEqual(res_files, [])
self.assertEqual(res_info['ext'], 'MP4')