diff --git a/.gitignore b/.gitignore index cb14cfd6..cf63cfba 100644 --- a/.gitignore +++ b/.gitignore @@ -134,3 +134,6 @@ dmypy.json Pipfile.lock .vscode/launch.json + +# Ignore Jetbrains IDE files +.idea/ \ No newline at end of file diff --git a/README.md b/README.md index b85b2b4a..9a565c29 100644 --- a/README.md +++ b/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,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 diff --git a/tubesync/sync/tests.py b/tubesync/sync/tests.py index 72411894..86a39366 100644 --- a/tubesync/sync/tests.py +++ b/tubesync/sync/tests.py @@ -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') \ No newline at end of file diff --git a/tubesync/tubesync/settings.py b/tubesync/tubesync/settings.py index d67d577a..7bb4b2a2 100644 --- a/tubesync/tubesync/settings.py +++ b/tubesync/tubesync/settings.py @@ -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: *