-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
55 lines (45 loc) · 1.67 KB
/
run.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
#!/usr/bin/python
import argparse
import logging
import sys
from plexapi.server import PlexServer
from plexapi.playlist import Playlist
logging.basicConfig(stream=sys.stdout)
logger = logging.getLogger(__name__)
def parse_args():
parser = argparse.ArgumentParser(description='PlexAPI Playlist Copier')
parser.add_argument('src_token', type=str,
help='Plex auth token for user with existing playlist.')
parser.add_argument('dst_token', type=str,
help='Plex auth token for user that will receive the playlist.')
parser.add_argument('baseurl', type=str,
help='Plex server base URL.')
parser.add_argument('playlist', type=str,
help='Playlist to copy.')
parser.add_argument('-v', '--verbose', action='count')
args = parser.parse_args()
if not (args.src_token and args.dst_token and args.baseurl and args.playlist):
parser.error('Missing argument. All arguments are required.')
return args
def main():
args = parse_args()
src_token = args.src_token
dst_token = args.dst_token
baseurl = args.baseurl
playlist = args.playlist
src_plex = PlexServer(baseurl, src_token)
dst_plex = PlexServer(baseurl, dst_token)
for src_playlist in src_plex.playlists():
print(src_playlist.title)
if src_playlist.title == playlist:
print(f"Copying playlist {playlist}...")
src_playlist.create(server=dst_plex, title=playlist, items=src_playlist.items())
print("Done!")
if not args.verbose:
loglevel = logging.WARNING
if args.verbose == 1:
loglevel = logging.INFO
if args.verbose == 2:
loglevel = logging.DEBUG
if __name__ == "__main__":
main()