From ddb35448aa2f5d2570e5d4f569fde491e4338729 Mon Sep 17 00:00:00 2001 From: Roland Date: Wed, 9 Nov 2022 08:54:56 -0700 Subject: [PATCH] Finding channel by destination directory if any. --- app/src/components/Download.js | 22 ++++++++-------------- app/src/components/VideoPlayer.js | 3 ++- modules/videos/downloader.py | 6 ++++-- modules/videos/test/test_downloader.py | 1 + wrolpi/root_api.py | 3 ++- 5 files changed, 17 insertions(+), 18 deletions(-) diff --git a/app/src/components/Download.js b/app/src/components/Download.js index 362cdcc3..7ef56f5b 100644 --- a/app/src/components/Download.js +++ b/app/src/components/Download.js @@ -13,12 +13,7 @@ class Downloader extends React.Component { constructor(props) { super(props); this.state = { - advancedOpen: false, - destination: '', - downloader: props.downloader, - pending: false, - urls: '', - valid: true, + advancedOpen: false, destination: '', downloader: props.downloader, pending: false, urls: '', valid: true, }; } @@ -27,13 +22,7 @@ class Downloader extends React.Component { if (urls) { this.setState({pending: true}); try { - let response = await postDownload( - urls, - downloader, - null, - null, - null, - destination); + let response = await postDownload(urls, downloader, null, null, null, destination); if (response.status === 204) { this.setState({urls: '', pending: false}); } @@ -44,9 +33,14 @@ class Downloader extends React.Component { } handleInputChange = async (event, {name, value}) => { + console.log(name, value); this.setState({[name]: value}, this.validateUrls); } + handleDestinationChange = (value) => { + this.setState({destination: value}); + } + validateUrls = async () => { // Validate that all URLs in state are valid. if (this.state.urls) { @@ -78,7 +72,7 @@ class Downloader extends React.Component { this.handleInputChange('directory', value)} + setInput={this.handleDestinationChange} placeholder='download/into/custom/directory' /> diff --git a/app/src/components/VideoPlayer.js b/app/src/components/VideoPlayer.js index b49eddf1..a34e553e 100644 --- a/app/src/components/VideoPlayer.js +++ b/app/src/components/VideoPlayer.js @@ -39,7 +39,8 @@ function VideoPage({videoFile, prevFile, nextFile, setFavorite, ...props}) { const handleDeleteVideo = async (video_id) => { try { - await deleteVideos(video_id) + await deleteVideos([video_id]) + setDeleteOpen(false); } catch (e) { setDeleteOpen(false); throw e; diff --git a/modules/videos/downloader.py b/modules/videos/downloader.py index 66d68484..e9eb15a7 100755 --- a/modules/videos/downloader.py +++ b/modules/videos/downloader.py @@ -241,10 +241,12 @@ class VideoDownloader(Downloader, ABC): settings = download.settings or dict() local_channel_id = settings.get('channel_id') channel_url = settings.get('channel_url') + destination = settings.get('destination') if not channel and (local_channel_id or channel_url): # Could not find channel via yt-dlp info_json, use info from ChannelDownloader if it created this Download. logger.info(f'Using download.settings to find channel') - channel = get_channel(channel_id=local_channel_id, url=channel_url, return_dict=False) + channel = get_channel(channel_id=local_channel_id, url=channel_url, directory=destination, + return_dict=False) if channel: found_channel = 'download_settings' @@ -256,7 +258,7 @@ class VideoDownloader(Downloader, ABC): logger.info('Could not find channel') # Use the default directory if this video has no channel. - if settings.get('destination'): + if destination: out_dir = pathlib.Path(settings['destination']) else: out_dir = get_no_channel_directory() diff --git a/modules/videos/test/test_downloader.py b/modules/videos/test/test_downloader.py index ee10c0a5..d777cb6c 100644 --- a/modules/videos/test/test_downloader.py +++ b/modules/videos/test/test_downloader.py @@ -446,6 +446,7 @@ async def test_download_result(test_session, test_directory, video_download_mana @pytest.mark.asyncio 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.""" mock_video_extract_info.return_value = example_video_json settings = dict(destination=f'{test_directory}/custom') diff --git a/wrolpi/root_api.py b/wrolpi/root_api.py index 34ff52bc..419eb764 100644 --- a/wrolpi/root_api.py +++ b/wrolpi/root_api.py @@ -221,7 +221,8 @@ async def post_download(_: Request, body: DownloadRequest): downloader = body.downloader if not downloader or downloader in ('auto', 'None', 'null'): downloader = None - settings = dict(excluded_urls=excluded_urls, destination=body.destination) + destination = get_media_directory() / body.destination if body.destination else None + settings = dict(excluded_urls=excluded_urls, destination=str(destination)) if body.frequency: download_manager.recurring_download(urls[0], body.frequency, downloader=downloader, sub_downloader=body.sub_downloader, reset_attempts=True,