boyska 6 years ago
parent
commit
e9ca1cf181
1 changed files with 8 additions and 2 deletions
  1. 8 2
      feed

+ 8 - 2
feed

@@ -8,6 +8,7 @@ import re
 import urllib.request
 from urllib.parse import urlparse, unquote
 import posixpath
+import random
 
 from lxml import html
 import requests
@@ -115,6 +116,8 @@ def get_parser():
                    'By default, play from most recent')
     p.add_argument('--max-len', default=0, type=int,
                    help='Exclude any audio that is longer than MAXLEN seconds')
+    p.add_argument('--random', default=False,
+                   action='store_true', help='Pick randomly')
     p.add_argument('--howmany', default=1, type=int,
                    help='If not specified, only 1 will be played')
     p.add_argument('--slotsize', help='Seconds between each audio', type=int)
@@ -154,13 +157,16 @@ def main():
         audios = [audio for audio in get_urls(tree)
                   if args.max_len == 0 or
                   audio.durata <= args.max_len]
-        audios = audios[args.start:args.start+args.howmany]
     else:
         groups = get_grouped_urls(tree)
         audios = [groups[g] for g in groups.keys()
                   if args.max_len == 0 or
                   groups[g].durata <= args.max_len
-                 ][args.start:args.start+args.howmany]
+                  ]
+    audios = audios[args.start:]
+    if args.random:
+        random.shuffle(audios)
+    audios = audios[:args.howmany]
 
     # the for loop excludes the last one
     # this is to support  the --slotsize option