Comments (4)
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.
from jw-scripts.
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.
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)
- UnicodeEncodeError HOT 2
- is it posible to download songs in mp3 format HOT 2
- download experiences audio HOT 3
- Lyrics and lead sheets HOT 1
- JW Broadcasting video bug HOT 5
- Return watching HOT 5
- List languages HOT 3
- Checksums are very slow HOT 8
- possible to get the friendly name ? HOT 3
- Windows: link not working HOT 3
- All videos/media for meeting that week HOT 1
- TypeError on windows 10 HOT 4
- new approach HOT 1
- Improving streaming HOT 12
- Not an Issue: Just a windows example HOT 2
- Match subtitle names and add language code to filename HOT 13
- jw-scripts 2.0 survey (I want your brain) HOT 7
- Symlinks are not created correctly HOT 2
- issue with downloading HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
đ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google â¤ď¸ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jw-scripts.