11

I want to download videos from a YouTube search query using youtube-dl. Suppose I want videos from the search query https://www.youtube.com/results?q=how+to+create+android+app+in+android+studio.

How can I download query-based videos from YouTube as well as other video sites? This is what I've tried, and it leads to the following error: error

  • As Mike Mckay answered, try youtube-dl "gvsearchX:search words here". Replace 'X' with a number. If you would prefer a website that allows downloading audio/video from YouTube instead, then I recommend offliberty.com. – David your friend Feb 2 '17 at 7:16
9

Yes, it is possible to download videos from search query on YouTube.

Adding &page=1 to the previous query allowed the download to go through.

https://www.youtube.com/results?search_query=how+to+create+android+app+in+android+studio&page=1

page 1

| improve this answer | |
  • 2
    That CANNOT be how you fixed it as youtube-dl would never see the &page=1 as you did not quote the URL! You assigned the value 1 to the shell variable $page, then ran youtube-dl as background process 4816. – Martin Thornton Apr 3 '17 at 19:41
8

There is a built-in search option for youtube-dl. Old way:

youtube-dl "gvsearch1:how to create android app in app studio"

The argument is: gvsearchX, where gvsearch means use google and X is the number of results you want to download. So the above will search for "how to create android app in app studio" and download the first result.

(Update!) Seems like ytsearch (youtube search) is the better approach now:

youtube-dl "ytsearch1:how to create android app in app studio"
| improve this answer | |
6

Besides the before-mentioned possibility to use google video search via gvsearch you can also search directly on YouTube:

youtube-dl "ytsearch1:how to create android app in app studio"

I didn't find it anywhere documented, but recently an error message pointed me into the right direction.

| improve this answer | |
  • I'd like to point out that you can watch directly the video with mpv "ytdl://ytsearch1:how to create android app in app studio" – ivanxuu Aug 9 '19 at 13:41
3

For audio tracks, you might also find useful this script to read lines of a plain text file (for example with author and title of themes) and download them to mp3:

#!/bin/bash
YOUTUBEDLAUDIO='youtube-dl --output "%(title)s.%(ext)s" --extract-audio --audio-format mp3 --audio-quality 0'

while IFS='' read -r line || [[ -n "$line" ]] && [[ ! -z "$line" ]]; do
  $YOUTUBEDLAUDIO "gvsearch1:$line"
done < "$1"
| improve this answer | |

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.