Skip to content

cloph-dsp/YouTubeSortByDuration

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🔀 YouTubeSortByDuration 🚀

Forked from KohGeek/SortYoutubePlaylistByDuration — complete rewrite using YouTube's InnerTube API.

ViolentMonkey Compatible Tampermonkey Compatible Install from Greasy Fork GPL-2.0 License

Overview

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. ⚡


✨ Key Features

  • 🎬 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

📦 Installation

  1. Install a userscript manager like ViolentMonkey or Tampermonkey.
  2. Install the script from Greasy Fork.
  3. Open a YouTube playlist, and the sort controls will appear automatically.

🚀 Usage

  1. Open a YouTube playlist.
  2. Select a sort order (by Longest or by Shortest).
  3. Click Sort Videos to begin.
  4. The page will reload when sorting is complete.

🛠 Technical Details

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 positions
  • SAPISIDHASH authentication — uses your session cookie to authorize requests
  • ytInitialData parsing — extracts setVideoId identifiers from YouTube's page data
  • Virtual array tracking — tracks order in memory (DOM doesn't reflect API changes until reload)

v6.2 Fixes

  • Fixed "already sorted" false positivecurrent order is now captured before entries.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.

About

YouTubeSortByDuration is the ultimate YouTube userscript that supercharges your playlist management by sorting videos by duration.

Resources

License

Stars

3 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • JavaScript 100.0%