mirror of
https://github.com/meeb/tubesync.git
synced 2025-06-24 22:16:37 +00:00
updating code per comments
This commit is contained in:
parent
aa3bc7e6af
commit
ff8d00f5bd
14
README.md
14
README.md
@ -362,7 +362,7 @@ There are a number of other environment variables you can set. These are, mostly
|
||||
useful if you are manually installing TubeSync in some other environment. These are:
|
||||
|
||||
| Name | What | Example |
|
||||
| --------------------------- | ------------------------------------------------------------ | ------------------------------------ |
|
||||
| --------------------------- | ------------------------------------------------------------ |--------------------------------------|
|
||||
| DJANGO_SECRET_KEY | Django's SECRET_KEY | YJySXnQLB7UVZw2dXKDWxI5lEZaImK6l |
|
||||
| DJANGO_URL_PREFIX | Run TubeSync in a sub-URL on the web server | /somepath/ |
|
||||
| TUBESYNC_DEBUG | Enable debugging | True |
|
||||
@ -376,21 +376,15 @@ useful if you are manually installing TubeSync in some other environment. These
|
||||
| HTTP_PASS | Sets the password for HTTP basic authentication | some-secure-password |
|
||||
| DATABASE_CONNECTION | Optional external database connection details | mysql://user:pass@host:port/database |
|
||||
| VIDEO_HEIGHT_CUTOFF | Smallest video height in pixels permitted to download | 240 |
|
||||
| TUBESYNC_DIRECTORY_MODE | Controls how downloaded files are organized. | default |
|
||||
| TUBESYNC_DIRECTORY_PREFIX | Controls how downloaded files are organized. | true |
|
||||
|
||||
# TubeSync Directory Mode
|
||||
|
||||
Controls how downloaded files are organized.
|
||||
|
||||
Values:
|
||||
- default: Audio files go to `audio`, video files to `video`.
|
||||
- flat: All files are placed in the root of DOWNLOAD_DIR.
|
||||
- custom:<audio_prefix>,<video_prefix>: Allows custom prefixes for audio and video directories under DOWNLOAD_DIR.
|
||||
|
||||
Example:
|
||||
```
|
||||
TUBESYNC_DIRECTORY_MODE=custom:music,shows
|
||||
```
|
||||
- true: Audio files go to `audio`, video files to `video`.
|
||||
- false: All files are placed in the root of DOWNLOAD_DIR.
|
||||
|
||||
# Manual, non-containerised, installation
|
||||
|
||||
|
@ -1719,68 +1719,28 @@ class TasksTestCase(TestCase):
|
||||
|
||||
class TypeDirectoryPathTestCase(TestCase):
|
||||
def setUp(self):
|
||||
self.audio_dir = Path(settings.DOWNLOAD_AUDIO_DIR)
|
||||
self.video_dir = Path(settings.DOWNLOAD_VIDEO_DIR)
|
||||
self.download_dir = Path(settings.DOWNLOAD_ROOT)
|
||||
self.source = Source(
|
||||
directory="test_directory",
|
||||
source_resolution=Source.SOURCE_RESOLUTION_AUDIO,
|
||||
)
|
||||
|
||||
def test_default_mode_audio(self):
|
||||
def test_directory_prefix_default(self):
|
||||
"""
|
||||
Test default mode for audio resolution.
|
||||
Test that default directory prefix exist.
|
||||
"""
|
||||
os.environ["TUBESYNC_DIRECTORY_MODE"] = "default"
|
||||
expected_path = self.audio_dir / self.source.directory
|
||||
self.assertEqual(self.source.type_directory_path, expected_path)
|
||||
os.environ['TUBESYNC_DIRECTORY_PREFIX'] = ''
|
||||
self.assertEqual(self.source.type_directory_path, Path(settings.DOWNLOAD_AUDIO_DIR) / 'test_directory')
|
||||
|
||||
def test_default_mode_video(self):
|
||||
def test_directory_prefix_true(self):
|
||||
"""
|
||||
Test default mode for video resolution.
|
||||
Test that when TUBESYNC_DIRECTORY_PREFIX is set to true the directory prefix exist.
|
||||
"""
|
||||
os.environ["TUBESYNC_DIRECTORY_MODE"] = "default"
|
||||
self.source.source_resolution = Source.SOURCE_RESOLUTION_1080P
|
||||
expected_path = self.video_dir / self.source.directory
|
||||
self.assertEqual(self.source.type_directory_path, expected_path)
|
||||
os.environ['TUBESYNC_DIRECTORY_PREFIX'] = 'true'
|
||||
self.assertEqual(self.source.type_directory_path, Path(settings.DOWNLOAD_AUDIO_DIR) / 'test_directory')
|
||||
|
||||
def test_flat_mode(self):
|
||||
def test_directory_prefix_false(self):
|
||||
"""
|
||||
Test flat mode places files in the root download directory.
|
||||
Test that when TUBESYNC_DIRECTORY_PREFIX is set to false the directory prefix does not exist.
|
||||
"""
|
||||
os.environ["TUBESYNC_DIRECTORY_MODE"] = "flat"
|
||||
expected_path = self.download_dir / self.source.directory
|
||||
self.assertEqual(self.source.type_directory_path, expected_path)
|
||||
|
||||
def test_custom_mode_audio(self):
|
||||
"""
|
||||
Test custom mode with prefixes for audio.
|
||||
"""
|
||||
os.environ["TUBESYNC_DIRECTORY_MODE"] = "custom:audio_prefix,video_prefix"
|
||||
expected_path = self.download_dir / "audio_prefix" / self.source.directory
|
||||
self.assertEqual(self.source.type_directory_path, expected_path)
|
||||
|
||||
def test_custom_mode_video(self):
|
||||
"""
|
||||
Test custom mode with prefixes for video.
|
||||
"""
|
||||
os.environ["TUBESYNC_DIRECTORY_MODE"] = "custom:audio_prefix,video_prefix"
|
||||
self.source.source_resolution = Source.SOURCE_RESOLUTION_1080P
|
||||
expected_path = self.download_dir / "video_prefix" / self.source.directory
|
||||
self.assertEqual(self.source.type_directory_path, expected_path)
|
||||
|
||||
def test_custom_mode_invalid_format(self):
|
||||
"""
|
||||
Test custom mode with an invalid format.
|
||||
"""
|
||||
os.environ["TUBESYNC_DIRECTORY_MODE"] = "custom:only_audio_prefix"
|
||||
with self.assertRaises(ValueError):
|
||||
_ = self.source.type_directory_path
|
||||
|
||||
def test_invalid_mode(self):
|
||||
"""
|
||||
Test unsupported directory mode raises an error.
|
||||
"""
|
||||
os.environ["TUBESYNC_DIRECTORY_MODE"] = "unsupported_mode"
|
||||
with self.assertRaises(ValueError):
|
||||
_ = self.source.type_directory_path
|
||||
os.environ['TUBESYNC_DIRECTORY_PREFIX'] = 'false'
|
||||
self.assertEqual(self.source.type_directory_path, Path('.') / 'test_directory')
|
@ -112,19 +112,10 @@ DOWNLOAD_VIDEO_DIR = 'video'
|
||||
DOWNLOAD_AUDIO_DIR = 'audio'
|
||||
SASS_PROCESSOR_ROOT = STATIC_ROOT
|
||||
|
||||
directory_mode = os.getenv('TUBESYNC_DIRECTORY_MODE', 'default')
|
||||
if directory_mode == 'flat':
|
||||
directory_prefix = os.getenv('TUBESYNC_DIRECTORY_PREFIX', 'true')
|
||||
if directory_prefix == 'false':
|
||||
DOWNLOAD_VIDEO_DIR = '.'
|
||||
DOWNLOAD_AUDIO_DIR = '.'
|
||||
elif directory_mode.startswith('custom:'):
|
||||
custom_value = directory_mode.split(':', maxsplit=1)[1]
|
||||
if ',' in custom_value:
|
||||
DOWNLOAD_AUDIO_DIR, DOWNLOAD_VIDEO_DIR = custom_value.split(',', maxsplit=1)
|
||||
else:
|
||||
raise ValueError("Invalid format for TUBESYNC_DIRECTORY_MODE=custom. Expected 'custom:audio_prefix,video_prefix'.")
|
||||
elif directory_mode not in ('', 'default'):
|
||||
raise ValueError(f"Unsupported TUBESYNC_DIRECTORY_MODE: {directory_mode}")
|
||||
|
||||
|
||||
ROBOTS = '''
|
||||
User-agent: *
|
||||
|
Loading…
Reference in New Issue
Block a user