Subdirectories are tested.

This commit is contained in:
Roland 2019-10-14 17:13:17 -06:00
parent ef4656aa65
commit 7a1447207c
No known key found for this signature in database
GPG key ID: 9D6DBD3ACF11AB93
2 changed files with 37 additions and 7 deletions

View file

@ -1,3 +1,26 @@
"""
This module contains the CherryPy classes, as well as functions necessary to retrieve video files. This module also
contains functions that will search the file structure for video files, as well as cleanup the DB video records.
All paths in the DB are relative. A Channel's directory is relative to the video_root_directory. A Video's path (as
well as its meta files) is relative to its Channel's directory.
Example:
Real Paths:
video_root_directory = '/media/something'
channel['directory'] = '/media/something/the channel'
video['video_path'] = '/media/something/the channel/foo.mp4'
video['poster_path'] = '/media/something/the channel/foo.jpg'
video['video_path'] = '/media/something/the channel/subdir/bar.mp4'
The same paths in the DB:
channel['directory'] = 'the channel'
video['video_path'] = 'foo.mp4'
video['poster_path'] = 'foo.jpg'
video['video_path'] = 'subdir/bar.mp4'
Relative DB paths allow files to be moved without having to rebuild the entire collection.
"""
import json
import pathlib
from functools import wraps
@ -204,6 +227,9 @@ def get_channel_form(form_data: dict):
def refresh_channel_videos(db, channel):
"""
Find all video files in a channel's directory. Add any videos not in the DB to the DB.
"""
# A set of paths relative to this channel's directory
existing_paths = {i['video_path'] for i in channel['videos']}
directory = resolve_project_path(channel['directory']).absolute()

View file

@ -124,14 +124,18 @@ class TestAPI(unittest.TestCase):
Video, Channel = db['video'], db['channel']
# Files in subdirectories should be found and handled properly
subdir = (channel_path / 'subdir')
subdir.mkdir()
# These are the types of files that will be found first
vid1 = pathlib.Path(channel_path / 'channel name_20000101_abcdefghijk_title.mp4')
vid1 = pathlib.Path(subdir / 'channel name_20000101_abcdefghijk_title.mp4')
vid1.touch()
vid2 = pathlib.Path(channel_path / 'channel name_20000102_bcdefghijkl_title.webm')
vid2.touch()
# These files are associated with the video files above, and should be found "near" them
poster1 = pathlib.Path(channel_path / 'channel name_20000101_abcdefghijk_title.jpg')
poster1 = pathlib.Path(subdir / 'channel name_20000101_abcdefghijk_title.jpg')
poster1.touch()
poster2 = pathlib.Path(channel_path / 'channel name_20000102_bcdefghijkl_title.jpg')
poster2.touch()
@ -140,10 +144,10 @@ class TestAPI(unittest.TestCase):
channel = Channel(directory=channel_dir).flush()
video1 = insert_video(db, vid1, channel)
video2 = insert_video(db, vid2, channel)
self.assertEqual({i['video_path'] for i in channel['videos']}, {vid1.name, vid2.name})
self.assertEqual({i['video_path'] for i in channel['videos']}, {'subdir/' + vid1.name, vid2.name})
# Poster files were found
self.assertEqual(video1['poster_path'], poster1.name)
self.assertEqual(video1['poster_path'], 'subdir/' + poster1.name)
self.assertEqual(video2['poster_path'], poster2.name)
# Add a bogus file, this should be removed during the refresh
@ -171,9 +175,9 @@ class TestAPI(unittest.TestCase):
# Final channel video list we built
expected = {
(vid1.name, poster1.name, None), # no description
(vid2.name, poster2.name, None), # no description
(vid3.name, None, description3.name), # no poster
('subdir/' + vid1.name, 'subdir/' + poster1.name, None), # in a subdirectory, no description
(vid2.name, poster2.name, None), # no description
(vid3.name, None, description3.name), # no poster
}
self.assertEqual(
{(i['video_path'], i['poster_path'], i['description_path']) for i in channel['videos']},