More config options (tmpl, yt_proxy) + notes
This commit is contained in:
parent
0cbb9d424e
commit
96be306b2b
3 changed files with 23 additions and 6 deletions
5
Makefile
5
Makefile
|
@ -1,7 +1,10 @@
|
|||
.PHONY: run test build frontend backend
|
||||
|
||||
run:
|
||||
HOST=127.0.0.1 PORT=4009 COOKIES_DIR=cookies python3 ./backend/main.py
|
||||
# See backend/config.py for more fields
|
||||
HOST=127.0.0.1 PORT=4009 \
|
||||
COOKIES_DIR=cookies \
|
||||
python3 ./backend/main.py
|
||||
|
||||
test:
|
||||
@python3 -m unittest discover -vcs ./backend
|
||||
|
|
|
@ -8,9 +8,24 @@ class Config:
|
|||
|
||||
self.host = os.getenv('HOST') or '0.0.0.0'
|
||||
self.port = int(os.getenv('PORT') or 4009)
|
||||
self.path_length = int(os.getenv('PATH_LENGTH') or 255)
|
||||
|
||||
# This directory will be searched for <site>.txt (e.g. yandex.txt)
|
||||
# Cookies are in Netscape CSV format, see yt-dlp docs
|
||||
self.cookies_dir = Path(os.getenv('COOKIES_DIR') or 'cookies')
|
||||
|
||||
# Note: yt-dlp's path trimmer also counts album_path_tmpl, not only filename
|
||||
# Why 235? 255 is the ext4 limit. 255 - len("/var/lib/musicdlp/") = 237, rounded down to 235
|
||||
self.path_length = int(os.getenv('PATH_LENGTH') or 235)
|
||||
|
||||
self.tmpl = os.path.join(
|
||||
# `artists.0` instead of `artist`, because the latter can contain "feat. ..."
|
||||
os.getenv('ALBUM_PATH_TMPL') or 'music/%(artists.0)s/%(album)s',
|
||||
os.getenv('TRACK_FILE_TMPL') or '%(track)s.%(ext)s',
|
||||
)
|
||||
|
||||
# Proxy URL for yt_proxied downloader (can be used for geo-restricted content)
|
||||
self.yt_proxy = os.getenv('YT_PROXY') or 'http://127.0.0.1:1080'
|
||||
|
||||
|
||||
_config: Config | None = None
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ class _CreateYDL:
|
|||
@staticmethod
|
||||
def yt_proxied() -> YoutubeDL:
|
||||
ydl = _CreateYDL.youtube()
|
||||
ydl.params['proxy'] = 'http://127.0.0.1:1080' # TODO
|
||||
ydl.params['proxy'] = config.get().yt_proxy
|
||||
return ydl
|
||||
|
||||
@staticmethod
|
||||
|
@ -52,9 +52,8 @@ class Downloaders:
|
|||
if ydl is None:
|
||||
ydl = create_ydl_fn[site]()
|
||||
|
||||
ydl.params['trim_file_name'] = cfg.path_length # NOTE: includes path, not only filename
|
||||
# artists.0 instead of artist, because it can contain "feat. ..."
|
||||
ydl.params['outtmpl']['default'] = 'music/%(artists.0)s/%(album)s/%(track)s.%(ext)s'
|
||||
ydl.params['trim_file_name'] = cfg.path_length # Note: not only filename, but path in outtmpl
|
||||
ydl.params['outtmpl']['default'] = cfg.tmpl
|
||||
ydl.add_post_processor(id3pp.ID3TagsPP(), when='post_process')
|
||||
|
||||
cookies = cfg.cookies_dir / (site + '.txt')
|
||||
|
|
Loading…
Add table
Reference in a new issue