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:
commit
8738e5998f
5 changed files with 42 additions and 18 deletions
7
.vscode/launch.json
vendored
7
.vscode/launch.json
vendored
|
|
@ -32,12 +32,7 @@
|
|||
"YTP_CONFIG_PATH": "${workspaceFolder}/var/config",
|
||||
"YTP_DOWNLOAD_PATH": "${workspaceFolder}/var/downloads",
|
||||
"YTP_TEMP_PATH": "${workspaceFolder}/var/tmp",
|
||||
"YTP_YTDL_OPTIONS_FILE": "${workspaceFolder}/var/config/ytdlp.json",
|
||||
"YTP_URL_HOST": "http://localhost:8081",
|
||||
"YTP_YTDL_DEBUG": "false",
|
||||
"YTP_TEMP_KEEP": "false",
|
||||
"YTP_KEEP_ARCHIVE": "false",
|
||||
"YTP_MAX_WORKERS": "0",
|
||||
"YTP_URL_HOST": "http://localhost:8081"
|
||||
}
|
||||
}
|
||||
]
|
||||
|
|
|
|||
1
Pipfile
1
Pipfile
|
|
@ -10,6 +10,7 @@ yt-dlp = "*"
|
|||
caribou = "*"
|
||||
coloredlogs = "*"
|
||||
aiocron = "*"
|
||||
python-dotenv = "*"
|
||||
|
||||
[dev-packages]
|
||||
|
||||
|
|
|
|||
22
Pipfile.lock
generated
22
Pipfile.lock
generated
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"_meta": {
|
||||
"hash": {
|
||||
"sha256": "fe1facc749dd399988b1a97d60121af298edf76c14b60ceff6aa398114b15030"
|
||||
"sha256": "36cb208ba40791e46e98172f435ff284855eb3a0c6ba6bf5691bd80624963e8d"
|
||||
},
|
||||
"pipfile-spec": 6,
|
||||
"requires": {
|
||||
|
|
@ -602,21 +602,29 @@
|
|||
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'",
|
||||
"version": "==2.8.2"
|
||||
},
|
||||
"python-dotenv": {
|
||||
"hashes": [
|
||||
"sha256:a8df96034aae6d2d50a4ebe8216326c61c3eb64836776504fcca410e5937a3ba",
|
||||
"sha256:f5971a9226b701070a4bf2c38c89e5a3f0d64de8debda981d1db98583009122a"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==1.0.0"
|
||||
},
|
||||
"python-engineio": {
|
||||
"hashes": [
|
||||
"sha256:70a7700ec68e6a1e0f40eb34533f47dfbd0418a87746a60a54d2ff3b4179be25",
|
||||
"sha256:fadc39c66348f96476d8dc2d7aaee7ea0a39d96e333217f5321300677b980121"
|
||||
"sha256:a357f0aba275c311b66f22181472ed5b174bbc541742eea1d16feae2fa1afabd",
|
||||
"sha256:f8609e3afdda318fdc336b4ba2de8dd397bb8f9b8a1b43e56c27330e32c2e34c"
|
||||
],
|
||||
"markers": "python_version >= '3.6'",
|
||||
"version": "==4.8.1"
|
||||
"version": "==4.8.2"
|
||||
},
|
||||
"python-socketio": {
|
||||
"hashes": [
|
||||
"sha256:01c616946fa9f67ed5cc3d1568e1c4940acfc64aeeb9ff621a53e80cabeb748a",
|
||||
"sha256:fb18d9b84cfb05289dc207b790c3de59cd242310d9b980b1c31e9faf4f79101a"
|
||||
"sha256:b03186e04b942088781f6286c13604a853e5e35ed59158c51ff7af22fa032e6f",
|
||||
"sha256:cfcb0163d77c8d23b98285754e79016786740dd901268654a52823da0bc73382"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==5.10.0"
|
||||
"version": "==5.11.0"
|
||||
},
|
||||
"pytz": {
|
||||
"hashes": [
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import re
|
|||
import sys
|
||||
import coloredlogs
|
||||
from version import APP_VERSION
|
||||
from dotenv import load_dotenv
|
||||
|
||||
|
||||
class Config:
|
||||
|
|
@ -60,11 +61,20 @@ class Config:
|
|||
else:
|
||||
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.download_path = os.path.join(baseDefualtPath, 'var', 'downloads')
|
||||
self.temp_path = os.path.join(baseDefualtPath, 'var', 'tmp')
|
||||
self.config_path = os.environ.get('YTP_CONFIG_PATH', None) or os.path.join(
|
||||
baseDefualtPath, 'var', 'config')
|
||||
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():
|
||||
if k.startswith('_'):
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import yt_dlp
|
|||
from Utils import Notifier, get_format, get_opts, jsonCookie, mergeConfig
|
||||
from ItemDTO import ItemDTO
|
||||
from Config import Config
|
||||
import hashlib
|
||||
|
||||
log = logging.getLogger('download')
|
||||
|
||||
|
|
@ -160,7 +161,11 @@ class Download:
|
|||
self.notifier = notifier
|
||||
|
||||
# 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):
|
||||
os.makedirs(self.tempPath, exist_ok=True)
|
||||
|
||||
|
|
@ -199,6 +204,11 @@ class Download:
|
|||
if self.tempKeep is True or not self.tempPath:
|
||||
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):
|
||||
return
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue