Aggiunta funzione che permette di non caricare i file doppi
parent
75231952dd
commit
c2304ac4c0
51
upload.py
51
upload.py
|
@ -5,16 +5,19 @@ import json
|
||||||
# Video Library e Api Key ottenute tramite interfaccia di BunnyCDN https://panel.bunny.net/stream
|
# Video Library e Api Key ottenute tramite interfaccia di BunnyCDN https://panel.bunny.net/stream
|
||||||
VIDEO_LIBRARY: int = 23411
|
VIDEO_LIBRARY: int = 23411
|
||||||
API_KEY: str = "2237b6ed-4454-4937-b5f870d55cc0-a148-4937"
|
API_KEY: str = "2237b6ed-4454-4937-b5f870d55cc0-a148-4937"
|
||||||
endpoint_listCollection = f"http://video.bunnycdn.com/library/{VIDEO_LIBRARY}/collections"
|
endpoint_listCollection = (
|
||||||
|
f"http://video.bunnycdn.com/library/{VIDEO_LIBRARY}/collections"
|
||||||
|
)
|
||||||
endpoint_createVideoID = f"http://video.bunnycdn.com/library/{VIDEO_LIBRARY}/videos"
|
endpoint_createVideoID = f"http://video.bunnycdn.com/library/{VIDEO_LIBRARY}/videos"
|
||||||
endpoint_uploadVideo = f"http://video.bunnycdn.com/library/{VIDEO_LIBRARY}/videos/"
|
endpoint_uploadVideo = f"http://video.bunnycdn.com/library/{VIDEO_LIBRARY}/videos/"
|
||||||
|
endpoint_listVideoForCollection = (
|
||||||
|
f"http://video.bunnycdn.com/library/{VIDEO_LIBRARY}/videos"
|
||||||
|
)
|
||||||
collectionId = ""
|
collectionId = ""
|
||||||
|
fileinDirectory = []
|
||||||
|
|
||||||
# Headers per BunnyCDN
|
# Headers per BunnyCDN
|
||||||
headers = {
|
headers = {"Accept": "application/json", "AccessKey": API_KEY}
|
||||||
"Accept": "application/json",
|
|
||||||
"AccessKey": API_KEY
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def getCollectionList():
|
def getCollectionList():
|
||||||
|
@ -24,7 +27,9 @@ def getCollectionList():
|
||||||
data = response.json()
|
data = response.json()
|
||||||
for dirlist in data["items"]:
|
for dirlist in data["items"]:
|
||||||
collectionList[dirlist["name"]] = dirlist["guid"]
|
collectionList[dirlist["name"]] = dirlist["guid"]
|
||||||
listOfPossibleCollection = " - ".join(['{0}'.format(k) for k in collectionList.keys()])
|
listOfPossibleCollection = " - ".join(
|
||||||
|
["{0}".format(k) for k in collectionList.keys()]
|
||||||
|
)
|
||||||
print(listOfPossibleCollection)
|
print(listOfPossibleCollection)
|
||||||
select_folder = input("Seleziona la cartella dove caricare i file : ")
|
select_folder = input("Seleziona la cartella dove caricare i file : ")
|
||||||
if select_folder in collectionList.keys():
|
if select_folder in collectionList.keys():
|
||||||
|
@ -36,13 +41,17 @@ def getCollectionList():
|
||||||
print("Errore : ", response.status_code)
|
print("Errore : ", response.status_code)
|
||||||
print(response.content)
|
print(response.content)
|
||||||
|
|
||||||
|
|
||||||
def getVideoID(title_obj, count):
|
def getVideoID(title_obj, count):
|
||||||
headers["Content-Type"] = "application/*+json"
|
headers["Content-Type"] = "application/*+json"
|
||||||
if(count==1):
|
if count == 1:
|
||||||
global collectionId
|
global collectionId
|
||||||
collectionId = getCollectionList()
|
collectionId = getCollectionList()
|
||||||
payload = {"title": title_obj, "collectionId": collectionId}
|
payload = {"title": title_obj, "collectionId": collectionId}
|
||||||
payload = json.dumps(payload)
|
payload = json.dumps(payload)
|
||||||
|
if checkIfFileExistsOnBunnyCDN(title_obj) == True:
|
||||||
|
return
|
||||||
|
else:
|
||||||
response = requests.post(endpoint_createVideoID, headers=headers, data=payload)
|
response = requests.post(endpoint_createVideoID, headers=headers, data=payload)
|
||||||
if response.ok:
|
if response.ok:
|
||||||
print(response.json()["guid"])
|
print(response.json()["guid"])
|
||||||
|
@ -52,16 +61,41 @@ def getVideoID(title_obj,count):
|
||||||
print(response.content)
|
print(response.content)
|
||||||
|
|
||||||
|
|
||||||
|
def checkIfFileExistsOnBunnyCDN(title_file):
|
||||||
|
url = f"{endpoint_listVideoForCollection}?collection={collectionId}&orderBy=date&itemsPerPage=10000"
|
||||||
|
response = requests.get(url, headers=headers)
|
||||||
|
if response.ok:
|
||||||
|
data = response.json()
|
||||||
|
for files in data["items"]:
|
||||||
|
global fileinDirectory
|
||||||
|
fileinDirectory.append(files["title"])
|
||||||
|
if title_file in fileinDirectory:
|
||||||
|
print(f"File doppio : {title_file} - Non verrá caricato... ")
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
print("Errore : ", response.status_code)
|
||||||
|
print(response.content)
|
||||||
|
|
||||||
|
|
||||||
def upload(file_obj):
|
def upload(file_obj):
|
||||||
|
"""
|
||||||
|
Carica i file da Gdrive a BunnyCDN Stream (Conviene Montare i file localmente con Rclone)
|
||||||
|
Possibile usarlo per caricare file da locale
|
||||||
|
"""
|
||||||
count = 1
|
count = 1
|
||||||
# Carica i file da Gdrive a BunnyCDN Stream (Conviene Montare i file localmente con Rclone)
|
|
||||||
if os.path.isdir(file_obj) != True:
|
if os.path.isdir(file_obj) != True:
|
||||||
print(" La cartella selezionata non esiste! ")
|
print(" La cartella selezionata non esiste! ")
|
||||||
for files in os.listdir(file_obj):
|
for files in os.listdir(file_obj):
|
||||||
|
print(count)
|
||||||
file_path = os.path.join(file_obj, files)
|
file_path = os.path.join(file_obj, files)
|
||||||
content_name = str(files)
|
content_name = str(files)
|
||||||
videoId = getVideoID(content_name, count)
|
videoId = getVideoID(content_name, count)
|
||||||
count += 1
|
count += 1
|
||||||
|
if videoId == None:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
headers = {
|
headers = {
|
||||||
"AccessKey": API_KEY,
|
"AccessKey": API_KEY,
|
||||||
"Accept": "application/json",
|
"Accept": "application/json",
|
||||||
|
@ -86,7 +120,6 @@ def upload(file_obj):
|
||||||
print(status_msg)
|
print(status_msg)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
folderUpload = input("Inserisci la cartella dove sono presenti i file : ")
|
folderUpload = input("Inserisci la cartella dove sono presenti i file : ")
|
||||||
upload(folderUpload)
|
upload(folderUpload)
|
Loading…
Reference in New Issue