add download_format_str option and update icons

- change icons to unicode glyphs
- remove trailing slash from download directory if it exists
- allow configuring file output format during download
This commit is contained in:
ksyasuda 2023-08-06 02:22:44 -07:00
parent 02ad7d708e
commit 4e4489cf36

View File

@ -40,9 +40,10 @@ local options = {
print_queue = "ctrl+q", print_queue = "ctrl+q",
clipboard_command = "xclip -o", clipboard_command = "xclip -o",
browser = "firefox", browser = "firefox",
cursor_icon = "🠺", cursor_icon = "",
marked_icon = "󰆾", marked_icon = "",
download_directory = "~/videos/YouTube", download_directory = "~/videos/YouTube",
download_format_str = "%(uploader)s/%(title)s.%(ext)s",
downloader = "curl", downloader = "curl",
download_quality = "720p", download_quality = "720p",
font_name = "JetBrains Mono", font_name = "JetBrains Mono",
@ -105,6 +106,8 @@ local function print_current_video()
end end
local function expanduser(path) local function expanduser(path)
-- remove trailing slash if it exists
if string.sub(path, -1) == "/" then path = string.sub(path, 1, -2) end
if path:sub(1, 1) == "~" then if path:sub(1, 1) == "~" then
local home = os.getenv("HOME") local home = os.getenv("HOME")
if home then if home then
@ -457,12 +460,12 @@ function YouTubeQueue.download_current_video()
local o = options local o = options
local v = current_video local v = current_video
local q = o.download_quality:sub(1, -2) local q = o.download_quality:sub(1, -2)
local dl_dir = expanduser(o.download_directory)
local command = 'yt-dlp -f \'bestvideo[height<=' .. q .. local command = 'yt-dlp -f \'bestvideo[height<=' .. q ..
']+bestaudio/best[height<=' .. q .. ']\' -o "' .. ']+bestaudio/best[height<=' .. q .. ']\' -o "' ..
expanduser(o.download_directory) .. '/' .. dl_dir .. "/" .. options.download_format_str ..
v.channel_name .. '/' .. v.video_name .. '" --downloader ' .. o.downloader .. ' ' ..
'.%(ext)s" ' .. '--downloader ' .. o.downloader .. v.video_url
' ' .. v.video_url
-- Run the download command -- Run the download command
local handle = io.popen(command) local handle = io.popen(command)