manbearwiz/youtube-dl-server

How to automatically create a directory

PDSCi996 opened this issue · 4 comments

I changed the 21st line of the "youtube-dl-server.py" configuration file to "'YDL_OUTPUT_TEMPLATE':'/youtube-dl/%%(uploader)s/(title)s.%(ext)s', ", so that the video file will automatically create a directory named after the channel name after downloading, and copy this file into it, but if you download a playlist composed of different channels, multiple directories will be created. In youtube-dl-server.py, set parameters like "'YDL_OUTPUT_TEMPLATE_PLAYLIST':'/youtube-dl/%(playlist)s/%(playlist_index)s-%(title)s.%(ext)s', When downloading a playlist, only one directory will be created with the name of the playlist.
Thanks a lot.

I made some changes but I don’t know that meets your needs?
`
app_defaults = {
"YDL_FORMAT": "bestvideo+bestaudio/best",
"YDL_EXTRACT_AUDIO_FORMAT": None,
"YDL_EXTRACT_AUDIO_QUALITY": "192",
"YDL_RECODE_VIDEO_FORMAT": None,
"YDL_OUTPUT_TEMPLATE": "/youtube-dl/%(title).200s [%(id)s].%(ext)s",
"YDL_OUTPUT_TEMPLATE_PLAYLIST": "/youtube-dl/%(playlist)s/%(playlist_index)s-%(title)s.%(ext)s",
"YDL_ARCHIVE_FILE": None,
"YDL_SERVER_HOST": "0.0.0.0",
"YDL_SERVER_PORT": 8080,
"YDL_UPDATE_TIME": "True",
}

def get_ydl_options(request_options,url):
...
outtmpl = ydl_vars["YDL_OUTPUT_TEMPLATE"]
if "list=" in url:
outtmpl = ydl_vars["YDL_OUTPUT_TEMPLATE_PLAYLIST"]

return {
"format": ydl_vars["YDL_FORMAT"],
"postprocessors": postprocessors,
"outtmpl": outtmpl,
"download_archive": ydl_vars["YDL_ARCHIVE_FILE"],
"updatetime": ydl_vars["YDL_UPDATE_TIME"] == "True",
}
def download(url, request_options):
print(url)
with YoutubeDL(get_ydl_options(request_options,url)) as ydl:
ydl.download([url])
`

I made some changes but I don’t know that meets your needs?
`
app_defaults = {
"YDL_FORMAT": "bestvideo+bestaudio/best",
"YDL_EXTRACT_AUDIO_FORMAT": None,
"YDL_EXTRACT_AUDIO_QUALITY": "192",
"YDL_RECODE_VIDEO_FORMAT": None,
"YDL_OUTPUT_TEMPLATE": "/youtube-dl/%(title).200s [%(id)s].%(ext)s",
"YDL_OUTPUT_TEMPLATE_PLAYLIST": "/youtube-dl/%(playlist)s/%(playlist_index)s-%(title)s.%(ext)s",
"YDL_ARCHIVE_FILE": None,
"YDL_SERVER_HOST": "0.0.0.0",
"YDL_SERVER_PORT": 8080,
"YDL_UPDATE_TIME": "True",
}

def get_ydl_options(request_options,url):
...
outtmpl = ydl_vars["YDL_OUTPUT_TEMPLATE"] if "list=" in url: outtmpl = ydl_vars["YDL_OUTPUT_TEMPLATE_PLAYLIST"]
return {
"format": ydl_vars["YDL_FORMAT"],
"postprocessors": postprocessors,
"outtmpl": outtmpl,
"download_archive": ydl_vars["YDL_ARCHIVE_FILE"],
"updatetime": ydl_vars["YDL_UPDATE_TIME"] == "True",
}
def download(url, request_options):
print(url)
with YoutubeDL(get_ydl_options(request_options,url)) as ydl:
ydl.download([url])
`

Thank you very much for your reply, but is the part in bold you rewritten? Also, have you tested it?

Yes, I did simple test.

Would this be saved as config.yml somewhere?