YouTube doesn't have an option to sort by duration. You can only filter by "short videos" and "long videos", so here I made a chrome extension that does exactly that.
-
Download the latest release, or the latest commit with the message "updated to version <version number>"
-
Add a file called secret.js
-
Declare a variable called
apiKey
and put your API key for the YouTube Data API in it:var apiKey = "...";
-
Install the chrome extension by following this Stack Overflow answer.
In fact, the YouTube Data API doesn't have a sort by duration option either, so what I did was to request search results by relevance, and then sort them on the client. Note that I only fetch the 250 most relevant videos, anything more than that is going to take (IMO) too long to fetch and sort. I can't fetch them lazily (e.g. infinite scrolling) either because the new results I get would affect the sort order. 250 results is enough for most people, in my experience, anyway.
- Click the popup icon on the top right of chrome.
- A new tab with a search box will appear.
- Type in the search box and search.
- Wait a few seconds.
- The search results will be sorted!
- Go to a YouTube page containing some videos
- Type in
cy
and a space - Optionally, include 2 one-based indices, separated by commas, indicating the start and end index of the videos you want to sort. e.g.
10,50
means "sort the 10th to the 50th video". - Press enter and wait!