Removing unused code. Matching use of style for file name parsing.

This commit is contained in:
Roland 2022-12-14 10:33:11 -07:00
parent 282713537c
commit 9b048af7fd
No known key found for this signature in database
GPG key ID: 9D6DBD3ACF11AB93
7 changed files with 24 additions and 82 deletions

View file

@ -58,50 +58,6 @@ def get_no_channel_directory() -> pathlib.Path:
return directory
@iterify(set)
def remove_duplicate_video_paths(paths: Iterable[Path]) -> Set[Path]:
"""
Remove any duplicate paths from a given list.
Duplicate is defined as any file that shares the EXACT same name as another file, but with a different extension.
If a duplicate is found, only yield one of the paths. The path that will be yielded will be whichever is first in
the VIDEO_EXTESIONS tuple.
i.e.
>>> remove_duplicate_video_paths([Path('one.mp4'), Path('two.mp4'), Path('one.ogg')])
{'one.mp4, 'two.mp4'}
"""
new_paths = {}
# Group all paths by their name, but without their extension.
for path in set(paths):
name, _, _ = path.name.rpartition(path.suffix)
try:
new_paths[name].append(path)
except KeyError:
new_paths[name] = [path]
# Yield back the first occurrence of the preferred format for each video.
for name, paths in new_paths.items():
if len(paths) == 1:
# This should be the most common case. Most videos will only have one format.
yield paths[0]
else:
path_strings = [i.name for i in paths]
for ext in VIDEO_EXTENSIONS:
try:
index = path_strings.index(f'{name}.{ext}')
yield paths[index]
break
except ValueError:
# That extension is not in the paths.
pass
else:
# Somehow no format was found, yield back the first one. This is probably caused by an unexpected video
# format in the paths.
yield sorted(paths)[0]
def check_for_channel_conflicts(session: Session, id_=None, url=None, name=None, directory=None,
source_id=None):
"""

View file

@ -14,8 +14,7 @@ from wrolpi.dates import local_timezone, now
from wrolpi.downloader import Download, DownloadFrequency
from wrolpi.vars import PROJECT_DIR
from .. import common
from ..common import convert_image, remove_duplicate_video_paths, \
apply_info_json, get_video_duration, generate_video_poster, is_valid_poster
from ..common import convert_image, apply_info_json, get_video_duration, generate_video_poster, is_valid_poster
from ..lib import save_channels_config, get_channels_config, import_channels_config
@ -40,20 +39,6 @@ def test_get_video_duration(test_directory):
get_video_duration(empty_file)
@pytest.mark.parametrize(
'paths,expected',
(
(['1.mp4', ], ['1.mp4', ]),
(['1.mp4', '2.mp4'], ['1.mp4', '2.mp4']),
(['1.mp4', '1.ogg'], ['1.mp4']),
(['1.bad_ext', '1.other_ext'], ['1.bad_ext']),
)
)
def test_remove_duplicate_video_paths(paths, expected):
result = remove_duplicate_video_paths(map(pathlib.Path, paths))
assert sorted(result) == sorted(map(pathlib.Path, expected))
def test_convert_image():
"""
An image's format can be changed. This tests that convert_image() converts from a WEBP format, to a JPEG format.