mirror of
https://github.com/ytdl-org/youtube-dl.git
synced 2026-06-17 11:54:53 +00:00
Removes ~147k lines of code that's not needed for downloading YouTube
videos from a source checkout on macOS.
Extractors:
- Delete 806 non-YouTube extractor modules; rewrite extractors.py to
expose only the YouTube IE classes; drop GenericIE plumbing from
__init__.py.
Modules removed:
- update.py + --update flag (use git pull instead)
- swfinterp.py and aes.py (no remaining importers)
- traversal.py (15-line re-export stub of utils.py functions)
- casefold.py (Py2 polyfill)
- version.py (inlined the version string)
- socks.py + all SOCKS proxy plumbing in utils.py / YoutubeDL.py
- downloader/{f4m,ism,rtmp,rtsp,niconico}.py — protocols YouTube
doesn't use; inline the two F4M helpers common.py still references
CLI flags removed (with their __init__.py / YoutubeDL.py plumbing):
- --update / -U
- --force-generic-extractor (no GenericIE)
- --cn-verification-proxy (deprecated alias)
- --include-ads (no consumers)
- Adobe Pass: --ap-mso, --ap-username, --ap-password, --ap-list-mso
compat.py: simplified from 3886 to 408 lines by collapsing every
Py2/Py3.x try/except fallback to the Py3.12 path; deleted the 2234-
line html5 entity polyfill, the Py2.6 xpath reimplementation, and the
_workaround_optparse_bug9161 patcher.
utils.py: removed 8 dead helpers (bool_or_none, bytes_to_intlist,
decode_packed_codes, decode_png, get_element_by_id,
month_by_abbreviation, random_birthday, urlhandle_detect_ext) plus
the SOCKS-related code paths.
Repo hygiene:
- Deleted .github/ (CI + issue/PR templates), CONTRIBUTING.md, AUTHORS,
ChangeLog, Makefile, tox.ini, MANIFEST.in, setup.py, setup.cfg,
bin/youtube-dl, youtube-dl.plugin.zsh, docs/, devscripts/, LICENSE.
- Trimmed README.md to CLI-reference-only sections; removed dead refs
to deleted flags / extractors / upstream URLs.
- __main__.py: dropped sys.frozen check and __package__ sys.path fixup.
Verified: 69 local tests pass (test_YoutubeDL, test_compat,
test_InfoExtractor, test_cache, test_traversal, test_utils,
test_options); python3 -m youtube_dl --version works.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
84 lines
2.5 KiB
Python
84 lines
2.5 KiB
Python
#!/usr/bin/env python
|
|
# coding: utf-8
|
|
|
|
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__))))
|
|
|
|
import shutil
|
|
|
|
from test.helper import FakeYDL
|
|
from youtube_dl.cache import Cache
|
|
from youtube_dl.utils import version_tuple
|
|
__version__ = '2025.04.07'
|
|
|
|
|
|
def _is_empty(d):
|
|
return not bool(os.listdir(d))
|
|
|
|
|
|
def _mkdir(d):
|
|
if not os.path.exists(d):
|
|
os.mkdir(d)
|
|
|
|
|
|
class TestCache(unittest.TestCase):
|
|
def setUp(self):
|
|
TEST_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
TESTDATA_DIR = os.path.join(TEST_DIR, 'testdata')
|
|
_mkdir(TESTDATA_DIR)
|
|
self.test_dir = os.path.join(TESTDATA_DIR, 'cache_test')
|
|
self.tearDown()
|
|
|
|
def tearDown(self):
|
|
if os.path.exists(self.test_dir):
|
|
shutil.rmtree(self.test_dir)
|
|
|
|
def test_cache(self):
|
|
ydl = FakeYDL({
|
|
'cachedir': self.test_dir,
|
|
})
|
|
c = Cache(ydl)
|
|
obj = {'x': 1, 'y': ['ä', '\\a', True]}
|
|
self.assertEqual(c.load('test_cache', 'k.'), None)
|
|
c.store('test_cache', 'k.', obj)
|
|
self.assertEqual(c.load('test_cache', 'k2'), None)
|
|
self.assertFalse(_is_empty(self.test_dir))
|
|
self.assertEqual(c.load('test_cache', 'k.'), obj)
|
|
self.assertEqual(c.load('test_cache', 'y'), None)
|
|
self.assertEqual(c.load('test_cache2', 'k.'), None)
|
|
c.remove()
|
|
self.assertFalse(os.path.exists(self.test_dir))
|
|
self.assertEqual(c.load('test_cache', 'k.'), None)
|
|
|
|
def test_cache_validation(self):
|
|
ydl = FakeYDL({
|
|
'cachedir': self.test_dir,
|
|
})
|
|
c = Cache(ydl)
|
|
obj = {'x': 1, 'y': ['ä', '\\a', True]}
|
|
c.store('test_cache', 'k.', obj)
|
|
self.assertEqual(c.load('test_cache', 'k.', min_ver='1970.01.01'), obj)
|
|
new_version = '.'.join(('%0.2d' % ((v + 1) if i == 0 else v, )) for i, v in enumerate(version_tuple(__version__)))
|
|
self.assertIs(c.load('test_cache', 'k.', min_ver=new_version), None)
|
|
|
|
def test_cache_clear(self):
|
|
ydl = FakeYDL({
|
|
'cachedir': self.test_dir,
|
|
})
|
|
c = Cache(ydl)
|
|
c.store('test_cache', 'k.', 'kay')
|
|
c.store('test_cache', 'l.', 'ell')
|
|
self.assertEqual(c.load('test_cache', 'k.'), 'kay')
|
|
c.clear('test_cache', 'k.')
|
|
self.assertEqual(c.load('test_cache', 'k.'), None)
|
|
self.assertEqual(c.load('test_cache', 'l.'), 'ell')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|