Merge pull request #57 from arabcoders/dev

Keep temp dir if video is livestream, and allow load env variables from file.
This commit is contained in:
Abdulmohsen 2024-01-09 19:58:38 +03:00 committed by GitHub
commit 8738e5998f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 42 additions and 18 deletions

7
.vscode/launch.json vendored
View file

@ -32,12 +32,7 @@
"YTP_CONFIG_PATH": "${workspaceFolder}/var/config", "YTP_CONFIG_PATH": "${workspaceFolder}/var/config",
"YTP_DOWNLOAD_PATH": "${workspaceFolder}/var/downloads", "YTP_DOWNLOAD_PATH": "${workspaceFolder}/var/downloads",
"YTP_TEMP_PATH": "${workspaceFolder}/var/tmp", "YTP_TEMP_PATH": "${workspaceFolder}/var/tmp",
"YTP_YTDL_OPTIONS_FILE": "${workspaceFolder}/var/config/ytdlp.json", "YTP_URL_HOST": "http://localhost:8081"
"YTP_URL_HOST": "http://localhost:8081",
"YTP_YTDL_DEBUG": "false",
"YTP_TEMP_KEEP": "false",
"YTP_KEEP_ARCHIVE": "false",
"YTP_MAX_WORKERS": "0",
} }
} }
] ]

View file

@ -10,6 +10,7 @@ yt-dlp = "*"
caribou = "*" caribou = "*"
coloredlogs = "*" coloredlogs = "*"
aiocron = "*" aiocron = "*"
python-dotenv = "*"
[dev-packages] [dev-packages]

22
Pipfile.lock generated
View file

@ -1,7 +1,7 @@
{ {
"_meta": { "_meta": {
"hash": { "hash": {
"sha256": "fe1facc749dd399988b1a97d60121af298edf76c14b60ceff6aa398114b15030" "sha256": "36cb208ba40791e46e98172f435ff284855eb3a0c6ba6bf5691bd80624963e8d"
}, },
"pipfile-spec": 6, "pipfile-spec": 6,
"requires": { "requires": {
@ -602,21 +602,29 @@
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'",
"version": "==2.8.2" "version": "==2.8.2"
}, },
"python-dotenv": {
"hashes": [
"sha256:a8df96034aae6d2d50a4ebe8216326c61c3eb64836776504fcca410e5937a3ba",
"sha256:f5971a9226b701070a4bf2c38c89e5a3f0d64de8debda981d1db98583009122a"
],
"index": "pypi",
"version": "==1.0.0"
},
"python-engineio": { "python-engineio": {
"hashes": [ "hashes": [
"sha256:70a7700ec68e6a1e0f40eb34533f47dfbd0418a87746a60a54d2ff3b4179be25", "sha256:a357f0aba275c311b66f22181472ed5b174bbc541742eea1d16feae2fa1afabd",
"sha256:fadc39c66348f96476d8dc2d7aaee7ea0a39d96e333217f5321300677b980121" "sha256:f8609e3afdda318fdc336b4ba2de8dd397bb8f9b8a1b43e56c27330e32c2e34c"
], ],
"markers": "python_version >= '3.6'", "markers": "python_version >= '3.6'",
"version": "==4.8.1" "version": "==4.8.2"
}, },
"python-socketio": { "python-socketio": {
"hashes": [ "hashes": [
"sha256:01c616946fa9f67ed5cc3d1568e1c4940acfc64aeeb9ff621a53e80cabeb748a", "sha256:b03186e04b942088781f6286c13604a853e5e35ed59158c51ff7af22fa032e6f",
"sha256:fb18d9b84cfb05289dc207b790c3de59cd242310d9b980b1c31e9faf4f79101a" "sha256:cfcb0163d77c8d23b98285754e79016786740dd901268654a52823da0bc73382"
], ],
"index": "pypi", "index": "pypi",
"version": "==5.10.0" "version": "==5.11.0"
}, },
"pytz": { "pytz": {
"hashes": [ "hashes": [

View file

@ -5,6 +5,7 @@ import re
import sys import sys
import coloredlogs import coloredlogs
from version import APP_VERSION from version import APP_VERSION
from dotenv import load_dotenv
class Config: class Config:
@ -60,11 +61,20 @@ class Config:
else: else:
Config.__instance = self Config.__instance = self
baseDefualtPath: str = os.path.dirname(os.path.dirname(__file__)) baseDefualtPath: str = os.path.dirname(__file__)
self.config_path = os.path.join(baseDefualtPath, 'var', 'config') self.config_path = os.environ.get('YTP_CONFIG_PATH', None) or os.path.join(
self.download_path = os.path.join(baseDefualtPath, 'var', 'downloads') baseDefualtPath, 'var', 'config')
self.temp_path = os.path.join(baseDefualtPath, 'var', 'tmp') self.download_path = os.environ.get('YTP_DOWNLOAD_PATH', None) or os.path.join(
baseDefualtPath, 'var', 'downloads')
self.temp_path = os.environ.get('YTP_TEMP_PATH', None) or os.path.join(
baseDefualtPath, 'var', 'tmp')
envFile: str = os.path.join(self.config_path, '.env')
if os.path.exists(envFile):
logging.info(f'Loading environment variables from [{envFile}].')
load_dotenv(envFile)
for k, v in self._getAttributes().items(): for k, v in self._getAttributes().items():
if k.startswith('_'): if k.startswith('_'):

View file

@ -10,6 +10,7 @@ import yt_dlp
from Utils import Notifier, get_format, get_opts, jsonCookie, mergeConfig from Utils import Notifier, get_format, get_opts, jsonCookie, mergeConfig
from ItemDTO import ItemDTO from ItemDTO import ItemDTO
from Config import Config from Config import Config
import hashlib
log = logging.getLogger('download') log = logging.getLogger('download')
@ -160,7 +161,11 @@ class Download:
self.notifier = notifier self.notifier = notifier
# Create temp dir for each download. # Create temp dir for each download.
self.tempPath = os.path.join(self.temp_dir, self.info._id) self.tempPath = os.path.join(
self.temp_dir,
hashlib.shake_256(self.info.id.encode('utf-8')).hexdigest(5)
)
if not os.path.exists(self.tempPath): if not os.path.exists(self.tempPath):
os.makedirs(self.tempPath, exist_ok=True) os.makedirs(self.tempPath, exist_ok=True)
@ -199,6 +204,11 @@ class Download:
if self.tempKeep is True or not self.tempPath: if self.tempKeep is True or not self.tempPath:
return return
if self.info.status != 'finished' and (self.info.live_in or self.info.is_live):
log.warning(
f'Keeping live temp directory: {self.tempPath}, as the reported status is not finished [{self.info.status}].')
return
if not os.path.exists(self.tempPath): if not os.path.exists(self.tempPath):
return return