Repository: ytdl-org/youtube-dl

Issue:
randomize playlist order, i.e.  --playlist-random
- [x] I've **verified** and **I assure** that I'm running youtube-dl **2017.01.29**
- [x] At least skimmed through [README](https://github.com/rg3/youtube-dl/blob/master/README.md) and **most notably** [FAQ](https://github.com/rg3/youtube-dl#faq) and [BUGS](https://github.com/rg3/youtube-dl#bugs) sections
- [x] [Searched](https://github.com/rg3/youtube-dl/search?type=Issues) the bugtracker for similar issues including closed ones

### What is the purpose of your *issue*?
- [x] Feature request (request for a new functionality)

Please add support for **randomizing the playlist** download order via  `--playlist-random` (or whatever other switch name).

Since there is already an option for `--reverse-playlist`, I don't think this should be too hard? (I'd contribute it myself if I was more confident in my python skills.)

The motivation for this feature is that it could be used in conjunction with `--max-downloads` (i.e. set to a low value) to randomly "sample" a variety of videos from across a channel with lots of videos, as opposed to just being able to get the first few (or last few, using `--reverse-playlist`).


Discussion:

Resolving patch:
diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py
--- a/youtube_dl/YoutubeDL.py
+++ b/youtube_dl/YoutubeDL.py
@@ -24,6 +24,7 @@
 import time
 import tokenize
 import traceback
+import random
 
 from .compat import (
     compat_basestring,
@@ -159,6 +160,7 @@ class YoutubeDL(object):
     playlistend:       Playlist item to end at.
     playlist_items:    Specific indices of playlist to download.
     playlistreverse:   Download playlist items in reverse order.
+    playlistrandom:    Download playlist items in random order.
     matchtitle:        Download only matching titles.
     rejecttitle:       Reject downloads for matching titles.
     logger:            Log messages to a logging.Logger instance.
@@ -842,6 +844,9 @@ def iter_playlistitems(format):
             if self.params.get('playlistreverse', False):
                 entries = entries[::-1]
 
+            if self.params.get('playlistrandom', False):
+                random.shuffle(entries)
+
             for i, entry in enumerate(entries, 1):
                 self.to_screen('[download] Downloading video %s of %s' % (i, n_entries))
                 extra = {
diff --git a/youtube_dl/__init__.py b/youtube_dl/__init__.py
--- a/youtube_dl/__init__.py
+++ b/youtube_dl/__init__.py
@@ -344,6 +344,7 @@ def parse_retries(retries):
         'playliststart': opts.playliststart,
         'playlistend': opts.playlistend,
         'playlistreverse': opts.playlist_reverse,
+        'playlistrandom': opts.playlist_random,
         'noplaylist': opts.noplaylist,
         'logtostderr': opts.outtmpl == '-',
         'consoletitle': opts.consoletitle,
diff --git a/youtube_dl/options.py b/youtube_dl/options.py
--- a/youtube_dl/options.py
+++ b/youtube_dl/options.py
@@ -470,6 +470,10 @@ def _scrub_eq(o):
         '--playlist-reverse',
         action='store_true',
         help='Download playlist videos in reverse order')
+    downloader.add_option(
+        '--playlist-random',
+        action='store_true',
+        help='Download playlist videos in random order')
     downloader.add_option(
         '--xattr-set-filesize',
         dest='xattr_set_filesize', action='store_true',


Test patch: