Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #automated nzb downloader based on imdb ratings
- #this script is designed to download nzb files from nzbs.org (requires registration)
- #original script created by popcorn, modified by binhex
- #ver 1.0
- import urllib
- import xml.dom.minidom
- import re
- import time
- import os
- import traceback
- import logging
- import socket
- #put your own folder names below as specified in sabnzbd+
- #double slashes for windows users essential
- watch_dir="J:\\downloads\\nzb"
- nzb_dir="J:\\downloads\\nzbbackup"
- completed_dir="E:\\Warez"
- #put your own folder names below to specify the location of your movie collection
- movies_dir1="E:\\Warez\\Movies"
- #put your own folder and filenames below to specify location of log files
- mainlog="J:\\sabnzbd+\\Logs\\Scriptlogs\\autodl_hd_main.log"
- tracelog="J:\\sabnzbd+\\Logs\\Scriptlogs\\autodl_hd_traceback.log"
- #put your own notification message process below for error logging or use the default
- notifylog="cmd /c msg console /TIME:43200 Script Error, Check Logs"
- #send failure messages to log file
- main_logger = logging.getLogger('myapp1')
- main_handler = logging.FileHandler(mainlog)
- main_formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
- main_handler.setFormatter(main_formatter)
- main_logger.addHandler(main_handler)
- main_logger.setLevel(logging.INFO)
- #sets timeout period for urlretrieve (in seconds)
- socket.setdefaulttimeout(240)
- #un-comment for x264 movies
- #movie_category="catid=4"
- #un-comment for dvdrips only
- #movie_format="&q=dvdrip.xvid"
- #un-comment for XviD movies
- movie_category="catid=2"
- #put your userid for nzbs.org website below (register and then go to http://www.nzbs.org/index.php?action=rss)
- userid="&i=11111&h=e1111111111111111111111111111111"
- #un-comment for 720p resolution only
- #movie_format="&q=720p"
- #un-comment for 1080p resolution only
- #movie_format="&q=1080p"
- #un-comment for all formats in selected category
- movie_format=""
- #rss feed for nzbs.org
- nzbs_org_feed="http://www.nzbs.org/rss.php?" + movie_category + userid + "&dl=1" + movie_format
- ##############
- # os filters #
- ##############
- try:
- def isInWatched(check_watched_folder):
- #this is set to download only if the nzb file doesn't exist in the watch folder (watch_dir)
- if os.path.exists(watch_dir + "\\" + check_watched_folder + ".nzb"):
- return 0
- else:
- return 1
- def isInNZB(check_nzb_folder):
- #this is set to download only if the nzb file doesn't exist in the nzb folder (nzb_dir)
- if os.path.exists(nzb_dir + "\\" + check_nzb_folder + ".nzb.gz"):
- return 0
- else:
- return 1
- def isCompleted(check_completed_folder):
- #this is set to download only if the movie doesn't exist in the completed folder (completed_dir)
- if os.path.exists(completed_dir + "\\" + check_completed_folder):
- return 0
- else:
- return 1
- def isDownloaded(check_downloaded_folder):
- #this is set to download only movies which don't exist in the movies folders (movies_dir1/2)
- if os.path.exists(movies_dir1 + "\\" + check_downloaded_folder):
- return 0
- else:
- return 1
- except:
- print("Error: OS Filter Error")
- main_logger.error("OS Filter Error")
- traceback.print_exc(file=open(tracelog,"a"))
- os.system(notifylog)
- ################
- # imdb filters #
- ################
- try:
- def isGoodRatings(imdb_html):
- #this is set to download only movies with a rating of 6.5 or more
- if re.compile("<b>6\.[5-9]/10</b>|<b>[7-9]\.[0-9]/10</b>").search(imdb_html):
- return 1
- else:
- return 0
- def isGoodVotes(imdb_html):
- #this is set to download only movies with 5,000 votes or more
- if re.compile(">[0-9][0-9]+,[0-9]+ votes<|>[5-9],[0-9]+ votes<", re.IGNORECASE).search(imdb_html):
- return 1
- else:
- return 0
- def isGoodLang(imdb_html):
- #this is set to download movies that contain language "English" (movie may contain other languages)
- if re.compile("Languages/English", re.IGNORECASE).search(imdb_html):
- return 1
- else:
- return 0
- def isGoodCountry(imdb_html):
- #this is set to download movies from countries that have english as their native language
- if re.compile("Countries/UK|Countries/USA|Countries/Canada|Countries/Australia|Countries/Ireland|Countries/SouthAfrica|Countries/NewZealand", re.IGNORECASE).search(imdb_html):
- return 1
- else:
- return 0
- def isBadDate(imdb_html):
- #this is set to download only movies with a release date of 1970 and newer
- movie_year = re.compile("<title>.+</title>").search(imdb_html)
- if movie_year is not None:
- if re.search("19[0-6][0-9]", movie_year.group()):
- return 0
- else:
- return 1
- def isBadGenre(imdb_html):
- #this is set to download only movies that DO NOT match certain genre's
- if re.compile(">Documentary<|>Musical<|>Music<", re.IGNORECASE).search(imdb_html):
- return 0
- else:
- return 1
- except:
- print("Error: IMDB Filter Error")
- main_logger.error("IMDB Filter Error")
- traceback.print_exc(file=open(tracelog,"a"))
- os.system(notifylog)
- #######################
- # nzb release filters #
- #######################
- try:
- def isGoodSize(check_movie_size):
- #this is set to download movies with file sizes from 700 MB to 2.59 GB (xvid format)
- if re.compile("[7-9][0-9][0-9].[0-9][0-9] MB|1.[0-9][0-9] GB|2.[0-5][0-9] GB", re.IGNORECASE).search(check_movie_size):
- return 1
- else:
- return 0
- def isBadGroup(check_group):
- #this is set to skip movies with the following release group names (currently disabled)
- if re.compile("-BadGroup", re.IGNORECASE).search(check_group):
- return 0
- else:
- return 1
- def isGoodMovie(check_movie):
- #this is set to ignore filters for certain movie titles
- if re.compile("good movie", re.IGNORECASE).search(check_movie):
- return 1
- else:
- return 0
- except:
- print("Error: NZB Filter Error")
- main_logger.error("NZB Filter Error")
- traceback.print_exc(file=open(tracelog,"a"))
- os.system(notifylog)
- try:
- def download(report_id):
- #this downloads the nzb from the link in the rss feed.
- print("")
- print("Status: Downloading Movie.....")
- print("IMDB Movie Title: " + imdb_movie_title + " (" + imdb_link + ")")
- print("Release Movie Title: " + movie_title)
- urllib.urlretrieve(msgid, watch_dir + "\\" + imdb_movie_title + ".nzb")
- except:
- print("Error: Download Of NZB Failed")
- main_logger.error("Download Of Movie " + imdb_movie_title + " Failed")
- traceback.print_exc(file=open(tracelog,"a"))
- os.system(notifylog)
- removeRetryCount = 0
- while removeRetryCount < 3:
- time.sleep(10)
- #sleep and retry to delete partial download 3 times
- try:
- os.remove(watch_dir + "\\" + imdb_movie_title + ".nzb")
- break
- except:
- removeRetryCount += 1
- else:
- print("Error: Deletion Of Partial NZB Failed")
- main_logger.error("Deletion Of NZB " + imdb_movie_title + " Failed")
- traceback.print_exc(file=open(tracelog,"a"))
- os.system(notifylog)
- #this reads the content of the rss feed from nzbs.org
- try:
- dom=xml.dom.minidom.parse(urllib.urlopen(nzbs_org_feed))
- except:
- print("Error: RSS Feed Error")
- main_logger.error("RSS Feed Error")
- traceback.print_exc(file=open(tracelog,"a"))
- os.system(notifylog)
- #this breaks down the rss feed page into tag sections
- for node in dom.getElementsByTagName("item"):
- movie_title = node.getElementsByTagName("title")[0].childNodes[0].data
- report_description = node.getElementsByTagName("description")[0].childNodes[0].data
- movie_desc = re.search("IMDB:.+\/\"\>", report_description)
- if movie_desc:
- try:
- movie_link = re.search("http.+\/",movie_desc.group())
- imdb_link=movie_link.group()
- sock = urllib.urlopen(imdb_link)
- htmlSource = sock.read()
- sock.close()
- except:
- print("Error: RSS Feed Tag Error")
- main_logger.error("RSS Feed Tag Error")
- traceback.print_exc(file=open(tracelog,"a"))
- os.system(notify)
- ######################
- # IMDB Title Filters #
- ######################
- try:
- #search imdb page for movie title
- imdb_movie_title_search = re.compile("<title>.+</title>").search(htmlSource)
- if imdb_movie_title_search is not None:
- imdb_movie_title = imdb_movie_title_search.group()
- #removes title tags from movie title
- imdb_movie_title = re.sub("</?title>?","" ,imdb_movie_title)
- #removes year from movie title
- imdb_movie_title = re.sub(" \(.*\)","" ,imdb_movie_title)
- #removes colons from movie title - e.g. "the movie: big movie" converts to "the movie big movie"
- imdb_movie_title = re.sub("\:","" ,imdb_movie_title)
- #removes question marks from movie title - e.g. "the movie?" converts to "the movie"
- imdb_movie_title = re.sub("\?","" ,imdb_movie_title)
- #removes end period from movie title - e.g. "the movie b.m." converts to "the movie b.m"
- imdb_movie_title = re.sub("\.$","" ,imdb_movie_title)
- #removes apostrophe from movie title - e.g. "the movie big movie's" converts to "the movie big movies"
- imdb_movie_title = re.sub("'","" ,imdb_movie_title)
- #replace xml & with "and" - e.g. "the movie & big movie" converts to "the movie and big movie"
- imdb_movie_title = re.sub("\&\;|\&\#38\;","and" ,imdb_movie_title)
- #replace roman numerals to numerics - e.g. "the movie V" converts to "the movie 5"
- imdb_movie_title = re.sub("V(?![a-zA-Z0-9_])","5", imdb_movie_title, re.I)
- #replace roman numerals to numerics - e.g. "the movie IV" converts to "the movie 4"
- imdb_movie_title = re.sub("IV(?![a-zA-Z0-9_])","4", imdb_movie_title, re.I)
- #replace roman numerals to numerics - e.g. "the movie III" converts to "the movie 3"
- imdb_movie_title = re.sub("III(?![a-zA-Z0-9_])","3" ,imdb_movie_title, re.I)
- #replace roman numerals to numerics - e.g. "the movie II" converts to "the movie 2"
- imdb_movie_title = re.sub("II(?![a-zA-Z0-9_])","2" ,imdb_movie_title, re.I)
- #converts first letter of each word in the movie title to caps e.g. "the movie" converts to "The Movie"
- imdb_movie_title = imdb_movie_title.title()
- except:
- print("Error: Title Modification Error")
- main_logger.error("Title Modification Error")
- traceback.print_exc(file=open(tracelog,"a"))
- os.system(notifylog)
- try:
- #######################
- # check filter values #
- #######################
- if (isGoodRatings(htmlSource) == 1):
- VisGoodRatings = 1
- else:
- VisGoodRatings = 0
- if (isGoodVotes(htmlSource) == 1):
- VisGoodVotes = 1
- else:
- VisGoodVotes = 0
- if (isDownloaded(imdb_movie_title) == 1):
- VisDownloaded = 1
- else:
- VisDownloaded = 0
- if (isInNZB(imdb_movie_title) == 1):
- VisInNZB = 1
- else:
- VisInNZB = 0
- if (isInWatched(imdb_movie_title) == 1):
- VisInWatched = 1
- else:
- VisInWatched = 0
- if (isCompleted(imdb_movie_title) == 1):
- VisCompleted = 1
- else:
- VisCompleted = 0
- if (isBadDate(htmlSource) == 1):
- VisBadDate = 1
- else:
- VisBadDate = 0
- if (isBadGenre(htmlSource) == 1):
- VisBadGenre = 1
- else:
- VisBadGenre = 0
- if (isBadGroup(movie_title) == 1):
- VisBadGroup = 1
- else:
- VisBadGroup = 0
- if (isGoodLang(htmlSource) == 1):
- VisGoodLang = 1
- else:
- VisGoodLang = 0
- if (isGoodCountry(htmlSource) == 1):
- VisGoodCountry = 1
- else:
- VisGoodCountry = 0
- if (isGoodSize(report_description) == 1):
- VisGoodSize = 1
- else:
- VisGoodSize = 0
- if (isGoodMovie(imdb_movie_title) == 1):
- VisGoodMovie = 1
- else:
- VisGoodMovie = 0
- if ((VisDownloaded == 1) and (VisInNZB == 1) and (VisInWatched == 1) and (VisCompleted == 1)) and (((VisGoodRatings == 1) and (VisGoodVotes == 1) and (VisBadDate == 1) and (VisBadGenre == 1) and (VisBadGroup == 1) and (VisGoodLang == 1) and (VisGoodCountry == 1) and (VisGoodSize == 1)) or (VisGoodMovie == 1)):
- msgid=node.getElementsByTagName("link")[0].childNodes[0].data
- download(msgid)
- else:
- print("")
- print("Status: Skipping Movie.....")
- print("IMDB Movie Title: " + imdb_movie_title + " (" + imdb_link + ")")
- print("Release Movie Title: " + movie_title)
- except:
- print("Error: Filter Value Check Error")
- main_logger.error("Filter Value Check Error")
- traceback.print_exc(file=open(tracelog,"a"))
- os.system(notifylog)
- #############
- # Debugging #
- #############
- if (VisGoodMovie == 1):
- print("Debug: Movie In Ignore Filters List")
- if (VisGoodRatings == 0):
- print("Debug: Rating < 6.5")
- if (VisGoodVotes == 0):
- print("Debug: Votes < 5,000")
- if (VisDownloaded == 0):
- print("Debug: Movie Exists In Downloaded Folder")
- if (VisInNZB == 0):
- print("Debug: NZB Exists In NZB Folder")
- if (VisInWatched == 0):
- print("Debug: NZB Exists In Watch Folder")
- if (VisCompleted == 0):
- print("Debug: Movie Exists In Completed Folder")
- if (VisBadDate == 0):
- print("Debug: Release Date Is Before 1970")
- if (VisBadGenre == 0):
- print("Debug: Genre Is Unsuitable")
- if (VisBadGroup == 0):
- print("Debug: Bad Release Group")
- if (VisGoodLang == 0):
- print("Debug: Language Of Movie Is NOT English")
- if (VisGoodCountry == 0):
- print("Debug: Language Of Country Is NOT English")
- if (VisGoodSize == 0):
- print("Debug: Size Is Too Small/Large")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement