Downloading videos and movies automation

Hello everyone. I have been trying to make a script that would move all the videos that I download to the plex media folder and change the mod, user, and the group for the files access.
but the question is how do I add a line after the script and make the program in the script do that command.
example:
cd /home/diyaa/youtube
youtube-dl “what ever video to download”
mv /home/diyaa/youtube/* /ver/lib/plexmediaserver/Library/Media/youtube-dl
chown plex:plex /ver/lib/plexmediaserver/Library/Media/youtube-dl/

how do I make a script to do this:

youtube-dl --extract-audio --audio-format mp3 <video URL>

and put something instead of and download the video by doing this:

sudo ./youtube “the link”

The green lines are files.
and the blue ones are folder.

@miguel
I need your help with this please!


that’s what I have done this week, and I am trying to make more smarter and automated
@miguel “JUST FOR THE PURPOSES OF LEARNING ONLY”

Try something like this in the script:

youtube-dl --extract-audio --audio-format mp3 $1

The $1 part means “first parameter”

So make a script called “youtubeaudio” or something and put the above line in it. Then you can call it like this:

youtubeaudio https://youtu.be/pVqnL0nkfPY

and it will do what you want…

BTW, I do this with mp4 video.

I put the following script, called “youtube-dl4” in /usr/local/bin and make it executable:

youtube-dl -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/mp4' $1

and that makes sure that I only download mp4 video, not webm or any other format, even if it’s better quality.

can you explain what is going on in that “first time I see way” in that picture.

I don’t understand the question. Which picture? What is going on?

I mean this:
youtube-dl -f ‘bestvideo[ext=mp4]+bestaudio[ext=m4a]/mp4’ $1

I called it picture :joy:

Oh, that’s just my little script (just one line) that uses the youtube-dl options to download the best mp4 video and best m4a audio of a youtube video, and puts them together. Works better than webm and other formats.

Youtube keeps a whole bunch of formats of videos, and serves what it thinks is appropriate based on your client capabilities, and your connection bandwidth. For example, if you specify the -F option, it will list all the available formats:

iMac3:bin miguel$ youtube-dl -F https://youtu.be/pVqnL0nkfPY
[youtube] pVqnL0nkfPY: Downloading webpage
[youtube] pVqnL0nkfPY: Downloading video info webpage
[youtube] pVqnL0nkfPY: Downloading js player vflNoyOhW
[info] Available formats for pVqnL0nkfPY:
format code  extension  resolution note
249          webm       audio only DASH audio   65k , opus @ 50k, 1.52MiB
250          webm       audio only DASH audio   84k , opus @ 70k, 2.01MiB
140          m4a        audio only DASH audio  130k , m4a_dash container, [email protected], 3.61MiB
171          webm       audio only DASH audio  143k , [email protected], 3.68MiB
251          webm       audio only DASH audio  160k , opus @160k, 3.94MiB
160          mp4        256x144    144p  111k , avc1.4d400c, 24fps, video only, 2.18MiB
278          webm       256x144    144p  139k , webm container, vp9, 24fps, video only, 2.61MiB
242          webm       426x240    240p  222k , vp9, 24fps, video only, 4.45MiB
133          mp4        426x240    240p  271k , avc1.4d4015, 24fps, video only, 4.13MiB
243          webm       640x360    360p  405k , vp9, 24fps, video only, 8.28MiB
134          mp4        640x360    360p  589k , avc1.4d401e, 24fps, video only, 7.99MiB
244          webm       854x480    480p  756k , vp9, 24fps, video only, 14.52MiB
135          mp4        854x480    480p  983k , avc1.4d401e, 24fps, video only, 12.73MiB
247          webm       1280x720   720p 1525k , vp9, 24fps, video only, 29.20MiB
136          mp4        1280x720   720p 2001k , avc1.4d401f, 24fps, video only, 22.36MiB
248          webm       1920x1080  1080p 2700k , vp9, 24fps, video only, 61.59MiB
137          mp4        1920x1080  1080p 4322k , avc1.640028, 24fps, video only, 91.21MiB
18           mp4        640x360    medium  621k , avc1.42001E, [email protected] 96k (44100Hz), 17.30MiB (best)

The options that I use in my youtube-dl4 script just make sure it defaults to the best mp4 video and the best m4a audio. But that’s just me. I find those formats to be the most “compatible” with my stuff.

And then when I actually run my youtube-dl4 script, it does this:

iMac3:Desktop miguel$ youtube-dl4 https://youtu.be/pVqnL0nkfPY
[youtube] pVqnL0nkfPY: Downloading webpage
[youtube] pVqnL0nkfPY: Downloading video info webpage
[download] Destination: Video Killed The Radio Star - Walk off the Earth Ft. Sarah Silverman-pVqnL0nkfPY.f137.mp4
[download] 100% of 91.21MiB in 00:05
[download] Destination: Video Killed The Radio Star - Walk off the Earth Ft. Sarah Silverman-pVqnL0nkfPY.f140.m4a
[download] 100% of 3.61MiB in 00:00
[ffmpeg] Merging formats into "Video Killed The Radio Star - Walk off the Earth Ft. Sarah Silverman-pVqnL0nkfPY.mp4"
Deleting original file Video Killed The Radio Star - Walk off the Earth Ft. Sarah Silverman-pVqnL0nkfPY.f137.mp4 (pass -k to keep)
Deleting original file Video Killed The Radio Star - Walk off the Earth Ft. Sarah Silverman-pVqnL0nkfPY.f140.m4a (pass -k to keep)

and gives me the best version possible for my situation.

Notice that it picked audio version 140, and video version 137. It thought those were the highest quality mp4 and m4a versions… then used ffmpeg to put them together.

may I ask you to get me a copy of the script please

It’s just one line, linked above.

Right here.

it worked.
Thank you so much for your help sir .

how do I make a one for mp3 only.

It’s in your first post on this thread…

youtube-dl --extract-audio --audio-format mp3 URL
1 Like

Thank you :slightly_smiling_face: