This repository has been archived by the owner on Oct 5, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsleep_playlist.py
79 lines (67 loc) · 1.97 KB
/
sleep_playlist.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
from random import randint
import sys
def plexlogin():
global plex
from plexapi.myplex import MyPlexAccount
from plexapi.server import PlexServer
PLEXSERVERIP = "SERVERIPGOESHERE" #plex server ip goes here.
PLEXSERVERPORT = "32400" #usually 32400, but if yours is different replace.
baseurl = 'http://' + PLEXSERVERIP + ':' + PLEXSERVERPORT
#note: May need to add your local network as an network authorized without access to use the local access method.
try:
LOGGEDIN
except Exception:
try:
plex = PlexServer(baseurl)
except Exception:
print ("Local Fail. Trying cloud access.")
#You will need to add your username, password, servername below if your local access fails.
PLEXUN = "MYPLEXUN"
PLEXPW = "MYPLEXPW"
PLEXSVR = "PLEXSERVERNAME"
user = MyPlexAccount.signin(PLEXUN,PLEXPW)
plex = user.resource(PLEXSVR).connect()
LOGGEDIN = "YES"
def geteps(cshow, num):
global plex
plexlogin()
ccheck = ""
TITLE = "TBN_PLEX: SLEEPER"
for video in plex.search(cshow):
if video.type == "show":
xshow = video.episodes()
xnum = int(len(xshow))-1
ccheck = "found"
if "found" not in ccheck:
return ("Error: " + cshow + " not found in library.")
try:
title = plex.playlist(TITLE)
title.delete()
except Exception:
pass
min = 0
eps = []
while (min <= (num-1)):
epn = randint(0,xnum)
addme = xshow[epn]
if ("unwatched" not in sys.argv):
if addme not in eps:
eps.append(addme)
min = min + 1
else:
if addme.viewCount >0:
pass
else:
if addme not in eps:
eps.append(addme)
min = min + 1
ccnt = 0
plex.createPlaylist(TITLE,eps)
return ("Sleep Playlist: \"TBN_PLEX: SLEEPER\" has been successfully created.")
try:
show = str(sys.argv[1])
num = int(sys.argv[2])
say = geteps(show,num)
except IndexError:
say = "Error: You must provide both a show name and a number of episodes to use this command."
print (say)