Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Get filename in a bash script #4870
Comments
|
--get-filename - simulate, quiet but print output filename |
|
It won't work for me. It the file downloaded is a youtube video, the output is the mp4 file and not the postprocessed mp3 file (because of -x option). I ended up creating a temporary folder, downloading into it, Here's the code for those interested:
|
|
I'm trying to do the almost exact same thing. What I've come up with is something like this; youtube-mp3() {
local tmp_dir="/tmp/youtube-dl";
local filename=$(youtube-dl "$1" -o "%(title)s" --get-filename);
mkdir -p "$tmp_dir";
pushd "$tmp_dir" > /dev/null;
youtube-dl "$1" -x -o "%(title)s.%(ext)s" --audio-format=mp3 --audio-quality=512k && mv "${filename}.mp3" "${HOME}/Drive/Music";
popd > /dev/null;
}There has to be a better way of doing this? I can't seem to find a solution in the manual. |
|
The output template accept path parts. For example, youtube-dl "$1" -x -o "~/Drive/Music/%(title)s.mp3" --audio-format=mp3 --audio-quality=512k |
|
@yan12125 Yeah that's how I did it before. But when you directly set the file to I think I managed to update my script after you commented, it works perfectly™ now. |
|
@williamboman i am have similar issue - when download mp3 and set option -o file.mp3 youtube-dl skip post-processing and resulting file is not readable in podcast players. |
|
The remaining issue is that --get-filename doesn't work with post-processing (mp3 conversion, etc.). This is discussed in #7137. |
I want to automate sending the newly downloaded file to my google play music using the almost-as-awesome-as-youtube-dl-library http://unofficial-google-music-api.readthedocs.org/
I am aware I could do that in python, but not being a python dev, I'd rather write a bash script for higher level operation.
Here's my take
My single trouble is to get the filename (or filepath) generated from
youtube-dlscript. Any tip on how I could do that?I'll post final solution for those who could be interested.
Thanks a lot,