Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shuffle all the time #35

Closed
jw-in-1-Team opened this issue Feb 5, 2021 · 4 comments
Closed

shuffle all the time #35

jw-in-1-Team opened this issue Feb 5, 2021 · 4 comments

Comments

@jw-in-1-Team
Copy link

hello,

i comment random.shuffle(links) in jw-stream and the movie continue to be shuffle !

i can not understand why?

@allejok96
Copy link
Owner

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?

@jw-in-1-Team
Copy link
Author

jw-in-1-Team commented Feb 9, 2021 via email

@allejok96
Copy link
Owner

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

@jw-in-1-Team
Copy link
Author

thanks i test ans it work and i simplify :

special jw-in-1

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants