Replace/remove substring in title

Share your scripts or request scripts with specific features.
Forum rules
Please keep the forum clean - one topic per script. Questions not related to a specific script should be posted in Support forum.
Post Reply
salami
Posts: 68
Joined: 14 Apr 2014, 11:09
Location: Switzerland

Replace/remove substring in title

Post by salami » 10 Feb 2015, 09:20

One of my indexers adds an annoying tag to some posts, would it be possible to add an RSS-option that would allow me to automatically remove that?

hugbug
Developer & Admin
Posts: 6710
Joined: 09 Sep 2008, 11:58
Location: Germany (NRW)

Re: [Feature Request] RSS: Replace/remove substring

Post by hugbug » 10 Feb 2015, 09:38

Scan-script is a place where you can modify nzb-name:

Code: Select all

echo "[NZB] NZBNAME=my download";

salami
Posts: 68
Joined: 14 Apr 2014, 11:09
Location: Switzerland

Re: [Feature Request] RSS: Replace/remove substring

Post by salami » 10 Feb 2015, 10:06

Ah that makes more sense, the following python snippet seems to work perfectly for NZBGeek:

Code: Select all

fwp = os.environ['NZBNP_NZBNAME']
f = re.sub('(?i)-NZBgeek\.nzb$', '.nzb', fwp)
if f:
	print('[NZB] NZBNAME=', f, sep='')
Thanks for the hint!

wurzel
Posts: 4
Joined: 28 Mar 2016, 09:31

Re: [Feature Request] RSS: Replace/remove substring

Post by wurzel » 28 Mar 2016, 09:32

Hi,

I have the same problem with -Obfuscated etc. Can anyone elaborate what I need to do here? I am not that good into coding.


Greetings

salami
Posts: 68
Joined: 14 Apr 2014, 11:09
Location: Switzerland

Re: [Feature Request] RSS: Replace/remove substring

Post by salami » 28 Mar 2016, 10:08

This is my current script to remove a few of those:

Code: Select all

#!c:\Python34\python.exe
# 

##############################################################################
### NZBGET SCAN SCRIPT                                                     ###

# Removes NZBGeek suffixes from NZB name.

### NZBGET SCAN SCRIPT                                                     ###
##############################################################################

import os, re, sys

# Code from EMail.py @ http://nzbget.sourceforge.net
# Exit codes used by NZBGet
POSTPROCESS_SKIP=95
POSTPROCESS_ERROR=94
POSTPROCESS_SUCCESS=93

# Code from EMail.py @ http://nzbget.sourceforge.net
# Check if the script is called from nzbget 13.0 or later
if not 'NZBOP_SCRIPTDIR' in os.environ:
	print('*** NZBGet post-processing script ***')
	print('This script is supposed to be called from nzbget (13.0 or later).')
	sys.exit(POSTPROCESS_ERROR)

if not 'NZBNP_NZBNAME' in os.environ:
	print('[WARN] Filename not found in environment')
	sys.exit(POSTPROCESS_ERROR)

fwp = os.environ['NZBNP_NZBNAME']
fwp = re.sub('(?i)-NZBgeek\.nzb$', '.nzb', fwp)
fwp = re.sub('(?i)-Chamele0n\.nzb$', '.nzb', fwp)
fwp = re.sub('(?i)-Obfuscated\.nzb$', '.nzb', fwp)
fwp = re.sub('(?i)-BUYMORE\.nzb$', '.nzb', fwp)
if fwp:
	print('[NZB] NZBNAME=', fwp, sep='')

sys.exit(POSTPROCESS_SUCCESS)
As I have no clue about python there is probably a much more elegant way to to it, but this gets the job done :)

wurzel
Posts: 4
Joined: 28 Mar 2016, 09:31

Re: [Feature Request] RSS: Replace/remove substring

Post by wurzel » 28 Mar 2016, 14:32

Any idea why this is happening?
ERROR Mon Mar 28 2016 16:28:54 Scan: Could not start /media/temp/scripts/Scan.py: No such file or directory
INFO Mon Mar 28 2016 16:28:54 Executing scan-script Scan.py for Billions.S01E10.720p.HDTV.x264-AVS-Obfuscated.nzb
The script is where it should be and it has chmod a+x rights

//ah, it was renamed to Billions.S01E10.720p.HDTV.x264-AVS-Obfuscated.nzb.queued before it could be renamed. So what do I do now? :D

salami
Posts: 68
Joined: 14 Apr 2014, 11:09
Location: Switzerland

Re: [Feature Request] RSS: Replace/remove substring

Post by salami » 28 Mar 2016, 14:39

Did you adjust the shebang (first line) to reflect your python installation? If you're using Linux, you'll have to replace it with something like this:

Code: Select all

#!/usr/bin/env python

wurzel
Posts: 4
Joined: 28 Mar 2016, 09:31

Re: [Feature Request] RSS: Replace/remove substring

Post by wurzel » 28 Mar 2016, 14:48

haha, dumb me. No I did not.

If I use python2 it says there is a syntax error.
I had to replace it with
#!/usr/bin/env python3


Thanks for your help! Works like a charm now :)

panniiii
Posts: 1
Joined: 10 Apr 2017, 01:59

Re: [Feature Request] RSS: Replace/remove substring

Post by panniiii » 10 Apr 2017, 02:01

Hey,

I've modified the script, simplified some parts, and made it python2 and 3 compatible:

Code: Select all

#!/usr/bin/env python
from __future__ import print_function

##########################################
### NZBGET SCAN SCRIPT                 ###

# Removes garbage suffixes from NZB names.
#
# NOTE: This script requires Python to be installed on your system.

### NZBGET SCAN SCRIPT                 ###
##########################################

import os
import re
import sys

# Code from EMail.py @ http://nzbget.sourceforge.net
# Exit codes used by NZBGet
POSTPROCESS_SKIP=95
POSTPROCESS_ERROR=94
POSTPROCESS_SUCCESS=93

# Code from EMail.py @ http://nzbget.sourceforge.net
# Check if the script is called from nzbget 13.0 or later
if 'NZBOP_SCRIPTDIR' not in os.environ:
   print('*** NZBGet post-processing script ***')
   print('This script is supposed to be called from nzbget (13.0 or later).')
   sys.exit(POSTPROCESS_ERROR)

if 'NZBNP_NZBNAME' not in os.environ:
   print('[WARN] Filename not found in environment')
   sys.exit(POSTPROCESS_ERROR)

fwp = re.sub('(?i)[._-](obfuscated|scrambled|nzbgeek|chamele0n|buymore)\.nzb$', '.nzb', os.environ['NZBNP_NZBNAME'], re.IGNORECASE)
if fwp:
   print('[NZB] NZBNAME=%s' % fwp)

   sys.exit(POSTPROCESS_SUCCESS)

sys.exit(POSTPROCESS_SKIP)

Post Reply

Who is online

Users browsing this forum: Baidu [Spider] and 1 guest