Forked from KohGeek/SortYoutubePlaylistByDuration — complete rewrite using YouTube's InnerTube API.
YouTubeSortByDuration sorts YouTube playlists by video duration using YouTube's own InnerTube API — no unreliable DOM drag-and-drop simulation. Works on playlists of any size. ⚡
- 🎬 Sort playlists by video length: shortest-to-longest or longest-to-shortest
- ⚡ YouTube InnerTube API — no broken drag-and-drop, fast and reliable
- 🎨 Sleek, modern UI with intuitive controls and live status updates
- 🌐 Broad compatibility: Works on all YouTube playlist types and browsers
- 🚀 Lightweight & open-source: Zero dependencies, GPL-2.0 licensed
- Install a userscript manager like ViolentMonkey or Tampermonkey.
- Install the script from Greasy Fork.
- Open a YouTube playlist, and the sort controls will appear automatically.
- Open a YouTube playlist.
- Select a sort order (
by Longestorby Shortest). - Click Sort Videos to begin.
- The page will reload when sorting is complete.
Version 6.0 replaced the broken DOM drag-and-drop approach with YouTube's youtubei/v1/browse/edit_playlist API:
ACTION_MOVE_VIDEO_AFTER— moves videos to their correct positionsSAPISIDHASH authentication— uses your session cookie to authorize requestsytInitialDataparsing — extractssetVideoIdidentifiers from YouTube's page data- Virtual array tracking — tracks order in memory (DOM doesn't reflect API changes until reload)
- Fixed "already sorted" false positive —
currentorder is now captured beforeentries.sort()in-place mutation - Ensured durations are fully loaded before sorting (previous versions could sort videos with no duration data to the wrong position)
- Filtered out entries with missing video IDs — videos whose identifiers couldn't be extracted from the DOM are now cleanly skipped instead of causing API errors
❤️ Contributing
Contributions, bug reports, and feature requests are welcome! Please fork the repo, create a feature branch, and open a pull request.