-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
75 lines (58 loc) · 2.33 KB
/
main.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
# move shows and movies from plex playlist to watchlist in bulk
try:
from BeautifulSoup import BeautifulSoup
except ImportError:
from bs4 import BeautifulSoup
import urllib
import requests
def getPlaylistId(plexUrl, plexToken):
playlistsLink = "%s/playlists?X-Plex-Token=%s" % (plexUrl, plexToken)
f = urllib.urlopen(playlistsLink)
parsed_html = BeautifulSoup(f.read(), 'xml')
playlists = {}
for playlist in parsed_html.find_all("Playlist"):
playlists[int(playlist.get("ratingKey"))] = playlist.get("title")
while 1:
for playlistKey in playlists.keys():
val = playlists[playlistKey]
print("Key", playlistKey, 'value', val)
try:
selectedPlaylistKey = int(input("enter source playlist key:"))
except ValueError:
print('Please enter an integer.')
continue
if selectedPlaylistKey in playlists.keys():
break
print "invalid playlist key!"
return selectedPlaylistKey
def getAllShowIdentifiersFromPlaylist(plexUrl, plexToken, playlistId):
playlistLink = "%s/playlists/%s/items?X-Plex-Token=%s" % (plexUrl, playlistId, plexToken)
f = urllib.urlopen(playlistLink)
parsed_html = BeautifulSoup(f.read(), 'xml')
playlistShowIdentifiers = [];
for videos in parsed_html.find_all("Video"):
try:
playlistShowIdentifiers.append(videos.get("grandparentGuid").replace("plex://show/", ""))
except:
pass
try:
playlistShowIdentifiers.append(videos.get("guid").replace("plex://movie/", ""))
except:
pass
# make distinct
return list(set(playlistShowIdentifiers))
plexUrl = input("please enter plex url (example: 127.0.0.1:32400):")
plexToken = input("please enter plex token (see: https://www.plexopedia.com/plex-media-server/general/plex-token/):")
playlistId = getPlaylistId(plexUrl, plexToken)
playlistShowIdentifiers = getAllShowIdentifiersFromPlaylist(plexUrl, plexToken, playlistId)
print playlistShowIdentifiers
# https://curlconverter.com/
headers = {
'x-plex-token': ('%s' % plexToken),
}
for result in playlistShowIdentifiers:
params = {
'ratingKey': result
}
response = requests.put('https://metadata.provider.plex.tv/actions/addToWatchlist', params=params, headers=headers)
print(response)