Git Product home page Git Product logo

Comments (4)

allejok96 avatar allejok96 commented on August 11, 2024

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?

from jw-scripts.

jw-in-1-Team avatar jw-in-1-Team commented on August 11, 2024

from jw-scripts.

allejok96 avatar allejok96 commented on August 11, 2024

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

from jw-scripts.

jw-in-1-Team avatar jw-in-1-Team commented on August 11, 2024

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)

from jw-scripts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.