youtube-dl, how do I resume a download after error? - youtube

I am using youtube-dl to download videos from Lynda (I have an account).
After about the 40th video in a list I received this error:
ERROR: Unable to download JSON metadata: HTTP Error 403: Forbidden
Is there a way to 'restart' the downloads so I don't have to start from the first file again? Say just tell it to start from file 41 or something?
This is the command I used to download:
./youtube-dl --cookies cookies.txt --username <myusername> --password <mypassword> --sleep-interval 200 -o "%(autonumber)s - %(title)s.%(ext)s” http://www.lynda.com/C-tutorials/C-Essential-Training/188207-2.html

It's good to use a combination of -ciw when downloading playlists.
-i, --ignore-errors Continue on download errors, for example to skip
unavailable videos in a playlist
-w, --no-overwrites Do not overwrite files
-c, --continue Force resume of partially downloaded files.
By default, youtube-dl will resume downloads if possible.
The following example downloads top 100 songs on YouTube Music
youtube-dl -ciw --playlist-items 1-100 --extract-audio --audio-format mp3 --restrict-filenames https://www.youtube.com/playlist?list=PLDcnymzs18LWrKzHmzrGH1JzLBqrHi3xQ
The actual link to Youtube Music playlist varies with time, I guess. You can go the the playlist and copy. One way to check whether a link refers to a playlist or a single video, is that the playlist link has "playlist" keyword in it.

You can continue the download using:
youtube-dl <link_to_video> -c
Or
youtube-dl <link_to_video> --continue
Also, youtube-dl mostly continues the download whenever possible

Download specific videos from playlist
This is yet another useful feature of Youtube-dl. It allows us to download a specific song(s) from a playlist that contains 100s of songs.
For example, to download the 10th file from a playlist, run:
$ youtube-dl --playlist-items 10 <playlist_url>
Similarly, to download multiple random files, just specify indices of the videos in the playlist separated by commas like below::
$ youtube-dl --playlist-items 2,3,7,10 <playlist_url>
You can also specify the range of songs. To download a video playlist starting from a certain video, say 10, to end:
$ youtube-dl --playlist-start 10 <playlist_url>
To download only the files starting from 2nd to 5th in a playlist, use:
$ youtube-dl --playlist-start 2 --playlist-end 5 <playlist_url>
You should do like this if it is a playlist with 200 videos and it stuck at the 127 also use the -ciw in the same order below to avoid it from stop during errors.
youtube-dl -ciw --playlist-start 127 <then past the playlist link after the 127>
To download only the audio from the video do this
youtube-dl -ciw -x --audio-format mp3 --playlist-start 127 <then past the playlist link after the 127>
for example:
youtube-dl -ciw -x --audio-format mp3 --playlist-start 127 https://www.youtube.com/playlist?list=PLjzdNLPsCsPeeO49mvhHP5uyKdYkAbON8

You can resume a video with -c option. For instance, if you previously started a download using:
youtube-dl <some_youtube_URL>
You may, if it was stopped or interrupted, resume that download later with:
youtube-dl -c <some_youtube_URL>

To resume downloading your video use -c(continue argument) if you have supplied any format while downloading the video you need to specify the same format with -c argument
I was downloading video:
youtube-dl -f best link_to_your_video_here
Then internet went off and to resume downloading the same video:
youtube-dl -c -f best link_to_your_video_here

After all the arguments use the flag [--playlist-start (Number)] before the url. This will start the download at the specified number.

Related

How do I run ffmpeg m3u8 download on iso when moved to background?

I am trying to download an m3u8 playlist in my ioS App using the following ffmpeg command line:
-i ""+url[0].absoluteString+"" -i ""+url[1].absoluteString+"" -c copy "+downloadsDirURL.absoluteString
This works fine when the iPad is open but as soon as it has been closedand goes into Background the process stops. I have tried including the command option -nostdin without success. Is it at all possible to execute this in background mode?

Flutter/Dart: Find two video segments and merge them into a single valid video file?

