Closed jw-in-1-Team closed 3 years ago
random.shuffle()
in this case was totally unnecessary. It will always be random because a set
is used to store the links.
A set object is an unordered collection of distinct hashable objects.
If you were to change it to a list
, the links would be sorted in the order they appear in the API, starting with Broadcasting working its way down to Interviews. There will also be a lot of duplicates, since a video may be in more than one place (especially with the Feature videos pages). That is why set
is used - it will remove all duplicates.
What is it you want to achieve by removing shuffle?
Dear Alex, thanks so much for your job that i use also for KODI
thanks so much , i change the code like this and for LastestVideos, i found this continue to shuffle even if the order is correct like VLC is shuffle not me...
START python "jwb-stream" --lang F --category LatestVideos "C:\Program Files\VideoLAN\VLC\vlc.exe" --fullscreen --sub-autodetect-file
I attach the jw-stream i have modified.
if you can test . 1) no double but shuffle all the time even i jump the line.
On 2/6/2021 9:57 AM, Alex wrote:
|random.shuffle()| in this case was totally unnecessary. It will always be random because a |set| https://docs.python.org/3/library/stdtypes.html?highlight=built%20types#set-types-set-frozenset is used to store the links.
A set object is an /unordered/ collection of distinct hashable objects.
If you were to change it to a |list|, the links would be sorted in the order they appear in the API, starting with Broadcasting working its way down to Interviews. There will also be a lot of duplicates, since a video may be in more than one place (especially with the Feature videos pages). That is why |set| is used - it will remove all duplicates.
What is it you want to achieve by removing shuffle?
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/allejok96/jw-scripts/issues/35#issuecomment-774428380, or unsubscribe https://github.com/notifications/unsubscribe-auth/ASXF3L3MOZZUNNRIJA6AIHDS5UAA5ANCNFSM4XFQDFZA.
import random import subprocess import time from jwlib.arguments import ArgumentParser, Settings from jwlib.parse import parse_broadcasting, Media
parser = ArgumentParser(prog='jwb-stream', usage='%(prog)s [options] [DIR]', description='Stream videos from jw.org')
parser.add_arguments(['--lang', '--languages', '--quality', '--hard-subtitles', '--category', '--exclude', '--latest', '--since', '--forever', 'command']) settings = Settings()
settings.include_categories = ('VODStudio',) parser.parse_args(namespace=settings)
pasnouveaute = True print(pasnouveaute)
if not settings.command: raise RuntimeError("Not enough arguments")
while True:
# Do the indexing
data = parse_broadcasting(settings)
if not data:
exit()
# All unique
links = set()
for category in data:
# special jw-in-1
#print("CATEGORIE NOUVELLE!!!")
if category.key == 'LatestVideos':
pasnouveaute = False
for item in category.contents:
if isinstance(item, Media):
print(item.name)
if item.exists_in('.'):
# Use local files if available
links.add(item.filename)
else:
links.add(item.url)
print(links)
print("______________________________")
links = list(links)
if pasnouveaute:
print("SHUFFLE VIDEOS")
random.shuffle(links)
# Avoid too long argument string (win) or too manny arguments (unix)
while links:
subprocess.check_call(settings.command + links[:300])
links = links[300:]
if not settings.stream_forever:
break
Here you see examples on how to keep original order, shuffle or sort. I don't know exactly what result you want.
If you keep original order, LatestVideos
will have newest first. But VODStudio
will not be 100% in date order.
#!/usr/bin/env python3
import random
import subprocess
import time
from jwlib.arguments import ArgumentParser, Settings
from jwlib.parse import parse_broadcasting, Media
parser = ArgumentParser(prog='jwb-stream',
usage='%(prog)s [options] [DIR]',
description='Stream videos from jw.org')
parser.add_arguments(['--lang',
'--languages',
'--quality',
'--hard-subtitles',
'--category',
'--exclude',
'--latest',
'--since',
'--forever',
'command'])
settings = Settings()
# Default starting point
settings.include_categories = ('VODStudio',)
parser.parse_args(namespace=settings)
# special jw-in-1
pasnouveaute = True
print(pasnouveaute)
if not settings.command:
raise RuntimeError("Not enough arguments")
while True:
# Do the indexing
data = parse_broadcasting(settings)
if not data:
exit()
# links SHOULD BE A list INSTEAD OF A set TO PRESERVE ORIGINAL ORDERING
links = list()
for category in data:
# special jw-in-1
#print("CATEGORIE NOUVELLE!!!")
if category.key == 'LatestVideos':
pasnouveaute = False
for item in category.contents:
if isinstance(item, Media):
print(item.name)
if item.exists_in('.'):
# Use local files if available
# WHEN USING list, USE append() INSTEAD OF add()
links.append(item.filename)
else:
links.append(item.url)
print("\nList with original order, may contain doublets: \n")
print('\n'.join(links)) # pretty print
print("\nConverted to set which removes doublets, but also removes order: \n")
links = set(links)
print('\n'.join(links)) # pretty print
print("\nConverted to sorted list (alphabetical, pointless), no doublets because they were removed earlier: \n")
links = sorted(links)
print('\n'.join(links)) # pretty print
# Avoid too long argument string (win) or too manny arguments (unix)
while links:
subprocess.check_call(settings.command + links[:300])
links = links[300:]
if not settings.stream_forever:
break
thanks i test ans it work and i simplify :
pasnouveaute = True
if not settings.command: raise RuntimeError("Not enough arguments")
while True:
# Do the indexing
data = parse_broadcasting(settings)
if not data:
exit()
# All unique
links = list()
for category in data:
# special jw-in-1
#print("CATEGORIE NOUVELLE!!!")
if category.key == 'LatestVideos':
pasnouveaute = False
for item in category.contents:
if isinstance(item, Media):
print(item.name)
if item.exists_in('.'):
# Use local files if available
links.append(item.filename)
else:
links.append(item.url)
print('\n'.join(links)) # pretty print
print("______________________________")
# links = list(links)
if pasnouveaute:
print("SHUFFLE VIDEOS")
random.shuffle(links)
hello,
i comment random.shuffle(links) in jw-stream and the movie continue to be shuffle !
i can not understand why?