PageRenderTime 53ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/checkmovie.py

http://crazy-beaver.googlecode.com/
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

  1. #!/usr/bin/python
  2. # -*- coding: iso-8859-15 -*-
  3. #|*************************************************************|
  4. #|* Crazy Beaver - Automatic NZB downloader upon IMDB filter |
  5. #|*************************************************************|
  6. #| Created by binhex |
  7. #| |
  8. #| Modified by Gotcha007 - 2011 |
  9. #|*************************************************************|
  10. #|*************************************************************|
  11. import urllib
  12. import httplib
  13. import xml.dom.minidom
  14. import re
  15. import time
  16. import os
  17. import traceback
  18. import logging
  19. import socket
  20. import fileinput
  21. import subprocess
  22. import string
  23. import htmlentitydefs
  24. import mechanize
  25. import StringIO
  26. import sys
  27. import json
  28. import smtplib
  29. import email.generator
  30. import email.iterators
  31. import email.mime.multipart
  32. import email.mime.text
  33. import datetime
  34. import sqlite3 as sqlite
  35. import urllib
  36. from threading import Thread
  37. from configobj import ConfigObj
  38. config = ConfigObj('./config.ini')
  39. execfile("./config.ini")
  40. class CheckMovie(Thread):
  41. def __init__(self, bind):
  42. self.bind = bind
  43. Thread.__init__(self)
  44. def run(self):
  45. IndexSite = self.bind.Server
  46. now = datetime.datetime.now()
  47. self.wait = 0
  48. #location of error and output logs
  49. errorlog = "./crazybeaver_error.log"
  50. warninglog = "./crazybeaver_warning.log"
  51. consolelog = "./crazybeaver_console.log"
  52. #check to see if logging to console or file
  53. if ConsoleLogToFile == "yes":
  54. #create console log to file
  55. consolelogfile=file(consolelog,"a")
  56. consolelogfile.write("" + "\n")
  57. consolelogfile.write(time.strftime("Script Run On " + "%d" + "/" + "%m" + "/" + "%Y" + " " + "%H" + ":" + "%M" + ":" + "%S" + "\n"))
  58. consolelogfile.write("" + "\n")
  59. consolelogfile.close()
  60. #sys.stdout = consolelogfile
  61. def error_logging(message_text):
  62. #create error log to file
  63. #print("Debug: Error " + message_text)
  64. errorlogfile=file(errorlog,"a")
  65. errorlogfile.write("" + "\n")
  66. errorlogfile.write(time.strftime("Script Run On " + "%d" + "/" + "%m" + "/" + "%Y" + " " + "%H" + ":" + "%M" + ":" + "%S" + "\n"))
  67. errorlogfile.write("" + "\n")
  68. errorlogfile.write("Debug: Error " + message_text + "\n")
  69. errorlogfile.close()
  70. #traceback.print_exc(file=open(errorlog,"a"))
  71. #os.system(notifylog)
  72. def console_logging(message_text):
  73. #create Console log to file
  74. consolelogfile=file(consolelog,"a")
  75. consolelogfile.write("" + "\n")
  76. consolelogfile.write(message_text + "\n")
  77. consolelogfile.close()
  78. def warning_logging(message_text):
  79. #create warning log to file
  80. warninglogfile=file(warninglog,"a")
  81. warninglogfile.write("" + "\n")
  82. warninglogfile.write(time.strftime("Script Run On " + "%d" + "/" + "%m" + "/" + "%Y" + " " + "%H" + ":" + "%M" + ":" + "%S" + "\n"))
  83. warninglogfile.write("" + "\n")
  84. warninglogfile.write("Debug: Warning " + message_text + "\n")
  85. warninglogfile.close()
  86. #sets timeout period for urlretrieve (in seconds)
  87. socket.setdefaulttimeout(240)
  88. #execute the code and pipe the result to a string
  89. if IndexSite == "nzbmatrix":
  90. self.bind.bar.SetStatusText("Testing nzbmatrix.com connection",1)
  91. pingtest = "ping nzbmatrix.com"
  92. else:
  93. if IndexSite == "nzbs":
  94. self.bind.bar.SetStatusText("Testing nzbs.org connection",1)
  95. pingtest = "ping nzbs.org"
  96. else:
  97. self.bind.bar.SetStatusText("Testing nzb.su connection",1)
  98. pingtest = "ping nzb.su"
  99. process = subprocess.Popen(pingtest, shell=True, stdout=subprocess.PIPE)
  100. #wait for ping process to complete
  101. process.wait()
  102. #check return code
  103. if process.returncode == 0:
  104. ##########################
  105. # html entity conversion #
  106. ##########################
  107. try:
  108. def decode_htmlentities(text):
  109. def fixup(m):
  110. text = m.group(0)
  111. if text[:2] == "&#":
  112. try:
  113. #hex character reference
  114. if text[:3] == "&#x":
  115. return unichr(int(text[3:-1], 16))
  116. else:
  117. return unichr(int(text[2:-1]))
  118. except ValueError:
  119. pass
  120. else:
  121. #named character reference
  122. try:
  123. text = unichr(htmlentitydefs.name2codepoint[text[1:-1]])
  124. except KeyError:
  125. pass
  126. #no match found leave text
  127. return text
  128. return re.sub("&#?\w+;", fixup, text)
  129. except:
  130. error_logging("HTML Entities Conversion Function")
  131. ##############
  132. # os filters #
  133. ##############
  134. try:
  135. def isInWatched(check_watched_folder):
  136. #this is set to download only if the nzb file doesn't exist in the watch folder (watch_dir)
  137. if os.path.exists(watch_dir + check_watched_folder + ".nzb"):
  138. return 0
  139. else:
  140. return 1
  141. def isInQueued(check_queued_folder):
  142. #this is set to download only if the nzb file doesn't exist in the queue folder (queue_dir)
  143. if os.path.exists(queue_dir + check_queued_folder + ".nzb"):
  144. return 0
  145. else:
  146. return 1
  147. def isInNZB(check_nzb_folder):
  148. #this is set to download only if the nzb file doesn't exist in the nzb folder (nzb_dir)
  149. if os.path.exists(nzb_dir + check_nzb_folder + ".nzb.gz"):
  150. return 0
  151. else:
  152. return 1
  153. def isCompleted(check_completed_folder):
  154. #this is set to download only if the movie doesn't exist in the completed folder (completed_dir)
  155. if os.path.exists(completed_dir + check_completed_folder):
  156. return 0
  157. else:
  158. return 1
  159. def isHDDownloaded(check_hd_downloaded_folder):
  160. if EnableDownloaded == "yes":
  161. #this is set to download movies which DO NOT exist (already downloaded)
  162. hddirnum = 1
  163. check_hd_path = (eval("movies_downloaded_dir" + str(hddirnum)) + check_hd_downloaded_folder)
  164. while check_hd_path is not None:
  165. try:
  166. check_hd_path = (eval("movies_downloaded_dir" + str(hddirnum)) + check_hd_downloaded_folder)
  167. if os.path.exists(check_hd_path):
  168. exitcode = 0
  169. break
  170. else:
  171. exitcode = 1
  172. hddirnum = hddirnum + 1
  173. except:
  174. check_hd_path = None
  175. #check exitcode (cannot use "return" as gives incorrect value)
  176. if exitcode == 0:
  177. return 0
  178. else:
  179. return 1
  180. else:
  181. return 1
  182. def isSDDownloaded(check_sd_downloaded_folder):
  183. if EnableReplace == "yes":
  184. #this is set to download movies which DO exist (will be replaced)
  185. sddirnum = 1
  186. check_sd_path = (eval("movies_to_replace_dir" + str(sddirnum)) + check_sd_downloaded_folder)
  187. while check_sd_path is not None:
  188. try:
  189. check_sd_path = (eval("movies_to_replace_dir" + str(sddirnum)) + check_sd_downloaded_folder)
  190. if os.path.exists(check_sd_path):
  191. exitcode = 1
  192. break
  193. else:
  194. exitcode = 0
  195. sddirnum = sddirnum + 1
  196. except:
  197. check_sd_path = None
  198. #check exitcode (cannot use "return" as gives incorrect value)
  199. if exitcode == 0:
  200. return 0
  201. else:
  202. return 1
  203. else:
  204. return 0
  205. except:
  206. error_logging("OS Filter Function")
  207. #####################
  208. # nzbmatrix filters #
  209. #####################
  210. if IndexSite == "nzbmatrix":
  211. try:
  212. def isBadReport(bad_report_id):
  213. #this will not download any reports that match the blacklist
  214. if re.compile(nzbmatrix_badreport, re.IGNORECASE).match(bad_report_id):
  215. return 0
  216. else:
  217. return 1
  218. except:
  219. error_logging("NZBMatrix Filter Function")
  220. ################
  221. # nzbs filters #
  222. ################
  223. if IndexSite == "nzbs":
  224. try:
  225. def isBadReport(bad_report_id):
  226. #this will not download any reports that match the blacklist
  227. if re.compile(nzbs_rss_badreport, re.IGNORECASE).match(bad_report_id):
  228. return 0
  229. else:
  230. return 1
  231. def isGoodSize(good_report_size):
  232. if nzbs_rss_maxsize > 0:
  233. #this will only download reports which are less than or equal to minsize and greater than or equal to maxsize
  234. if nzbs_rss_minsize <= good_report_size and nzbs_rss_maxsize >= good_report_size:
  235. return 1
  236. else:
  237. return 0
  238. else:
  239. #this will only download reports which are less than or equal to minsize
  240. if nzbs_rss_minsize <= good_report_size:
  241. return 1
  242. else:
  243. return 0
  244. except:
  245. error_logging("NZBs Filter Function")
  246. #################
  247. # nzbsu filters #
  248. #################
  249. if IndexSite == "nzbsu":
  250. try:
  251. def isBadReport(bad_report_id):
  252. #this will not download any reports that match the blacklist
  253. if re.compile(eval(IndexSite + "_badreport"), re.IGNORECASE).match(bad_report_id):
  254. return 0
  255. else:
  256. return 1
  257. def isGoodSize(good_report_size):
  258. if eval(IndexSite + "_maxsize") > 0:
  259. #this will only download reports which are less than or equal to minsize and greater than or equal to maxsize
  260. if eval(IndexSite + "_minsize") <= good_report_size and eval(IndexSite + "_maxsize") >= good_report_size:
  261. return 1
  262. else:
  263. return 0
  264. else:
  265. #this will only download reports which are less than or equal to minsize
  266. if eval(IndexSite + "_minsize") <= good_report_size:
  267. return 1
  268. else:
  269. return 0
  270. except:
  271. error_logging("NZBsu Filter Function")
  272. ################
  273. # imdb filters #
  274. ################
  275. try:
  276. def isGoodRatings(check_good_ratings):
  277. #this is set to download movies if preferred genre matches and movie rating is greater than preferred rating
  278. if EnablePreferred == "yes" and isPreferredGenre(imdb_movie_genres_str) == 1:
  279. if check_good_ratings is not None:
  280. GoodGeneralRatingsfloat = float(GoodGeneralRatings)
  281. GoodPreferredRatingsfloat = float(GoodPreferredRatings)
  282. GoodGeneralRatingsfloat = GoodPreferredRatingsfloat
  283. if check_good_ratings >= GoodGeneralRatingsfloat:
  284. return 1
  285. else:
  286. return 0
  287. else:
  288. #this is set to download movies if movie rating is greater than good general rating
  289. if check_good_ratings is not None:
  290. GoodGeneralRatingsfloat = float(GoodGeneralRatings)
  291. GoodPreferredRatingsfloat = float(GoodPreferredRatings)
  292. if check_good_ratings >= GoodGeneralRatingsfloat:
  293. return 1
  294. else:
  295. return 0
  296. def isGoodVotes(check_good_votes):
  297. #this is set to download movies with minimum defined vote count
  298. if check_good_votes is not None:
  299. if check_good_votes >= GoodVotes:
  300. return 1
  301. else:
  302. return 0
  303. def isGoodDate(check_good_date):
  304. #this is set to download movies with a minimum defined year
  305. if check_good_date is not None:
  306. if check_good_date >= GoodDate:
  307. return 1
  308. else:
  309. return 0
  310. def isGoodGenre(check_good_genre):
  311. #this is set to download only movies that match defined genre's
  312. if re.compile(GoodGenre, re.IGNORECASE).search(check_good_genre):
  313. return 1
  314. else:
  315. return 0
  316. if EnableFavorites == "yes":
  317. def isFavDir(check_fav_director):
  318. #this is set to ignore imdb filters for movies with defined directors
  319. if re.compile(FavDir, re.IGNORECASE).search(check_fav_director):
  320. return 1
  321. else:
  322. return 0
  323. def isFavActor(check_fav_actor):
  324. #this is set to ignore imdb filters for movies with defined actors
  325. if re.compile(FavActor, re.IGNORECASE).search(check_fav_actor):
  326. return 1
  327. else:
  328. return 0
  329. def isFavChar(check_fav_char):
  330. #this is set to ignore imdb filters for movies with defined characters
  331. if re.compile(FavChar, re.IGNORECASE).search(check_fav_char):
  332. return 1
  333. else:
  334. return 0
  335. def isFavTitle(check_fav_title):
  336. #this is set to ignore imdb filters for movies with defined good titles
  337. if re.compile(FavTitle, re.IGNORECASE).search(check_fav_title):
  338. return 1
  339. else:
  340. return 0
  341. else:
  342. def isFavDir(check_fav_director):
  343. return 0
  344. def isFavActor(check_fav_actor):
  345. return 0
  346. def isFavChar(check_fav_char):
  347. return 0
  348. def isFavTitle(check_fav_title):
  349. return 0
  350. def isBadTitle(check_bad_title):
  351. #this is set to ignore imdb filters for movies with defined bad titles
  352. if re.compile(BadTitle, re.IGNORECASE).search(check_bad_title):
  353. return 0
  354. else:
  355. return 1
  356. def isBadGenre(check_bad_genre):
  357. #this is set to download only movies that DO NOT match defined genre's
  358. if re.compile(BadGenre, re.IGNORECASE).search(check_bad_genre):
  359. return 0
  360. else:
  361. return 1
  362. if EnablePreferred == "yes":
  363. def isPreferredGenre(check_pref_genre):
  364. #this is set to download only movies that match defined genre's
  365. if check_pref_genre is not None:
  366. if re.compile(GoodPreferredGenre, re.IGNORECASE).search(check_pref_genre):
  367. return 1
  368. else:
  369. return 0
  370. if EnableQueuing == "yes":
  371. def isQueueDate(check_queue_date):
  372. #this is set to queue movies with a maximum defined year (min is GoodDate)
  373. if check_queue_date is not None:
  374. if check_queue_date <= QueueDate:
  375. return 1
  376. else:
  377. return 0
  378. def isQueueGenre(check_queue_genre):
  379. #this is set to queue movies with defined genre's
  380. if re.compile(QueueGenre, re.IGNORECASE).search(check_queue_genre):
  381. return 1
  382. else:
  383. return 0
  384. except:
  385. error_logging("IMDB Filter Function")
  386. ########################
  387. # IMDB Movie Variables #
  388. ########################
  389. def IMDBVarMod():
  390. try:
  391. global imdb_movie_title
  392. global imdb_movie_year
  393. global imdb_movie_year_str
  394. global imdb_movie_description
  395. global imdb_movie_runtime
  396. global imdb_movie_runtime_str
  397. global imdb_movie_rating
  398. global imdb_movie_rating_str
  399. global imdb_movie_votes
  400. global imdb_movie_genres
  401. global imdb_movie_genres_str
  402. global imdb_movie_directors
  403. global imdb_movie_directors_str
  404. global imdb_movie_cast_members
  405. global imdb_movie_cast_members_str
  406. #imdb movie title
  407. imdb_json_title = imdb_json_page["data"]["title"]
  408. imdb_movie_title = decode_htmlentities(imdb_json_title)
  409. imdb_movie_title = imdb_movie_title.encode("utf-8")
  410. #remove/replace illegal characters from imdb title (used for nzb filename)
  411. imdb_movie_title = re.sub("\.","" ,imdb_movie_title)
  412. imdb_movie_title = re.sub("\:","" ,imdb_movie_title)
  413. imdb_movie_title = re.sub("\"","" ,imdb_movie_title)
  414. imdb_movie_title = re.sub("\*","" ,imdb_movie_title)
  415. imdb_movie_title = re.sub("\"","" ,imdb_movie_title)
  416. imdb_movie_title = re.sub("/"," " ,imdb_movie_title)
  417. imdb_movie_title = re.sub("\\\\"," " ,imdb_movie_title)
  418. imdb_movie_title = re.sub("\?","" ,imdb_movie_title)
  419. imdb_movie_title = re.sub("\|","" ,imdb_movie_title)
  420. imdb_movie_title = re.sub("\<","" ,imdb_movie_title)
  421. imdb_movie_title = re.sub("\>","" ,imdb_movie_title)
  422. #replace roman numerals to numerics - e.g. "the movie IX" converts to "the movie 9"
  423. imdb_movie_title = re.sub("(?<![a-zA-Z0-9_])IX(?![a-zA-Z0-9_])","9", imdb_movie_title, re.I)
  424. #replace roman numerals to numerics - e.g. "the movie VIII" converts to "the movie 8"
  425. imdb_movie_title = re.sub("(?<![a-zA-Z0-9_])VIII(?![a-zA-Z0-9_])","8", imdb_movie_title, re.I)
  426. #replace roman numerals to numerics - e.g. "the movie VII" converts to "the movie 7"
  427. imdb_movie_title = re.sub("(?<![a-zA-Z0-9_])VII(?![a-zA-Z0-9_])","7", imdb_movie_title, re.I)
  428. #replace roman numerals to numerics - e.g. "the movie VI" converts to "the movie 6"
  429. imdb_movie_title = re.sub("(?<![a-zA-Z0-9_])VI(?![a-zA-Z0-9_])","6", imdb_movie_title, re.I)
  430. #replace roman numerals to numerics - e.g. "the movie V" converts to "the movie 5"
  431. imdb_movie_title = re.sub("(?<![a-zA-Z0-9_])V(?![a-zA-Z0-9_])","5", imdb_movie_title, re.I)
  432. #replace roman numerals to numerics - e.g. "the movie IV" converts to "the movie 4"
  433. imdb_movie_title = re.sub("(?<![a-zA-Z0-9_])IV(?![a-zA-Z0-9_])","4", imdb_movie_title, re.I)
  434. #replace roman numerals to numerics - e.g. "the movie III" converts to "the movie 3"
  435. imdb_movie_title = re.sub("(?<![a-zA-Z0-9_])III(?![a-zA-Z0-9_])","3" ,imdb_movie_title, re.I)
  436. #replace roman numerals to numerics - e.g. "the movie II" converts to "the movie 2"
  437. imdb_movie_title = re.sub("(?<![a-zA-Z0-9_])II(?![a-zA-Z0-9_])","2" ,imdb_movie_title, re.I)
  438. #converts first letter of each word in the movie title to caps e.g. "the movie" converts to "The Movie"
  439. imdb_movie_title = string.capwords(imdb_movie_title)
  440. #imdb movie release date
  441. imdb_movie_year = imdb_json_page["data"]["year"]
  442. imdb_movie_year = int(imdb_movie_year)
  443. imdb_movie_year_str = str(imdb_movie_year)
  444. #imdb movie runtime
  445. try:
  446. imdb_movie_runtime = imdb_json_page["data"]["runtime"]["time"]
  447. imdb_movie_runtime = int(imdb_movie_runtime) / 60
  448. imdb_movie_runtime_str = str(imdb_movie_runtime)
  449. except:
  450. imdb_movie_runtime = 1
  451. imdb_movie_runtime_str = str(imdb_movie_runtime)
  452. #imdb movie rating
  453. try:
  454. imdb_movie_rating = imdb_json_page["data"]["rating"]
  455. imdb_movie_rating = float(imdb_movie_rating)
  456. imdb_movie_rating_str = str(imdb_movie_rating)
  457. except:
  458. imdb_movie_rating = 1.0
  459. imdb_movie_rating_str = str(imdb_movie_rating)
  460. #imdb movie votes
  461. try:
  462. imdb_movie_votes = imdb_json_page["data"]["num_votes"]
  463. imdb_movie_votes = int(imdb_movie_votes)
  464. except:
  465. imdb_movie_votes = 1
  466. #imdb movie director
  467. try:
  468. imdb_movie_directors = imdb_json_page["data"]["directors_summary"]
  469. imdb_movie_directors_str = str(imdb_movie_directors)
  470. imdb_movie_directors_str = decode_htmlentities(imdb_movie_directors_str)
  471. imdb_movie_directors_str = imdb_movie_directors_str.encode("utf-8")
  472. except:
  473. imdb_movie_directors = "Unknown"
  474. imdb_movie_directors_str = "Unknown"
  475. #imdb movie cast
  476. try:
  477. imdb_movie_cast_members = imdb_json_page["data"]["cast_summary"]
  478. imdb_movie_cast_members_str = str(imdb_movie_cast_members)
  479. imdb_movie_cast_members_str = decode_htmlentities(imdb_movie_cast_members_str)
  480. imdb_movie_cast_members_str = imdb_movie_cast_members_str.encode("utf-8")
  481. except:
  482. imdb_movie_cast_members = "Unknown"
  483. imdb_movie_cast_members_str = "Unknown"
  484. #imdb movie description
  485. try:
  486. imdb_movie_description = imdb_json_page["data"]["plot"]["outline"]
  487. imdb_movie_description = decode_htmlentities(imdb_movie_description)
  488. imdb_movie_description = imdb_movie_description.encode("utf-8")
  489. except:
  490. imdb_movie_description = "Unknown"
  491. #imdb movie genres
  492. try:
  493. imdb_movie_genres = imdb_json_page["data"]["genres"]
  494. imdb_movie_genres_str = str(imdb_movie_genres)
  495. except:
  496. imdb_movie_genres = "Unknown"
  497. imdb_movie_genres_str = "Unknown"
  498. return "OK"
  499. except:
  500. error_logging("IMDB Movie Variables Function")
  501. return "Error"
  502. #######################
  503. # create mymovies.xml #
  504. #######################
  505. def MetaData():
  506. try:
  507. if EnableMetadata == "yes":
  508. self.bind.bar.SetStatusText("Writing Informations to MetaData File",1)
  509. #create mymovies.xml file
  510. mymoviesfile=file(metadata_dir + "\\" + imdb_movie_title + " mymovies.xml","w")
  511. mymoviesfile.write("<Title>" + "\n")
  512. #write imdb movie title
  513. mymoviesfile.write(" <LocalTitle>" + imdb_movie_title + "</LocalTitle>" + "\n")
  514. mymoviesfile.write(" <OriginalTitle>" + imdb_movie_title + "</OriginalTitle>" + "\n")
  515. mymoviesfile.write(" <SortTitle>" + imdb_movie_title + "</SortTitle>" + "\n")
  516. #write date and time
  517. mymoviesfile.write(time.strftime(" <Added>" + "%d" + "/" + "%m" + "/" + "%Y" + " " + "%H" + ":" + "%M" + ":" + "%S" + "</Added>" + "\n"))
  518. #write movie release year
  519. mymoviesfile.write(" <ProductionYear>" + imdb_movie_year_str + "</ProductionYear>" + "\n")
  520. #write running time
  521. mymoviesfile.write(" <RunningTime>" + imdb_movie_runtime_str + "</RunningTime>" + "\n")
  522. #write imdb rating
  523. mymoviesfile.write(" <IMDBrating>" + imdb_movie_rating_str + "</IMDBrating>" + "\n")
  524. #write description
  525. mymoviesfile.write(" <Description>" + imdb_movie_description + "</Description>" + "\n")
  526. #write static cover image links
  527. mymoviesfile.write(" <Covers>" + "\n")
  528. mymoviesfile.write(" <Front>folder.jpg</Front>" + "\n")
  529. mymoviesfile.write(" <Back />" + "\n")
  530. mymoviesfile.write(" </Covers>" + "\n")
  531. #write genres
  532. mymoviesfile.write(" <Genres>" + "\n")
  533. for imdb_movie_genre in imdb_movie_genres:
  534. mymoviesfile.write(" <Genre>" + imdb_movie_genre + "</Genre>" + "\n")
  535. mymoviesfile.write(" </Genres>" + "\n")
  536. #write directors name
  537. mymoviesfile.write(" <Persons>" + "\n")
  538. for imdb_movie_director in imdb_movie_directors:
  539. mymoviesfile.write(" <Person>" + "\n")
  540. imdb_movie_director_name = imdb_movie_director["name"]["name"]
  541. imdb_movie_director_name = decode_htmlentities(imdb_movie_director_name)
  542. imdb_movie_director_name = imdb_movie_director_name.encode("utf-8")
  543. mymoviesfile.write(" <Name>" + imdb_movie_director_name + "</Name>" + "\n")
  544. mymoviesfile.write(" <Type>Director</Type>" + "\n")
  545. mymoviesfile.write(" </Person>" + "\n")
  546. #write actor and character names
  547. for imdb_movie_cast_member in imdb_movie_cast_members:
  548. imdb_movie_actor = imdb_movie_cast_member["name"]["name"]
  549. imdb_movie_actor = decode_htmlentities(imdb_movie_actor)
  550. imdb_movie_actor = imdb_movie_actor.encode("utf-8")
  551. imdb_movie_character = imdb_movie_cast_member["char"]
  552. imdb_movie_character = decode_htmlentities(imdb_movie_character)
  553. imdb_movie_character = imdb_movie_character.encode("utf-8")
  554. mymoviesfile.write(" <Person>" + "\n")
  555. mymoviesfile.write(" <Name>" + imdb_movie_actor + "</Name>" + "\n")
  556. mymoviesfile.write(" <Type>Actor</Type>" + "\n")
  557. mymoviesfile.write(" <Role>" + imdb_movie_character + "</Role>" + "\n")
  558. mymoviesfile.write(" </Person>" + "\n")
  559. mymoviesfile.write(" </Persons>" + "\n")
  560. #write end tag and close file
  561. mymoviesfile.write("</Title>" + "\n")
  562. mymoviesfile.close()
  563. except:
  564. error_logging("MyMovies Creation Function")
  565. ####################
  566. # download trailer #
  567. ####################
  568. def Trailer():
  569. try:
  570. global PreferredTrailerSize
  571. global AlternativeTrailerSize
  572. if EnableTrailerDownloads == "yes":
  573. #change friendly names to actual resolutions for preferred size
  574. if PreferredTrailerSize == "high":
  575. PreferredTrailerSize = "HD 720p"
  576. elif PreferredTrailerSize == "med":
  577. PreferredTrailerSize = "HD 480p"
  578. elif PreferredTrailerSize == "low":
  579. PreferredTrailerSize = "H.264 480x320"
  580. #change friendly names to actual resolutions for alternative size
  581. if AlternativeTrailerSize == "high":
  582. AlternativeTrailerSize = "HD 720p"
  583. elif AlternativeTrailerSize == "med":
  584. AlternativeTrailerSize = "HD 480p"
  585. elif AlternativeTrailerSize == "low":
  586. AlternativeTrailerSize = "H.264 480x320"
  587. #generate imdb movie trailer url from json feed
  588. try:
  589. imdb_trailer_url = imdb_json_page["data"]["trailer"]["encodings"][PreferredTrailerSize]["url"]
  590. except:
  591. try:
  592. imdb_trailer_url = imdb_json_page["data"]["trailer"]["encodings"][AlternativeTrailerSize]["url"]
  593. except:
  594. imdb_trailer_url = None
  595. warning_logging("Trailer No Match")
  596. self.wait = 1
  597. #save trailer file in trailer folder
  598. if imdb_trailer_url is not None:
  599. if ConsoleLogToFile == "yes" :
  600. console_logging("------------------------------\nStatus: Downloading Trailer.....\nTitle: " + nzbmatrix_movietitle)
  601. self.bind.bar.SetStatusText("Downloading Trailer for " + imdb_movie_title + "...",1)
  602. urllib.urlretrieve(imdb_trailer_url, trailer_dir + imdb_movie_title + " Trailer" + ".mp4")
  603. except:
  604. error_logging("Trailer Download Function")
  605. ######################
  606. # nzbmatrix download #
  607. ######################
  608. def NZBMatrixDownload():
  609. try:
  610. global EmailDownloadStatus
  611. self.bind.bar.SetStatusText("Downloading Movie " + nzbmatrix_movietitle,1)
  612. if ConsoleLogToFile == "yes" :
  613. console_logging("------------------------------\nStatus: Downloading Movie.....\nTitle: " + nzbmatrix_movietitle)
  614. if EnableQueuing == "yes":
  615. #this will copy nzb to queued folder if queue date and queue votes are greater than defined values and not queue genres
  616. if (isQueueDate(imdb_movie_year) == 1 or isQueueGenre(imdb_movie_genres_str) == 1):
  617. NZBDownloadRetryCount = 0
  618. while NZBDownloadRetryCount < 5:
  619. #sleep and retry to download nzb from nzbmatrix 5 times with 30 sec gap
  620. try:
  621. #save nzb file in queued folder
  622. browser.retrieve(nzbmatrix_download_link, queue_dir + imdb_movie_title + ".nzb")
  623. EmailDownloadStatus = "Queued"
  624. break
  625. except:
  626. NZBDownloadRetryCount += 1
  627. time.sleep(30)
  628. else:
  629. warning_logging("Nzbmatrix Download Failed")
  630. self.wait = 1
  631. #os._exit(1)
  632. else:
  633. NZBDownloadRetryCount = 0
  634. while NZBDownloadRetryCount < 5:
  635. #sleep and retry to download nzb from nzbmatrix 5 times with 30 sec gap
  636. try:
  637. if ConsoleLogToFile == "yes" :
  638. console_logging("try : " + NZBDownloadRetryCount)
  639. #save nzb file in watched folder
  640. browser2 = mechanize.Browser()
  641. browser2.retrieve(nzbmatrix_download_link, watch_dir + imdb_movie_title + ".nzb")
  642. EmailDownloadStatus = "Downloading"
  643. if growl_notification == "yes":
  644. TheCommand = 'growlnotify.exe "Auto Download ' + nzbmatrix_movietitle + '"'
  645. os.system(TheCommand)
  646. if prowl_notification == "yes":
  647. 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()
  648. if xbmc_notification == "yes":
  649. urllib.urlopen("http://" + xbmc_server + ":" + xbmc_port + "/xbmcCmds/xbmcHttp?command=ExecBuiltIn(Notification(Crazy Beaver,%20Downloading " + nzbmatrix_movietitle + "))").close()
  650. 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')")
  651. conn.commit()
  652. break
  653. except:
  654. NZBDownloadRetryCount += 1
  655. time.sleep(30)
  656. else:
  657. warning_logging("Nzbmatrix Download Failed")
  658. self.wait = 1
  659. #os._exit(1)
  660. else:
  661. NZBDownloadRetryCount = 0
  662. while NZBDownloadRetryCount < 5:
  663. #sleep and retry to download nzb from nzbmatrix 5 times with 30 sec gap
  664. try:
  665. #save nzb file in watched folder
  666. #login to nzbmatrix using mechanize
  667. browser2 = mechanize.Browser()
  668. 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)")]
  669. #this attempts to open the login page for nzbmatrix
  670. OpenLoginRetryCount = 0
  671. while OpenLoginRetryCount < 5:
  672. #sleep and retry to read the login page for nzbmatrix 5 times with 30 sec gap
  673. try:
  674. browser2.open(nzbmatrix_login_url)
  675. break
  676. except:
  677. OpenLoginRetryCount += 1
  678. time.sleep(30)
  679. else:
  680. warning_logging("Nzbmatrix Login Down")
  681. self.wait = 1
  682. #os._exit(1)
  683. browser2.select_form(nr=0)
  684. browser2['username'] = nzbmatrix_username
  685. browser2['password'] = nzbmatrix_password
  686. browser2.submit()
  687. browser2.retrieve(nzbmatrix_download_link, watch_dir + imdb_movie_title + ".nzb")
  688. EmailDownloadStatus = "Downloading"
  689. break
  690. except:
  691. NZBDownloadRetryCount += 1
  692. time.sleep(30)
  693. else:
  694. warning_logging("Nzbmatrix Download Failed")
  695. self.wait = 1
  696. #os._exit(1)
  697. if growl_notification == "yes":
  698. TheCommand = 'growlnotify.exe "Auto Download ' + nzbmatrix_movietitle + '"'
  699. os.system(TheCommand)
  700. if prowl_notification == "yes":
  701. 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()
  702. if xbmc_notification == "yes":
  703. urllib.urlopen("http://" + xbmc_server + ":" + xbmc_port + "/xbmcCmds/xbmcHttp?command=ExecBuiltIn(Notification(Crazy Beaver,%20Downloading " + nzbmatrix_movietitle + "))").close()
  704. except:
  705. error_logging("NZBMatrix Download Function")
  706. #################
  707. # nzbs download #
  708. #################
  709. def NZBsDownload():
  710. try:
  711. global EmailDownloadStatus
  712. self.bind.bar.SetStatusText("Downloading Movie " + nzbs_movietitle,1)
  713. if ConsoleLogToFile == "yes" :
  714. console_logging("------------------------------\nStatus: Downloading Movie.....\nTitle: " + nzbs_movietitle)
  715. if EnableQueuing == "yes":
  716. #this will copy nzb to queued folder if queue date and queue votes are greater than defined values and not queue genres
  717. if (isQueueDate(imdb_movie_year) == 1 or isQueueGenre(imdb_movie_genres_str) == 1):
  718. NZBDownloadRetryCount = 0
  719. while NZBDownloadRetryCount < 5:
  720. #sleep and retry to download nzb from nzbs 5 times with 30 sec gap
  721. try:
  722. #save nzb file in queued folder
  723. urllib.urlretrieve(nzbs_directdl, queue_dir + imdb_movie_title + ".nzb")
  724. EmailDownloadStatus = "Queued"
  725. break
  726. except:
  727. NZBDownloadRetryCount += 1
  728. time.sleep(30)
  729. else:
  730. self.bind.bar.SetStatusText("Nzbs Download Failed",1)
  731. warning_logging("Nzbs Download Failed")
  732. self.wait = 1
  733. #os._exit(1)
  734. else:
  735. NZBDownloadRetryCount = 0
  736. while NZBDownloadRetryCount < 5:
  737. #sleep and retry to download nzb from nzbs 5 times with 30 sec gap
  738. try:
  739. #save nzb file in watched folder
  740. urllib.urlretrieve(nzbs_directdl, watch_dir + imdb_movie_title + ".nzb")
  741. EmailDownloadStatus = "Downloading"
  742. if growl_notification == "yes":
  743. TheCommand = 'growlnotify.exe "Auto Download ' + nzbs_movietitle + '"'
  744. os.system(TheCommand)
  745. if prowl_notification == "yes":
  746. 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()
  747. if xbmc_notification == "yes":
  748. urllib.urlopen("http://" + xbmc_server + ":" + xbmc_port + "/xbmcCmds/xbmcHttp?command=ExecBuiltIn(Notification(Crazy Beaver,%20Downloading " + nzbs_movietitle + "))").close()
  749. break
  750. except:
  751. NZBDownloadRetryCount += 1
  752. time.sleep(30)
  753. else:
  754. self.bind.bar.SetStatusText("Nzbs Download Failed",1)
  755. warning_logging("Nzbs Download Failed")
  756. self.wait = 1
  757. else:
  758. NZBDownloadRetryCount = 0
  759. while NZBDownloadRetryCount < 5:
  760. #sleep and retry to download nzb from nzbmatrix 5 times with 30 sec gap
  761. try:
  762. #save nzb file in watched folder
  763. urllib.urlretrieve(nzbs_directdl, watch_dir + imdb_movie_title + ".nzb")
  764. EmailDownloadStatus = "Downloading"
  765. if growl_notification == "yes":
  766. TheCommand = 'growlnotify.exe "Auto Download ' + nzbs_movietitle + '"'
  767. os.system(TheCommand)
  768. if prowl_notification == "yes":
  769. 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()
  770. if xbmc_notification == "yes":
  771. urllib.urlopen("http://" + xbmc_server + ":" + xbmc_port + "/xbmcCmds/xbmcHttp?command=ExecBuiltIn(Notification(Crazy Beaver,%20Downloading " + nzbs_movietitle + "))").close()
  772. break
  773. except:
  774. NZBDownloadRetryCount += 1
  775. time.sleep(30)
  776. else:
  777. self.bind.bar.SetStatusText("Nzbs Download Failed",1)
  778. warning_logging("Nzbs Download Failed")
  779. self.wait = 1
  780. except:
  781. self.bind.bar.SetStatusText("NZBs Download Function",1)
  782. error_logging("NZBs Download Function")
  783. ################
  784. # nzb download #
  785. ################
  786. def NZBDownload(nzbsu_guid):
  787. try:
  788. global EmailDownloadStatus
  789. self.bind.bar.SetStatusText("Downloading Movie",1)
  790. if ConsoleLogToFile == "yes" :
  791. console_logging("------------------------------\nStatus: Downloading Movie.....\nTitle: " + imdb_movie_title)
  792. if EnableQueuing == "yes":
  793. #this will copy nzb to queued folder if queue date and queue votes are greater than defined values and not queue genres
  794. if (isQueueDate(imdb_movie_year) == 1 or isQueueGenre(imdb_movie_genres_str) == 1):
  795. NZBDownloadRetryCount = 0
  796. while NZBDownloadRetryCount < 5:
  797. #sleep and retry to download nzb 5 times with 30 sec gap
  798. try:
  799. #save nzb file in queued folder
  800. nzbsu_download_link = "http://www.nzb.su/api?t=get&id=" + nzbsu_guid + "&apikey=" + nzbsu_key
  801. browser.retrieve(eval(IndexSite + "_download_link"), queue_dir + imdb_movie_title + ".nzb")
  802. EmailDownloadStatus = "Queued"
  803. break
  804. except:
  805. NZBDownloadRetryCount += 1
  806. time.sleep(30)
  807. else:
  808. self.bind.bar.SetStatusText(IndexSite + " Download Failed For Movie " + imdb_movie_title,1)
  809. warning_logging(IndexSite + " Download Failed For Movie " + imdb_movie_title)
  810. self.wait = 1
  811. if ConsoleLogToFile == "yes" :
  812. console_logging("---------------------------\n" + IndexSite + " Download Failed")
  813. #os._exit(1)
  814. else:
  815. NZBDownloadRetryCount = 0
  816. while NZBDownloadRetryCount < 5:
  817. #sleep and retry to download nzb 5 times with 30 sec gap
  818. try:
  819. #save nzb file in watched folder
  820. nzbsu_download_link = "http://www.nzb.su/api?t=get&id=" + nzbsu_guid + "&apikey=" + nzbsu_key
  821. browser.retrieve(eval(IndexSite + "_download_link"), watch_dir + imdb_movie_title + ".nzb")
  822. EmailDownloadStatus = "Downloading"
  823. if growl_notification == "yes":
  824. TheCommand = 'growlnotify.exe "Auto Download ' + imdb_movie_title + '"'
  825. os.system(TheCommand)
  826. if prowl_notification == "yes":
  827. 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()
  828. if xbmc_notification == "yes":
  829. urllib.urlopen("http://" + xbmc_server + ":" + xbmc_port + "/xbmcCmds/xbmcHttp?command=ExecBuiltIn(Notification(Crazy Beaver,%20Downloading " + imdb_movie_title + "))").close()
  830. break
  831. except:
  832. NZBDownloadRetryCount += 1
  833. time.sleep(30)
  834. else:
  835. self.bind.bar.SetStatusText(IndexSite + " Download Failed For Movie " + imdb_movie_title,1)
  836. warning_logging(IndexSite + " Download Failed For Movie " + imdb_movie_title)
  837. self.wait = 1
  838. if ConsoleLogToFile == "yes" :
  839. console_logging("---------------------------\n" + IndexSite + " Download Failed")
  840. #os._exit(1)

Large files files are truncated, but you can click here to view the full file