I have two video files on my iPhone. Is it possible, using Dart, to find two specific 10-second segments in each, and merge them both into a valid 20 second video file?
Ok, so there's a FFMpeg plugin for flutter that allows you to do all of this.
https://github.com/tanersener/flutter-ffmpeg
Cutting a 15 second video segment starting at second 20:
ffmpeg -i Funny.mkv -ss 00:00:20 -codec copy -t 15 Funny_cut.mkv
Merging a list of videos that is stored in videos.txt:
ffmpeg -f concat -i videos.txt -c copy Funny_join.mkv
For more about FFMpeg:
https://www.poftut.com/ffmpeg-command-tutorial-examples-video-audio/

Youtube - downloading a playlist - youtube-dl

I am trying to download all the videos from the playlist:
I am using youtube-dl for this and the command is:
youtube-dl -citk –format mp4 –yes-playlist https://www.youtube.com/watch?v=7Vy8970q0Xc&list=PLwJ2VKmefmxpUJEGB1ff6yUZ5Zd7Gegn2
But this only downloads the first video. Not sure what I am doing wrong.
In a shell, & is a special character, advising the shell to start everything up to the & as a process in the background. To avoid this behavior, you can put the URL in quotes. See the youtube-dl FAQ for more information.
Also beware of -citk. With the exception of -i, these options make little sense. See the youtube-dl FAQ for more information. Even -f mp4 looks very strange.
So what you want is:
youtube-dl -i -f mp4 --yes-playlist 'https://www.youtube.com/watch?v=7Vy8970q0Xc&list=PLwJ2VKmefmxpUJEGB1ff6yUZ5Zd7Gegn2'
Alternatively, you can just use the playlist ID:
youtube-dl -i PLwJ2VKmefmxpUJEGB1ff6yUZ5Zd7Gegn2
I found the best solution after many attempts at solving this problem.
Installation and usage;
For Windows users:
Script:
youtube-dl --ignore-errors --format bestaudio --extract-audio --audio-format mp3 --audio-quality 160K --output "%(title)s.%(ext)s" --yes-playlist https://www.youtube.com/playlist?list={your-youtube-playlist-id}
Download youtube-dl.exe file from the offical site.
Dowload ffmpeg from the offical site for convert WebM to MP3 (Recomended build version)
Exctract all zip files and move youtube-dl.exe, ffmpeg.exe and ffprobe.exe files to the folder that where you want the downloaded MP3 files.
Open cmd (Windows terminal) in same folder.
Replace the script {your-youtube-playlist-id} parameter with your YouTube playlist id.
Run the script.
For macOS/Linux users:
Script:
youtube-dl --ignore-errors --format bestaudio --extract-audio --audio-format mp3 --audio-quality 160K --output "%(title)s.%(ext)s" --yes-playlist 'https://www.youtube.com/playlist?list={your-youtube-playlist-id}'
Open terminal and if you don't have Homebrew, install it. (Linux users can skip this step.)
Run brew install youtube-dl ffmpeg and install youtube-dl and ffmpeg for convert WebM to MP3. (Installation may take longer to install other dependencies.) (For Linux users: install youtube-dl ffmpeg)
Open a terminal in the folder where you want to download the MP3 files.
Replace the script {your-youtube-playlist-id} parameter with your YouTube playlist id.
Run the script.
I have tried everything above, but none could solve my problem. I fixed it by updating the old version of youtube-dl to download playlist.
To update it
sudo youtube-dl -U
or
youtube-dl -U
after you have successfully updated using the above command
youtube-dl -cit https://www.youtube.com/playlist?list=PLttJ4RON7sleuL8wDpxbKHbSJ7BH4vvCk
Some commands which you may find useful while downloading a playlist
Download a playlist
youtube-dl <playlist link>
Best quality video and best quality audio (merged ) + preferred resolution
youtube-dl -f 'bestvideo[height<=1080]+bestaudio/best[height<=1080]' <playlist link>
This command will download videos in 1080p resolution if 1080p is available otherwise it will download the next best (less than 1080p) resolution. Here, You can use 480 or 720, etc instead of 1080.
Note: Make sure that ‘FFmpeg’ is installed, otherwise video and audio will not be merged.
Best quality video and best quality audio (merged ) + preferred resolution + Add video upload date on the file name
youtube-dl -o "[%(upload_date)s] %(title)s.%(ext)s" -f 'bestvideo[height<=1080]+bestaudio/best[height<=1080]' <playlist link>
Best quality video and best quality audio (merged ) + Preferred resolution + Add video upload date on the file name + Add uploader name on the file name
youtube-dl -o "[%(upload_date)s] %(title)s [%(uploader)s].%(ext)s" -f 'bestvideo[height<=1080]+bestaudio/best[height<=1080]' <playlist link>
Subtitle
Best quality video and best quality audio (merged ) + Preferred resolution + Download auto-generated Subtitle
youtube-dl --write-auto-sub -f 'bestvideo[height<=1080]+bestaudio/best[height<=1080]' <playlist link>
Best quality video and best quality audio (merged ) + Preferred resolution + Download video creator’s uploaded subtitle
youtube-dl --write-sub -f 'bestvideo[height<=1080]+bestaudio/best[height<=1080]' <playlist link>
Best quality video and best quality audio merged + Preferred resolution + Download video Creator’s uploaded specific language’s subtitle
youtube-dl --write-sub --sub-lang en -f 'bestvideo[height<=1080]+bestaudio/best[height<=1080]' <playlist link>
Your link is not a playlist.
A proper playlist URL looks like this:
https://www.youtube.com/playlist?list=PLHSdFJ8BDqEyvUUzm6R0HxawSWniP2c9K
Your URL is just the first video OF a certain playlist. It contains https://www.youtube.com/watch? instead of https://www.youtube.com/playlist?.
Pick the playlist by clicking on the title of the playlist on the right side in the list of videos and use this URL.
Removing the v=...& part from the url, and only keep the list=... part. The main problem being the special character &, interpreted by the shell.
You can also quote your 'url' in your command.
More information here (for instance) :
https://askubuntu.com/questions/564567/how-to-download-playlist-from-youtube-dl
The easiest thing to do is to create a file.txt file and pass the link url link so:
https://www.youtube.com/watch?v=5Lj1BF0Kn8c&list=PL9YFoJnn53xyf9GNZrtiraspAIKc80s1i
make sure to include the -a parameter in terminal:
youtube-dl -a file.txt
Basically, workaround for this problem could be simple replacing & symbol with it's encoded version %26
For those who are struggling with this problem while doing it through PHP (e.g. shell_exec()) , solution could be
str_replace("&", "%26", $shell_command);

Packaging AV streams from youtube into mpeg2 ts container?

I am trying to pull video streams from Youtube and repackage it into MPEG2 TS container.Youtube streams audio(.m4a) and video(.mp4) as separate streams and packages into mp4 container format at the client end.Are there any ffmpeg libraries or any tools which packages the individual streams into MPEG2-TS container?
Yes, ffmpeg has an mpegts option. First, you will need to merge your audio and video. There is a great answer on Super User on how to merge audio and video so I will not steal the answerer's rep by copying it.
Once you have your combined video, you can convert files to MPEG-TS like this:
ffmpeg -i input.avi -f mpegts -vcodec mpeg2video -sameq output.ts
(source, I have no affiliation)

Mixing video and audio files in Rails

I have a Rails app and I get as params in a controller two files. One is audio (WAV) and the other is video (webm).
I need to mix them together so that the output is a video (mp4) with the already mixed audio.
How can I do this?
As #Meier pointed, using Ruby is not the way to go, but using an external program.
Once ffmpeg is installed on host you can run following command inside Rails to have a mkv output video file:
`ffmpeg -i #{video_file.path} -i #{audio_file.path} -acodec copy -vcodec copy -f matroska output.mkv`

Resources