You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
TRaSH-Guides/Downloaders/SABnzbd/scripts/replace_for/replace_for.py

48 lines
1.9 KiB

#!/usr/bin/python3 -OO
##################################################################
### SABnzbd - Replace underscores with dots ##
##################################################################
## ##
## NOTE: This script requires Python 3 ##
## ##
## Author: miker ##
## ##
## Install: ##
## 1. Copy script to sabnzbd's script folder ##
## 2. run: sudo chmod +x replace_for.py ##
## 3. in SABnzbd go to Config > Categories ##
## 4. Assign replace_for.py to the required category ##
##################################################################
import sys
import os
import os.path
try:
try:
# Parse the 18 input variables for SABnzbd version >= 4.0.0
(scriptname, nzbname, postprocflags, category, script, prio, downloadsize, grouplist, showname, season, episodenumber, episodename, is_proper, resolution, decade, year, month, day, job_type) = sys.argv
except ValueError:
# ...or 11 variables for earlier versions
(scriptname, nzbname, postprocflags, category, script, prio, downloadsize, grouplist, showname, season, episodenumber, episodename) = sys.argv
except:
print("No commandline parameters found")
sys.exit(1) # exit with 1 causes SABnzbd to ignore the output of this script
files = os.listdir(directory)
for src in files:
if src.find("_") !=-1:
dst = src.replace('_', '.')
os.rename (os.path.join(directory,src),os.path.join(directory,dst) )
print(src, "renamed to ",dst)
print()
print()
print()
print()
# 0 means OK
sys.exit(0)