Fixing bug where empty destination would be coerced into 'None'.

This commit is contained in:
Roland 2022-11-09 19:19:06 -07:00
parent ddb35448aa
commit be852e3d46
No known key found for this signature in database
GPG key ID: 9D6DBD3ACF11AB93
3 changed files with 23 additions and 9 deletions

View file

@ -257,13 +257,17 @@ class VideoDownloader(Downloader, ABC):
else:
logger.info('Could not find channel')
# Use the default directory if this video has no channel.
if destination:
# Download to the directory specified in the settings.
out_dir = pathlib.Path(settings['destination'])
logger.debug(f'Downloading {url} to destination from settings')
elif channel:
out_dir = channel.directory
logger.debug(f'Downloading {url} to channel directory')
else:
# Download to the default directory if this video has no channel.
out_dir = get_no_channel_directory()
if channel:
out_dir = channel.directory
logger.debug(f'Downloading {url} to default directory')
out_dir.mkdir(exist_ok=True, parents=True)
logs = None # noqa

View file

@ -447,14 +447,24 @@ async def test_download_result(test_session, test_directory, video_download_mana
async def test_download_destination(test_session, test_directory, video_download_manager,
mock_video_process_runner, mock_video_extract_info, mock_video_prepare_filename):
"""A Video can be downloaded to a directory other than it's Channel's directory."""
# yt-dlp would return the video json.
mock_video_extract_info.return_value = example_video_json
# Download process is successful with no logs.
mock_video_process_runner.return_value = (0, {'stdout': '', 'stderr': ''})
# This result will be ignored during the test, we just need some value so the download does not fail.
mock_video_prepare_filename.return_value = str(test_directory / 'test video.mp4')
video_download_manager.create_download('https://example.com/1', downloader=VideoDownloader.name)
await video_download_manager.wait_for_all_downloads()
# Output directory matches the channel directory.
assert mock_video_prepare_filename.call_args_list[0].kwargs['ydl'].params['outtmpl']['default']\
.startswith(f'{test_directory}/videos/channel name/%(uploader)s')
mock_video_prepare_filename.reset_mock()
settings = dict(destination=f'{test_directory}/custom')
video_download_manager.create_download('https://example.com', downloader=VideoDownloader.name, settings=settings)
mock_video_process_runner.return_value = (0, {'stdout': '', 'stderr': ''})
mock_video_prepare_filename.return_value = str(test_directory / 'test video.mp4')
video_download_manager.create_download('https://example.com/2', downloader=VideoDownloader.name, settings=settings)
await video_download_manager.wait_for_all_downloads()
# Output directory matches the custom directory specified.
assert mock_video_prepare_filename.call_args_list[0].kwargs['ydl'].params['outtmpl']['default']\
.startswith(f'{test_directory}/custom/%(uploader)s')

View file

@ -221,8 +221,8 @@ async def post_download(_: Request, body: DownloadRequest):
downloader = body.downloader
if not downloader or downloader in ('auto', 'None', 'null'):
downloader = None
destination = get_media_directory() / body.destination if body.destination else None
settings = dict(excluded_urls=excluded_urls, destination=str(destination))
destination = str(get_media_directory() / body.destination) if body.destination else None
settings = dict(excluded_urls=excluded_urls, destination=destination)
if body.frequency:
download_manager.recurring_download(urls[0], body.frequency, downloader=downloader,
sub_downloader=body.sub_downloader, reset_attempts=True,