Code: Select all
#!/usr/bin/env python
import httplib
import subprocess
import sys
import os
import shutil
source_path = sys.argv[1]
file_name = sys.argv[3]
category = sys.argv[5]
pp_status = sys.argv[7]
move_dir = "/mnt/user/Downloads/"
if pp_status == 0:
currentDir = os.path.abspath(source_path)
filesInCurDir = os.listdir(currentDir)
for file in filesInCurDir:
curFile = os.path.join(currentDir, file)
if os.path.isfile(curFile):
curFileExtension = curFile[-3:]
if curFileExtension in ['avi', 'mkv', 'mp4'] and not "sample" in curFile:
try:
shutil.move(curFile, move_dir)
except shutil.Error:
print "\nDestination path " + curFile + " already exists"
shutil.rmtree(currentDir)
with open(os.devnull) as devnull:
subprocess.call(['curl', '-s', '-F', 'token=*****', '-F', 'user=*****', '-F', 'title=Download Finished', '-F', 'message=' + file_name, 'https://api.pushover.net/1/messages.json'], stdout=devnull, stderr=devnull)
connection = httplib.HTTPConnection('*****')
body_content = '<action><name>forceLibraryRefresh</name></action>'
headers = { "Content-type": "text/xml" }
connection.request('POST', '/rest/action' , body_content , headers)
result = connection.getresponse()
if result.status == 200:
print "\nUpdated Serviio Library"
else:
print "\nUpdate Failed"
elif pp_status != 0:
with open(os.devnull) as devnull:
subprocess.call(['curl', '-s', '-F', 'token=*****', '-F', 'user=*****', '-F', 'title=Download Failed', '-F', 'message=' + file_name, 'https://api.pushover.net/1/messages.json'], stdout=devnull, stderr=devnull)
Code: Select all
please sanitize before posting