/checkmovie.py
Python | 1616 lines | 1217 code | 307 blank | 92 comment | 134 complexity | dfc8b2d7491dfea9fa9da97ae05910dc MD5 | raw file
Large files files are truncated, but you can click here to view the full file
- #!/usr/bin/python
- # -*- coding: iso-8859-15 -*-
- #|*************************************************************|
- #|* Crazy Beaver - Automatic NZB downloader upon IMDB filter |
- #|*************************************************************|
- #| Created by binhex |
- #| |
- #| Modified by Gotcha007 - 2011 |
- #|*************************************************************|
- #|*************************************************************|
- import urllib
- import httplib
- import xml.dom.minidom
- import re
- import time
- import os
- import traceback
- import logging
- import socket
- import fileinput
- import subprocess
- import string
- import htmlentitydefs
- import mechanize
- import StringIO
- import sys
- import json
- import smtplib
- import email.generator
- import email.iterators
- import email.mime.multipart
- import email.mime.text
- import datetime
- import sqlite3 as sqlite
- import urllib
- from threading import Thread
- from configobj import ConfigObj
-
- config = ConfigObj('./config.ini')
- execfile("./config.ini")
-
- class CheckMovie(Thread):
- def __init__(self, bind):
-
- self.bind = bind
- Thread.__init__(self)
-
-
- def run(self):
-
- IndexSite = self.bind.Server
- now = datetime.datetime.now()
- self.wait = 0
-
- #location of error and output logs
- errorlog = "./crazybeaver_error.log"
- warninglog = "./crazybeaver_warning.log"
- consolelog = "./crazybeaver_console.log"
-
- #check to see if logging to console or file
- if ConsoleLogToFile == "yes":
-
- #create console log to file
- consolelogfile=file(consolelog,"a")
- consolelogfile.write("" + "\n")
- consolelogfile.write(time.strftime("Script Run On " + "%d" + "/" + "%m" + "/" + "%Y" + " " + "%H" + ":" + "%M" + ":" + "%S" + "\n"))
- consolelogfile.write("" + "\n")
- consolelogfile.close()
- #sys.stdout = consolelogfile
-
- def error_logging(message_text):
-
- #create error log to file
- #print("Debug: Error " + message_text)
- errorlogfile=file(errorlog,"a")
- errorlogfile.write("" + "\n")
- errorlogfile.write(time.strftime("Script Run On " + "%d" + "/" + "%m" + "/" + "%Y" + " " + "%H" + ":" + "%M" + ":" + "%S" + "\n"))
- errorlogfile.write("" + "\n")
- errorlogfile.write("Debug: Error " + message_text + "\n")
- errorlogfile.close()
- #traceback.print_exc(file=open(errorlog,"a"))
- #os.system(notifylog)
-
- def console_logging(message_text):
-
- #create Console log to file
- consolelogfile=file(consolelog,"a")
- consolelogfile.write("" + "\n")
- consolelogfile.write(message_text + "\n")
- consolelogfile.close()
-
-
- def warning_logging(message_text):
-
- #create warning log to file
- warninglogfile=file(warninglog,"a")
- warninglogfile.write("" + "\n")
- warninglogfile.write(time.strftime("Script Run On " + "%d" + "/" + "%m" + "/" + "%Y" + " " + "%H" + ":" + "%M" + ":" + "%S" + "\n"))
- warninglogfile.write("" + "\n")
- warninglogfile.write("Debug: Warning " + message_text + "\n")
- warninglogfile.close()
-
- #sets timeout period for urlretrieve (in seconds)
- socket.setdefaulttimeout(240)
-
- #execute the code and pipe the result to a string
- if IndexSite == "nzbmatrix":
- self.bind.bar.SetStatusText("Testing nzbmatrix.com connection",1)
- pingtest = "ping nzbmatrix.com"
- else:
- if IndexSite == "nzbs":
- self.bind.bar.SetStatusText("Testing nzbs.org connection",1)
- pingtest = "ping nzbs.org"
- else:
- self.bind.bar.SetStatusText("Testing nzb.su connection",1)
- pingtest = "ping nzb.su"
- process = subprocess.Popen(pingtest, shell=True, stdout=subprocess.PIPE)
-
- #wait for ping process to complete
- process.wait()
-
- #check return code
- if process.returncode == 0:
-
- ##########################
- # html entity conversion #
- ##########################
-
- try:
- def decode_htmlentities(text):
-
- def fixup(m):
-
- text = m.group(0)
-
- if text[:2] == "&#":
-
- try:
- #hex character reference
- if text[:3] == "&#x":
-
- return unichr(int(text[3:-1], 16))
-
- else:
-
- return unichr(int(text[2:-1]))
-
- except ValueError:
-
- pass
-
- else:
-
- #named character reference
- try:
-
- text = unichr(htmlentitydefs.name2codepoint[text[1:-1]])
-
- except KeyError:
-
- pass
-
- #no match found leave text
- return text
-
- return re.sub("&#?\w+;", fixup, text)
-
- except:
-
- error_logging("HTML Entities Conversion Function")
-
- ##############
- # 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 isInQueued(check_queued_folder):
-
- #this is set to download only if the nzb file doesn't exist in the queue folder (queue_dir)
- if os.path.exists(queue_dir + check_queued_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 isHDDownloaded(check_hd_downloaded_folder):
-
- if EnableDownloaded == "yes":
-
- #this is set to download movies which DO NOT exist (already downloaded)
- hddirnum = 1
-
- check_hd_path = (eval("movies_downloaded_dir" + str(hddirnum)) + check_hd_downloaded_folder)
-
- while check_hd_path is not None:
-
- try:
-
- check_hd_path = (eval("movies_downloaded_dir" + str(hddirnum)) + check_hd_downloaded_folder)
-
- if os.path.exists(check_hd_path):
-
- exitcode = 0
- break
-
- else:
-
- exitcode = 1
- hddirnum = hddirnum + 1
-
- except:
-
- check_hd_path = None
-
- #check exitcode (cannot use "return" as gives incorrect value)
- if exitcode == 0:
-
- return 0
-
- else:
-
- return 1
-
- else:
-
- return 1
-
- def isSDDownloaded(check_sd_downloaded_folder):
-
- if EnableReplace == "yes":
-
- #this is set to download movies which DO exist (will be replaced)
- sddirnum = 1
-
- check_sd_path = (eval("movies_to_replace_dir" + str(sddirnum)) + check_sd_downloaded_folder)
-
- while check_sd_path is not None:
-
- try:
-
- check_sd_path = (eval("movies_to_replace_dir" + str(sddirnum)) + check_sd_downloaded_folder)
-
- if os.path.exists(check_sd_path):
-
- exitcode = 1
- break
-
- else:
-
- exitcode = 0
- sddirnum = sddirnum + 1
-
- except:
-
- check_sd_path = None
-
- #check exitcode (cannot use "return" as gives incorrect value)
- if exitcode == 0:
-
- return 0
-
- else:
-
- return 1
-
- else:
-
- return 0
-
- except:
-
- error_logging("OS Filter Function")
-
- #####################
- # nzbmatrix filters #
- #####################
-
- if IndexSite == "nzbmatrix":
-
- try:
-
- def isBadReport(bad_report_id):
-
- #this will not download any reports that match the blacklist
- if re.compile(nzbmatrix_badreport, re.IGNORECASE).match(bad_report_id):
-
- return 0
-
- else:
-
- return 1
-
- except:
-
- error_logging("NZBMatrix Filter Function")
-
- ################
- # nzbs filters #
- ################
-
- if IndexSite == "nzbs":
-
- try:
-
- def isBadReport(bad_report_id):
-
- #this will not download any reports that match the blacklist
- if re.compile(nzbs_rss_badreport, re.IGNORECASE).match(bad_report_id):
-
- return 0
-
- else:
-
- return 1
-
- def isGoodSize(good_report_size):
-
- if nzbs_rss_maxsize > 0:
-
- #this will only download reports which are less than or equal to minsize and greater than or equal to maxsize
- if nzbs_rss_minsize <= good_report_size and nzbs_rss_maxsize >= good_report_size:
-
- return 1
-
- else:
-
- return 0
-
- else:
- #this will only download reports which are less than or equal to minsize
- if nzbs_rss_minsize <= good_report_size:
-
- return 1
-
- else:
-
- return 0
-
- except:
-
- error_logging("NZBs Filter Function")
- #################
- # nzbsu filters #
- #################
- if IndexSite == "nzbsu":
- try:
- def isBadReport(bad_report_id):
-
- #this will not download any reports that match the blacklist
- if re.compile(eval(IndexSite + "_badreport"), re.IGNORECASE).match(bad_report_id):
-
- return 0
-
- else:
-
- return 1
-
- def isGoodSize(good_report_size):
-
- if eval(IndexSite + "_maxsize") > 0:
-
- #this will only download reports which are less than or equal to minsize and greater than or equal to maxsize
- if eval(IndexSite + "_minsize") <= good_report_size and eval(IndexSite + "_maxsize") >= good_report_size:
-
- return 1
-
- else:
-
- return 0
-
- else:
- #this will only download reports which are less than or equal to minsize
- if eval(IndexSite + "_minsize") <= good_report_size:
-
- return 1
-
- else:
-
- return 0
- except:
- error_logging("NZBsu Filter Function")
-
- ################
- # imdb filters #
- ################
-
- try:
- def isGoodRatings(check_good_ratings):
-
- #this is set to download movies if preferred genre matches and movie rating is greater than preferred rating
- if EnablePreferred == "yes" and isPreferredGenre(imdb_movie_genres_str) == 1:
-
- if check_good_ratings is not None:
-
- GoodGeneralRatingsfloat = float(GoodGeneralRatings)
- GoodPreferredRatingsfloat = float(GoodPreferredRatings)
-
- GoodGeneralRatingsfloat = GoodPreferredRatingsfloat
-
- if check_good_ratings >= GoodGeneralRatingsfloat:
-
- return 1
-
- else:
-
- return 0
-
- else:
-
- #this is set to download movies if movie rating is greater than good general rating
- if check_good_ratings is not None:
-
- GoodGeneralRatingsfloat = float(GoodGeneralRatings)
- GoodPreferredRatingsfloat = float(GoodPreferredRatings)
-
- if check_good_ratings >= GoodGeneralRatingsfloat:
-
- return 1
-
- else:
-
- return 0
-
- def isGoodVotes(check_good_votes):
-
- #this is set to download movies with minimum defined vote count
- if check_good_votes is not None:
-
- if check_good_votes >= GoodVotes:
-
- return 1
-
- else:
-
- return 0
-
- def isGoodDate(check_good_date):
-
- #this is set to download movies with a minimum defined year
- if check_good_date is not None:
-
- if check_good_date >= GoodDate:
-
- return 1
-
- else:
-
- return 0
-
- def isGoodGenre(check_good_genre):
-
- #this is set to download only movies that match defined genre's
- if re.compile(GoodGenre, re.IGNORECASE).search(check_good_genre):
-
- return 1
-
- else:
-
- return 0
-
- if EnableFavorites == "yes":
-
- def isFavDir(check_fav_director):
-
- #this is set to ignore imdb filters for movies with defined directors
- if re.compile(FavDir, re.IGNORECASE).search(check_fav_director):
-
- return 1
-
- else:
-
- return 0
-
- def isFavActor(check_fav_actor):
-
- #this is set to ignore imdb filters for movies with defined actors
- if re.compile(FavActor, re.IGNORECASE).search(check_fav_actor):
-
- return 1
-
- else:
-
- return 0
-
- def isFavChar(check_fav_char):
-
- #this is set to ignore imdb filters for movies with defined characters
- if re.compile(FavChar, re.IGNORECASE).search(check_fav_char):
-
- return 1
-
- else:
-
- return 0
-
- def isFavTitle(check_fav_title):
-
- #this is set to ignore imdb filters for movies with defined good titles
- if re.compile(FavTitle, re.IGNORECASE).search(check_fav_title):
-
- return 1
-
- else:
-
- return 0
-
- else:
-
- def isFavDir(check_fav_director):
-
- return 0
-
- def isFavActor(check_fav_actor):
-
- return 0
-
- def isFavChar(check_fav_char):
-
- return 0
-
- def isFavTitle(check_fav_title):
-
- return 0
-
- def isBadTitle(check_bad_title):
-
- #this is set to ignore imdb filters for movies with defined bad titles
- if re.compile(BadTitle, re.IGNORECASE).search(check_bad_title):
-
- return 0
-
- else:
-
- return 1
-
- def isBadGenre(check_bad_genre):
-
- #this is set to download only movies that DO NOT match defined genre's
- if re.compile(BadGenre, re.IGNORECASE).search(check_bad_genre):
-
- return 0
-
- else:
-
- return 1
-
- if EnablePreferred == "yes":
-
- def isPreferredGenre(check_pref_genre):
-
- #this is set to download only movies that match defined genre's
- if check_pref_genre is not None:
-
- if re.compile(GoodPreferredGenre, re.IGNORECASE).search(check_pref_genre):
-
- return 1
-
- else:
-
- return 0
-
- if EnableQueuing == "yes":
-
- def isQueueDate(check_queue_date):
-
- #this is set to queue movies with a maximum defined year (min is GoodDate)
- if check_queue_date is not None:
-
- if check_queue_date <= QueueDate:
-
- return 1
-
- else:
-
- return 0
-
- def isQueueGenre(check_queue_genre):
-
- #this is set to queue movies with defined genre's
- if re.compile(QueueGenre, re.IGNORECASE).search(check_queue_genre):
-
- return 1
-
- else:
-
- return 0
-
- except:
-
- error_logging("IMDB Filter Function")
-
- ########################
- # IMDB Movie Variables #
- ########################
-
- def IMDBVarMod():
-
- try:
-
- global imdb_movie_title
- global imdb_movie_year
- global imdb_movie_year_str
- global imdb_movie_description
- global imdb_movie_runtime
- global imdb_movie_runtime_str
- global imdb_movie_rating
- global imdb_movie_rating_str
- global imdb_movie_votes
- global imdb_movie_genres
- global imdb_movie_genres_str
- global imdb_movie_directors
- global imdb_movie_directors_str
- global imdb_movie_cast_members
- global imdb_movie_cast_members_str
-
- #imdb movie title
- imdb_json_title = imdb_json_page["data"]["title"]
- imdb_movie_title = decode_htmlentities(imdb_json_title)
- imdb_movie_title = imdb_movie_title.encode("utf-8")
-
- #remove/replace illegal characters from imdb title (used for nzb filename)
- imdb_movie_title = re.sub("\.","" ,imdb_movie_title)
- imdb_movie_title = re.sub("\:","" ,imdb_movie_title)
- imdb_movie_title = re.sub("\"","" ,imdb_movie_title)
- imdb_movie_title = re.sub("\*","" ,imdb_movie_title)
- imdb_movie_title = re.sub("\"","" ,imdb_movie_title)
- imdb_movie_title = re.sub("/"," " ,imdb_movie_title)
- imdb_movie_title = re.sub("\\\\"," " ,imdb_movie_title)
- imdb_movie_title = re.sub("\?","" ,imdb_movie_title)
- imdb_movie_title = re.sub("\|","" ,imdb_movie_title)
- imdb_movie_title = re.sub("\<","" ,imdb_movie_title)
- imdb_movie_title = re.sub("\>","" ,imdb_movie_title)
-
- #replace roman numerals to numerics - e.g. "the movie IX" converts to "the movie 9"
- imdb_movie_title = re.sub("(?<![a-zA-Z0-9_])IX(?![a-zA-Z0-9_])","9", imdb_movie_title, re.I)
-
- #replace roman numerals to numerics - e.g. "the movie VIII" converts to "the movie 8"
- imdb_movie_title = re.sub("(?<![a-zA-Z0-9_])VIII(?![a-zA-Z0-9_])","8", imdb_movie_title, re.I)
-
- #replace roman numerals to numerics - e.g. "the movie VII" converts to "the movie 7"
- imdb_movie_title = re.sub("(?<![a-zA-Z0-9_])VII(?![a-zA-Z0-9_])","7", imdb_movie_title, re.I)
-
- #replace roman numerals to numerics - e.g. "the movie VI" converts to "the movie 6"
- imdb_movie_title = re.sub("(?<![a-zA-Z0-9_])VI(?![a-zA-Z0-9_])","6", imdb_movie_title, re.I)
-
- #replace roman numerals to numerics - e.g. "the movie V" converts to "the movie 5"
- imdb_movie_title = re.sub("(?<![a-zA-Z0-9_])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("(?<![a-zA-Z0-9_])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("(?<![a-zA-Z0-9_])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("(?<![a-zA-Z0-9_])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 = string.capwords(imdb_movie_title)
-
- #imdb movie release date
- imdb_movie_year = imdb_json_page["data"]["year"]
- imdb_movie_year = int(imdb_movie_year)
- imdb_movie_year_str = str(imdb_movie_year)
-
- #imdb movie runtime
- try:
-
- imdb_movie_runtime = imdb_json_page["data"]["runtime"]["time"]
- imdb_movie_runtime = int(imdb_movie_runtime) / 60
- imdb_movie_runtime_str = str(imdb_movie_runtime)
-
- except:
-
- imdb_movie_runtime = 1
- imdb_movie_runtime_str = str(imdb_movie_runtime)
-
- #imdb movie rating
- try:
- imdb_movie_rating = imdb_json_page["data"]["rating"]
- imdb_movie_rating = float(imdb_movie_rating)
- imdb_movie_rating_str = str(imdb_movie_rating)
-
- except:
-
- imdb_movie_rating = 1.0
- imdb_movie_rating_str = str(imdb_movie_rating)
-
- #imdb movie votes
- try:
-
- imdb_movie_votes = imdb_json_page["data"]["num_votes"]
- imdb_movie_votes = int(imdb_movie_votes)
-
- except:
-
- imdb_movie_votes = 1
-
- #imdb movie director
- try:
-
- imdb_movie_directors = imdb_json_page["data"]["directors_summary"]
- imdb_movie_directors_str = str(imdb_movie_directors)
- imdb_movie_directors_str = decode_htmlentities(imdb_movie_directors_str)
- imdb_movie_directors_str = imdb_movie_directors_str.encode("utf-8")
-
- except:
-
- imdb_movie_directors = "Unknown"
- imdb_movie_directors_str = "Unknown"
-
- #imdb movie cast
- try:
-
- imdb_movie_cast_members = imdb_json_page["data"]["cast_summary"]
- imdb_movie_cast_members_str = str(imdb_movie_cast_members)
- imdb_movie_cast_members_str = decode_htmlentities(imdb_movie_cast_members_str)
- imdb_movie_cast_members_str = imdb_movie_cast_members_str.encode("utf-8")
-
- except:
-
- imdb_movie_cast_members = "Unknown"
- imdb_movie_cast_members_str = "Unknown"
-
- #imdb movie description
- try:
-
- imdb_movie_description = imdb_json_page["data"]["plot"]["outline"]
- imdb_movie_description = decode_htmlentities(imdb_movie_description)
- imdb_movie_description = imdb_movie_description.encode("utf-8")
-
- except:
-
- imdb_movie_description = "Unknown"
-
- #imdb movie genres
- try:
-
- imdb_movie_genres = imdb_json_page["data"]["genres"]
- imdb_movie_genres_str = str(imdb_movie_genres)
-
- except:
-
- imdb_movie_genres = "Unknown"
- imdb_movie_genres_str = "Unknown"
-
- return "OK"
- except:
-
- error_logging("IMDB Movie Variables Function")
- return "Error"
-
-
- #######################
- # create mymovies.xml #
- #######################
-
- def MetaData():
-
- try:
-
- if EnableMetadata == "yes":
- self.bind.bar.SetStatusText("Writing Informations to MetaData File",1)
- #create mymovies.xml file
- mymoviesfile=file(metadata_dir + "\\" + imdb_movie_title + " mymovies.xml","w")
- mymoviesfile.write("<Title>" + "\n")
-
- #write imdb movie title
- mymoviesfile.write(" <LocalTitle>" + imdb_movie_title + "</LocalTitle>" + "\n")
- mymoviesfile.write(" <OriginalTitle>" + imdb_movie_title + "</OriginalTitle>" + "\n")
- mymoviesfile.write(" <SortTitle>" + imdb_movie_title + "</SortTitle>" + "\n")
-
- #write date and time
- mymoviesfile.write(time.strftime(" <Added>" + "%d" + "/" + "%m" + "/" + "%Y" + " " + "%H" + ":" + "%M" + ":" + "%S" + "</Added>" + "\n"))
-
- #write movie release year
- mymoviesfile.write(" <ProductionYear>" + imdb_movie_year_str + "</ProductionYear>" + "\n")
-
- #write running time
- mymoviesfile.write(" <RunningTime>" + imdb_movie_runtime_str + "</RunningTime>" + "\n")
-
- #write imdb rating
- mymoviesfile.write(" <IMDBrating>" + imdb_movie_rating_str + "</IMDBrating>" + "\n")
-
- #write description
- mymoviesfile.write(" <Description>" + imdb_movie_description + "</Description>" + "\n")
-
- #write static cover image links
- mymoviesfile.write(" <Covers>" + "\n")
- mymoviesfile.write(" <Front>folder.jpg</Front>" + "\n")
- mymoviesfile.write(" <Back />" + "\n")
- mymoviesfile.write(" </Covers>" + "\n")
-
- #write genres
- mymoviesfile.write(" <Genres>" + "\n")
-
- for imdb_movie_genre in imdb_movie_genres:
-
- mymoviesfile.write(" <Genre>" + imdb_movie_genre + "</Genre>" + "\n")
-
- mymoviesfile.write(" </Genres>" + "\n")
-
- #write directors name
- mymoviesfile.write(" <Persons>" + "\n")
-
- for imdb_movie_director in imdb_movie_directors:
-
- mymoviesfile.write(" <Person>" + "\n")
- imdb_movie_director_name = imdb_movie_director["name"]["name"]
- imdb_movie_director_name = decode_htmlentities(imdb_movie_director_name)
- imdb_movie_director_name = imdb_movie_director_name.encode("utf-8")
-
- mymoviesfile.write(" <Name>" + imdb_movie_director_name + "</Name>" + "\n")
- mymoviesfile.write(" <Type>Director</Type>" + "\n")
- mymoviesfile.write(" </Person>" + "\n")
-
- #write actor and character names
- for imdb_movie_cast_member in imdb_movie_cast_members:
-
- imdb_movie_actor = imdb_movie_cast_member["name"]["name"]
- imdb_movie_actor = decode_htmlentities(imdb_movie_actor)
- imdb_movie_actor = imdb_movie_actor.encode("utf-8")
-
- imdb_movie_character = imdb_movie_cast_member["char"]
- imdb_movie_character = decode_htmlentities(imdb_movie_character)
- imdb_movie_character = imdb_movie_character.encode("utf-8")
-
- mymoviesfile.write(" <Person>" + "\n")
- mymoviesfile.write(" <Name>" + imdb_movie_actor + "</Name>" + "\n")
- mymoviesfile.write(" <Type>Actor</Type>" + "\n")
- mymoviesfile.write(" <Role>" + imdb_movie_character + "</Role>" + "\n")
- mymoviesfile.write(" </Person>" + "\n")
-
- mymoviesfile.write(" </Persons>" + "\n")
-
- #write end tag and close file
- mymoviesfile.write("</Title>" + "\n")
- mymoviesfile.close()
-
- except:
-
- error_logging("MyMovies Creation Function")
-
-
- ####################
- # download trailer #
- ####################
-
- def Trailer():
-
- try:
-
- global PreferredTrailerSize
- global AlternativeTrailerSize
-
- if EnableTrailerDownloads == "yes":
-
- #change friendly names to actual resolutions for preferred size
- if PreferredTrailerSize == "high":
-
- PreferredTrailerSize = "HD 720p"
-
- elif PreferredTrailerSize == "med":
-
- PreferredTrailerSize = "HD 480p"
-
- elif PreferredTrailerSize == "low":
-
- PreferredTrailerSize = "H.264 480x320"
-
- #change friendly names to actual resolutions for alternative size
- if AlternativeTrailerSize == "high":
-
- AlternativeTrailerSize = "HD 720p"
-
- elif AlternativeTrailerSize == "med":
-
- AlternativeTrailerSize = "HD 480p"
-
- elif AlternativeTrailerSize == "low":
-
- AlternativeTrailerSize = "H.264 480x320"
-
- #generate imdb movie trailer url from json feed
- try:
-
- imdb_trailer_url = imdb_json_page["data"]["trailer"]["encodings"][PreferredTrailerSize]["url"]
-
- except:
-
- try:
-
- imdb_trailer_url = imdb_json_page["data"]["trailer"]["encodings"][AlternativeTrailerSize]["url"]
-
- except:
-
- imdb_trailer_url = None
- warning_logging("Trailer No Match")
- self.wait = 1
-
- #save trailer file in trailer folder
- if imdb_trailer_url is not None:
- if ConsoleLogToFile == "yes" :
- console_logging("------------------------------\nStatus: Downloading Trailer.....\nTitle: " + nzbmatrix_movietitle)
-
- self.bind.bar.SetStatusText("Downloading Trailer for " + imdb_movie_title + "...",1)
- urllib.urlretrieve(imdb_trailer_url, trailer_dir + imdb_movie_title + " Trailer" + ".mp4")
-
- except:
-
- error_logging("Trailer Download Function")
-
- ######################
- # nzbmatrix download #
- ######################
-
- def NZBMatrixDownload():
-
- try:
-
- global EmailDownloadStatus
-
- self.bind.bar.SetStatusText("Downloading Movie " + nzbmatrix_movietitle,1)
- if ConsoleLogToFile == "yes" :
- console_logging("------------------------------\nStatus: Downloading Movie.....\nTitle: " + nzbmatrix_movietitle)
-
- if EnableQueuing == "yes":
-
- #this will copy nzb to queued folder if queue date and queue votes are greater than defined values and not queue genres
- if (isQueueDate(imdb_movie_year) == 1 or isQueueGenre(imdb_movie_genres_str) == 1):
-
- NZBDownloadRetryCount = 0
- while NZBDownloadRetryCount < 5:
-
- #sleep and retry to download nzb from nzbmatrix 5 times with 30 sec gap
- try:
-
- #save nzb file in queued folder
-
- browser.retrieve(nzbmatrix_download_link, queue_dir + imdb_movie_title + ".nzb")
- EmailDownloadStatus = "Queued"
-
- break
-
- except:
-
- NZBDownloadRetryCount += 1
- time.sleep(30)
-
- else:
-
- warning_logging("Nzbmatrix Download Failed")
- self.wait = 1
- #os._exit(1)
-
- else:
-
- NZBDownloadRetryCount = 0
- while NZBDownloadRetryCount < 5:
-
- #sleep and retry to download nzb from nzbmatrix 5 times with 30 sec gap
- try:
- if ConsoleLogToFile == "yes" :
- console_logging("try : " + NZBDownloadRetryCount)
-
- #save nzb file in watched folder
-
- browser2 = mechanize.Browser()
- browser2.retrieve(nzbmatrix_download_link, watch_dir + imdb_movie_title + ".nzb")
- EmailDownloadStatus = "Downloading"
-
- if growl_notification == "yes":
- TheCommand = 'growlnotify.exe "Auto Download ' + nzbmatrix_movietitle + '"'
- os.system(TheCommand)
-
- if prowl_notification == "yes":
- urllib.urlopen("https://prowl.weks.net/publicapi/add?apikey=" + prowl_api + "&priority=" + prowl_priority + "&application=CrazyBeaver&event=" + now.strftime("%Y-%m-%d %H:%M") + "&description=Auto Download " + nzbmatrix_movietitle).close()
-
- if xbmc_notification == "yes":
- urllib.urlopen("http://" + xbmc_server + ":" + xbmc_port + "/xbmcCmds/xbmcHttp?command=ExecBuiltIn(Notification(Crazy Beaver,%20Downloading " + nzbmatrix_movietitle + "))").close()
-
- c.execute("insert into Movie values ('" + nzbmatrix_movietitle + "','" + now.strftime("%Y-%m-%d %H:%M") + "','" + nzbmatrix_postid + "','" + imdb_movie_title + "','" + nzbmatrix_imdb_tt_number + "','Movie Downloaded','" + eval(IndexSite + """_imdb_link_full""") + "','yes','nzbmatrix','yes')")
- conn.commit()
-
- break
-
- except:
-
- NZBDownloadRetryCount += 1
- time.sleep(30)
-
- else:
-
- warning_logging("Nzbmatrix Download Failed")
- self.wait = 1
- #os._exit(1)
-
- else:
-
- NZBDownloadRetryCount = 0
- while NZBDownloadRetryCount < 5:
-
- #sleep and retry to download nzb from nzbmatrix 5 times with 30 sec gap
- try:
-
- #save nzb file in watched folder
- #login to nzbmatrix using mechanize
- browser2 = mechanize.Browser()
- browser2.addheaders = [('User-agent', "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)")]
-
- #this attempts to open the login page for nzbmatrix
- OpenLoginRetryCount = 0
- while OpenLoginRetryCount < 5:
-
- #sleep and retry to read the login page for nzbmatrix 5 times with 30 sec gap
- try:
- browser2.open(nzbmatrix_login_url)
- break
-
- except:
-
- OpenLoginRetryCount += 1
- time.sleep(30)
-
- else:
-
- warning_logging("Nzbmatrix Login Down")
- self.wait = 1
- #os._exit(1)
-
- browser2.select_form(nr=0)
- browser2['username'] = nzbmatrix_username
- browser2['password'] = nzbmatrix_password
- browser2.submit()
-
- browser2.retrieve(nzbmatrix_download_link, watch_dir + imdb_movie_title + ".nzb")
- EmailDownloadStatus = "Downloading"
-
- break
-
- except:
-
- NZBDownloadRetryCount += 1
- time.sleep(30)
-
- else:
-
- warning_logging("Nzbmatrix Download Failed")
- self.wait = 1
- #os._exit(1)
-
- if growl_notification == "yes":
- TheCommand = 'growlnotify.exe "Auto Download ' + nzbmatrix_movietitle + '"'
- os.system(TheCommand)
-
- if prowl_notification == "yes":
- urllib.urlopen("https://prowl.weks.net/publicapi/add?apikey=" + prowl_api + "&priority=" + prowl_priority + "&application=CrazyBeaver&event=" + now.strftime("%Y-%m-%d %H:%M") + "&description=Auto Download " + nzbmatrix_movietitle).close()
-
- if xbmc_notification == "yes":
- urllib.urlopen("http://" + xbmc_server + ":" + xbmc_port + "/xbmcCmds/xbmcHttp?command=ExecBuiltIn(Notification(Crazy Beaver,%20Downloading " + nzbmatrix_movietitle + "))").close()
-
- except:
-
- error_logging("NZBMatrix Download Function")
-
- #################
- # nzbs download #
- #################
-
- def NZBsDownload():
-
- try:
-
- global EmailDownloadStatus
- self.bind.bar.SetStatusText("Downloading Movie " + nzbs_movietitle,1)
- if ConsoleLogToFile == "yes" :
- console_logging("------------------------------\nStatus: Downloading Movie.....\nTitle: " + nzbs_movietitle)
-
-
- if EnableQueuing == "yes":
-
- #this will copy nzb to queued folder if queue date and queue votes are greater than defined values and not queue genres
- if (isQueueDate(imdb_movie_year) == 1 or isQueueGenre(imdb_movie_genres_str) == 1):
-
- NZBDownloadRetryCount = 0
- while NZBDownloadRetryCount < 5:
-
- #sleep and retry to download nzb from nzbs 5 times with 30 sec gap
- try:
-
- #save nzb file in queued folder
- urllib.urlretrieve(nzbs_directdl, queue_dir + imdb_movie_title + ".nzb")
- EmailDownloadStatus = "Queued"
-
- break
-
- except:
-
- NZBDownloadRetryCount += 1
- time.sleep(30)
-
- else:
- self.bind.bar.SetStatusText("Nzbs Download Failed",1)
-
- warning_logging("Nzbs Download Failed")
- self.wait = 1
- #os._exit(1)
-
- else:
-
- NZBDownloadRetryCount = 0
- while NZBDownloadRetryCount < 5:
-
- #sleep and retry to download nzb from nzbs 5 times with 30 sec gap
- try:
-
- #save nzb file in watched folder
- urllib.urlretrieve(nzbs_directdl, watch_dir + imdb_movie_title + ".nzb")
- EmailDownloadStatus = "Downloading"
- if growl_notification == "yes":
- TheCommand = 'growlnotify.exe "Auto Download ' + nzbs_movietitle + '"'
- os.system(TheCommand)
-
- if prowl_notification == "yes":
- urllib.urlopen("https://prowl.weks.net/publicapi/add?apikey=" + prowl_api + "&priority=" + prowl_priority + "&application=CrazyBeaver&event=" + now.strftime("%Y-%m-%d %H:%M") + "&description=Auto Download " + nzbs_movietitle).close()
-
- if xbmc_notification == "yes":
- urllib.urlopen("http://" + xbmc_server + ":" + xbmc_port + "/xbmcCmds/xbmcHttp?command=ExecBuiltIn(Notification(Crazy Beaver,%20Downloading " + nzbs_movietitle + "))").close()
- break
-
- except:
-
- NZBDownloadRetryCount += 1
- time.sleep(30)
-
- else:
- self.bind.bar.SetStatusText("Nzbs Download Failed",1)
- warning_logging("Nzbs Download Failed")
- self.wait = 1
-
- else:
-
-
- NZBDownloadRetryCount = 0
- while NZBDownloadRetryCount < 5:
-
- #sleep and retry to download nzb from nzbmatrix 5 times with 30 sec gap
- try:
-
- #save nzb file in watched folder
- urllib.urlretrieve(nzbs_directdl, watch_dir + imdb_movie_title + ".nzb")
- EmailDownloadStatus = "Downloading"
- if growl_notification == "yes":
- TheCommand = 'growlnotify.exe "Auto Download ' + nzbs_movietitle + '"'
- os.system(TheCommand)
-
- if prowl_notification == "yes":
- urllib.urlopen("https://prowl.weks.net/publicapi/add?apikey=" + prowl_api + "&priority=" + prowl_priority + "&application=CrazyBeaver&event=" + now.strftime("%Y-%m-%d %H:%M") + "&description=Auto Download " + nzbs_movietitle).close()
-
- if xbmc_notification == "yes":
- urllib.urlopen("http://" + xbmc_server + ":" + xbmc_port + "/xbmcCmds/xbmcHttp?command=ExecBuiltIn(Notification(Crazy Beaver,%20Downloading " + nzbs_movietitle + "))").close()
-
- break
-
- except:
-
- NZBDownloadRetryCount += 1
- time.sleep(30)
-
- else:
- self.bind.bar.SetStatusText("Nzbs Download Failed",1)
- warning_logging("Nzbs Download Failed")
- self.wait = 1
-
- except:
- self.bind.bar.SetStatusText("NZBs Download Function",1)
- error_logging("NZBs Download Function")
-
- ################
- # nzb download #
- ################
-
- def NZBDownload(nzbsu_guid):
-
- try:
-
- global EmailDownloadStatus
- self.bind.bar.SetStatusText("Downloading Movie",1)
- if ConsoleLogToFile == "yes" :
- console_logging("------------------------------\nStatus: Downloading Movie.....\nTitle: " + imdb_movie_title)
-
-
- if EnableQueuing == "yes":
-
- #this will copy nzb to queued folder if queue date and queue votes are greater than defined values and not queue genres
- if (isQueueDate(imdb_movie_year) == 1 or isQueueGenre(imdb_movie_genres_str) == 1):
-
- NZBDownloadRetryCount = 0
- while NZBDownloadRetryCount < 5:
-
- #sleep and retry to download nzb 5 times with 30 sec gap
- try:
-
- #save nzb file in queued folder
- nzbsu_download_link = "http://www.nzb.su/api?t=get&id=" + nzbsu_guid + "&apikey=" + nzbsu_key
- browser.retrieve(eval(IndexSite + "_download_link"), queue_dir + imdb_movie_title + ".nzb")
- EmailDownloadStatus = "Queued"
- break
-
- except:
-
- NZBDownloadRetryCount += 1
- time.sleep(30)
-
- else:
- self.bind.bar.SetStatusText(IndexSite + " Download Failed For Movie " + imdb_movie_title,1)
- warning_logging(IndexSite + " Download Failed For Movie " + imdb_movie_title)
- self.wait = 1
- if ConsoleLogToFile == "yes" :
- console_logging("---------------------------\n" + IndexSite + " Download Failed")
- #os._exit(1)
-
- else:
-
- NZBDownloadRetryCount = 0
- while NZBDownloadRetryCount < 5:
-
- #sleep and retry to download nzb 5 times with 30 sec gap
- try:
- #save nzb file in watched folder
- nzbsu_download_link = "http://www.nzb.su/api?t=get&id=" + nzbsu_guid + "&apikey=" + nzbsu_key
- browser.retrieve(eval(IndexSite + "_download_link"), watch_dir + imdb_movie_title + ".nzb")
- EmailDownloadStatus = "Downloading"
- if growl_notification == "yes":
- TheCommand = 'growlnotify.exe "Auto Download ' + imdb_movie_title + '"'
- os.system(TheCommand)
-
- if prowl_notification == "yes":
- urllib.urlopen("https://prowl.weks.net/publicapi/add?apikey=" + prowl_api + "&priority=" + prowl_priority + "&application=CrazyBeaver&event=" + now.strftime("%Y-%m-%d %H:%M") + "&description=Auto Download " + imdb_movie_title).close()
-
- if xbmc_notification == "yes":
- urllib.urlopen("http://" + xbmc_server + ":" + xbmc_port + "/xbmcCmds/xbmcHttp?command=ExecBuiltIn(Notification(Crazy Beaver,%20Downloading " + imdb_movie_title + "))").close()
- break
-
- except:
-
- NZBDownloadRetryCount += 1
- time.sleep(30)
-
- else:
- self.bind.bar.SetStatusText(IndexSite + " Download Failed For Movie " + imdb_movie_title,1)
- warning_logging(IndexSite + " Download Failed For Movie " + imdb_movie_title)
- self.wait = 1
- if ConsoleLogToFile == "yes" :
- console_logging("---------------------------\n" + IndexSite + " Download Failed")
- #os._exit(1)
- …
Large files files are truncated, but you can click here to view the full file