Moving video about pane to it's own segment to avoid tabs going out of mobile viewing area.

This commit is contained in:
Roland 2024-02-20 15:13:18 -07:00
parent 5629adc84c
commit 08fa3af453
No known key found for this signature in database
GPG key ID: 9D6DBD3ACF11AB93
3 changed files with 42 additions and 36 deletions

View file

@ -214,25 +214,6 @@ function VideoPage({videoFile, prevFile, nextFile, fetchVideo, ...props}) {
</TabPane>
};
const aboutPane = {
menuItem: 'About', render: () => <TabPane>
<h3>Size</h3>
<p>{videoFile.size ? humanFileSize(videoFile.size) : 'Unknown'}</p>
<h3>Source URL</h3>
<p>{videoFile.url ? <a href={videoFile.url}>{videoFile.url}</a> : 'N/A'}</p>
<h3>View Count</h3>
<p>{video.view_count ? humanNumber(video.view_count) : 'N/A'}</p>
<h3>Censored</h3>
<p>{video.censored ? 'Yes' : 'No'}</p>
<h3>Codec Names</h3>
<>{video.codec_names ? video.codec_names.map(i => <Label key={i}>{i}</Label>) : 'N/A'}</>
</TabPane>
}
const captionsPane = {
menuItem: 'Captions', render: () => <TabPane>
<pre>{video.caption || 'No captions available.'}</pre>
@ -278,9 +259,27 @@ function VideoPage({videoFile, prevFile, nextFile, fetchVideo, ...props}) {
</TabPane>,
};
const tabPanes = [commentsPane, descriptionPane, aboutPane, filesPane, captionsPane];
const tabPanes = [commentsPane, descriptionPane, filesPane, captionsPane];
const tabMenu = theme === darkTheme ? {inverted: true, attached: true} : {attached: true};
const aboutSegment = <Segment>
<Header as='h2'>About Video</Header>
<h3>Size</h3>
<p>{videoFile.size ? humanFileSize(videoFile.size) : 'Unknown'}</p>
<h3>Source URL</h3>
<p>{videoFile.url ? <a href={videoFile.url}>{videoFile.url}</a> : 'N/A'}</p>
<h3>View Count</h3>
<p>{video.view_count ? humanNumber(video.view_count) : 'N/A'}</p>
<h3>Censored</h3>
<p>{video.censored ? 'Yes' : 'No'}</p>
<h3>Codec Names</h3>
<>{video.codec_names ? video.codec_names.map(i => <Label key={i}>{i}</Label>) : 'N/A'}</>
</Segment>;
const localAddTag = async (name) => {
await tagFileGroup(videoFile, name);
await fetchVideo();
@ -371,6 +370,8 @@ function VideoPage({videoFile, prevFile, nextFile, fetchVideo, ...props}) {
<Tab menu={tabMenu} panes={tabPanes}/>
{aboutSegment}
{prevNextVideosSegment}
</Container>
</>

View file

@ -451,6 +451,14 @@ class VideoDownloader(Downloader, ABC):
Replace existing metadata files only after successful download."""
url = download.url
with get_db_session(commit=True) as session:
# Find the existing video, replace its info json.
video = Video.get_by_url(url, session)
location = f'/videos/video/{video.id}'
if video.channel_id:
location = f'/videos/channel/{video.channel_id}/video/{video.id}'
# Download metadata files into temporary directory so yt-dlp always downloads the latest files.
with tempfile.TemporaryDirectory() as tmp_dir:
tmp_dir = pathlib.Path(tmp_dir)
@ -483,6 +491,7 @@ class VideoDownloader(Downloader, ABC):
return DownloadResult(
success=False,
error=error,
location=location,
)
# Find the info json file in the temporary directory.
@ -490,12 +499,14 @@ class VideoDownloader(Downloader, ABC):
if len(info_json_paths) == 0:
return DownloadResult(
success=False,
error='No info json file was downloaded.'
error='No info json file was downloaded.',
location=location,
)
elif len(info_json_paths) > 1:
return DownloadResult(
success=False,
error='More than one info json file was downloaded.'
error='More than one info json file was downloaded.',
location=location,
)
info_json_path = info_json_paths[0]
@ -504,6 +515,7 @@ class VideoDownloader(Downloader, ABC):
return DownloadResult(
success=False,
error='Video info json file was empty',
location=location,
)
# Reformat new info json file for human reading.
@ -512,8 +524,6 @@ class VideoDownloader(Downloader, ABC):
with get_db_session(commit=True) as session:
# Find the existing video, replace its info json.
video = Video.get_by_url(url, session)
video_id = video.id
channel_id = video.channel_id
if video.info_json_path and video.info_json_path.is_file():
# Move old file temporarily. Only delete old data if the swap is successful.
@ -543,11 +553,6 @@ class VideoDownloader(Downloader, ABC):
new_info_json_path.write_text(info_json_path.read_text())
video.file_group.append_files(new_info_json_path)
if channel_id:
location = f'/videos/channel/{channel_id}/video/{video_id}'
else:
location = f'/videos/video/{video_id}'
logger.debug(f'Downloaded video info json {location=}')
logger.info(f'Successfully downloaded video info json {url} {video}')

View file

@ -220,17 +220,17 @@ def test_file_statistics(test_session, test_client, test_directory, example_pdf,
assert response.status_code == HTTPStatus.OK
assert response.json['file_statistics'] == {
'archive_count': 0,
'total_size': 0,
'audio_count': 0,
'ebook_count': 0,
'image_count': 0,
'pdf_count': 0,
'total_count': 0,
'video_count': 0,
'zip_count': 0,
'tagged_files': 0,
'tagged_zims': 0,
'tags_count': 0,
'total_count': 0,
'total_size': 0,
'video_count': 0,
'zip_count': 0,
}
test_client.post('/api/files/refresh')
@ -245,12 +245,12 @@ def test_file_statistics(test_session, test_client, test_directory, example_pdf,
'ebook_count': 2,
'image_count': 0,
'pdf_count': 1,
'total_count': 5, # extracted cover
'video_count': 1,
'zip_count': 0,
'tagged_files': 0,
'tagged_zims': 0,
'tags_count': 0,
'total_count': 5, # extracted cover
'video_count': 1,
'zip_count': 0,
}