-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.py
105 lines (96 loc) · 3.35 KB
/
script.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
from asyncore import loop
from copy import copy
import os
import shutil
from urllib import response
from xml.dom import minidom
import constants
import requests
import time
###
# gets the size of the selected playlists
###
def getSize(playlists):
total = 0
for playlist in playlists:
response = requests.get(constants.PLEX_ADDR + playlist["path"])
xmlParts = minidom.parseString(response.text).getElementsByTagName("Part")
for elem in xmlParts:
file = elem.attributes['file'].value.replace(constants.FILE_REPLACE, '').replace('/', '\\')
if constants.PRINT_FILES:
print(file)
size = os.stat(constants.SERVER_SHARE + file).st_size
total += size
return round(total/1000000000, 3)
###
# copies the playlists selected to the destination
###
def copyFiles(playlists):
print('**************************Copying Files Start**************************')
for playlist in playlists:
response = requests.get(constants.PLEX_ADDR + playlist["path"])
xmlParts = minidom.parseString(response.text).getElementsByTagName("Part")
for elem in xmlParts:
id = elem.attributes["id"].value
file = constants.SERVER_SHARE + elem.attributes['file'].value.replace(constants.FILE_REPLACE, '').replace('/', '\\')
print("copying ID: " + id + " file: " + file)
shutil.copy(file, constants.DESTINATION)
print("**************************Copying Files Complete**************************")
###
# Selects the playlists
###
def selectPlaylists():
playlistsToCopy = []
response = requests.get(constants.PLEX_ADDR + "/playlists/")
playlistsXML = minidom.parseString(response.text).getElementsByTagName("Playlist")
playlist = {}
i=1
for playlistXML in playlistsXML:
playlist[i] = {'name':playlistXML.attributes["title"].value, 'path':playlistXML.attributes["key"].value.replace(constants.FILE_REPLACE, '')}
i+=1
for item in playlist:
print("[" + str(item) + "]: " + playlist[item]["name"])
temp = input("Enter playlists separated by commas: ")
ids = temp.split(',')
for id in ids:
playlistsToCopy.append(playlist[int(id)])
return playlistsToCopy
###
# prints the menu
###
def printMenu():
print("Select an options below:")
print("[1]: Select Playlists")
print("[2]: Set Options (Not implemented yet, set constants.py)")
print("[3]: Get Size of selected playlist")
print('[4]: Copy Playlists')
print('[5]: Exit')
def __main__():
option = 0
playlistsToCopy = []
while(option != 5):
printMenu()
selectedOption = input("Enter option: ")
option = int(selectedOption)
if(option == 1):
playlistsToCopy = selectPlaylists()
for playlist in playlistsToCopy:
print(playlist["name"])
elif(option == 2):
print("set options")
print("This feature isn't working yet, set options via constants.py")
elif(option == 3):
if(len(playlistsToCopy) <= 0):
print("Select playlists first")
else:
size = getSize(playlistsToCopy)
print("File size of the following playlists in GB: " + str(size))
for playlist in playlistsToCopy:
print(playlist["name"])
elif(option == 4):
if(len(playlistsToCopy) <= 0):
print("Select playlists first")
else:
copyFiles(playlistsToCopy)
time.sleep(1.5)
__main__()