Merge pull request #572 from jameswlane/main

Add Support for TUBESYNC_DIRECTORY_PREFIX Environment Variable
This commit is contained in:
meeb 2024-12-11 22:45:42 +11:00 committed by GitHub
commit a8997400b2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 46 additions and 1 deletions

3
.gitignore vendored
View File

@ -134,3 +134,6 @@ dmypy.json
Pipfile.lock
.vscode/launch.json
# Ignore Jetbrains IDE files
.idea/

View File

@ -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,7 +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_PREFIX | Controls how downloaded files are organized. | true |
# TubeSync Directory Mode
Controls how downloaded files are organized.
Values:
- 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

View File

@ -6,7 +6,9 @@
import logging
import os
from datetime import datetime, timedelta
from pathlib import Path
from urllib.parse import urlsplit
from xml.etree import ElementTree
from django.conf import settings
@ -1714,3 +1716,31 @@ class TasksTestCase(TestCase):
self.assertEqual(src1.media_source.all().count(), 3)
self.assertEqual(src2.media_source.all().count(), 2)
self.assertEqual(Media.objects.filter(pk=m22.pk).exists(), False)
class TypeDirectoryPathTestCase(TestCase):
def setUp(self):
self.source = Source(
directory="test_directory",
source_resolution=Source.SOURCE_RESOLUTION_AUDIO,
)
def test_directory_prefix_default(self):
"""
Test that default directory prefix exist.
"""
os.environ['TUBESYNC_DIRECTORY_PREFIX'] = ''
self.assertEqual(self.source.type_directory_path, Path(settings.DOWNLOAD_AUDIO_DIR) / 'test_directory')
def test_directory_prefix_true(self):
"""
Test that when TUBESYNC_DIRECTORY_PREFIX is set to true the directory prefix exist.
"""
os.environ['TUBESYNC_DIRECTORY_PREFIX'] = 'true'
self.assertEqual(self.source.type_directory_path, Path(settings.DOWNLOAD_AUDIO_DIR) / 'test_directory')
def test_directory_prefix_false(self):
"""
Test that when TUBESYNC_DIRECTORY_PREFIX is set to false the directory prefix does not exist.
"""
os.environ['TUBESYNC_DIRECTORY_PREFIX'] = 'false'
self.assertEqual(self.source.type_directory_path, Path('.') / 'test_directory')

View File

@ -112,6 +112,10 @@ DOWNLOAD_VIDEO_DIR = 'video'
DOWNLOAD_AUDIO_DIR = 'audio'
SASS_PROCESSOR_ROOT = STATIC_ROOT
directory_prefix = os.getenv('TUBESYNC_DIRECTORY_PREFIX', 'true')
if directory_prefix == 'false':
DOWNLOAD_VIDEO_DIR = '.'
DOWNLOAD_AUDIO_DIR = '.'
ROBOTS = '''
User-agent: *