I recently asked This question about the use of gpaste getoutput as STDIN for youtube-dl. That question has since then been answered, but I would like to move on to the next step of automation a multi-command task:

  1. initate a download of video in the current folder using url copied from url bar in firefox command: youtube-dl $(gpaste get [video url])

  2. convert the mkv or mp4 or m4a file to a .wav
    command: ffmpeg -i [filename of video from step one].<filetype of video from step one> [filename of video from step one].wav

  3. [...process continues...]

My question is: I am still new to regex. Is there a regex sequence that I can employ to grab the filename from the file created by the youtube-dl command and use it as the input for the following ffmpeg command?

Here’s an example:

gpaste get 0

returns https://somevideo.com/video

youtube-dl $(gpaste get 0)

Downloads file to current folder with Y filename &&

ffmpeg -i <filename Y>

Will return a duplicate of the initial file, now in .wav format

How can I get tell bash to get that filename Y before it exists, so that I can put all of this into a script?

Would I also need to filter according to a range of filetypes (all video types) or would I filter for most recent file in the current folder or a combination of both?


Just checked documentation of youtube-dl, it accepts this parameter:

--get-filename                   Simulate, quiet but print output filename

So, maybe you can try something like this:

videourl=$(gpaste get [video url])
videofilename=$(youtube-dl --get-filename $videourl)
youtube-dl $videourl
#further processing. 
  • I remember seeing this parameter in the man pages, but I had no idea how I could use it. Your solution makes total sense, just set it as a variable then call it in the next command of the sequence, am I right? – Andrew Sep 30 '15 at 3:02
  • @AndÚ, exactly. – SparedWhisle Sep 30 '15 at 4:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.