Skip to content

Commit

Permalink
Fixed issue with Sab and NZBMatrix,Added torrent blackhole,add kat to…
Browse files Browse the repository at this point in the history
…rrent provider
  • Loading branch information
Michael Dlesk committed Jan 12, 2012
1 parent 366897d commit 84e8f8a
Show file tree
Hide file tree
Showing 15 changed files with 4,049 additions and 16 deletions.
22 changes: 21 additions & 1 deletion API.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,26 @@ Examples:
<br />
&nbsp;&nbsp;&nbsp;Get list of all games: http://127.0.0.1:8085/api?api_key=ikzFRzA1Y8I1UajNJAOQ803TbTYk1vLB64A9SxrAxAw&mode=search
<br />
&nbsp;&nbsp;&nbsp;Search for games that contain "Super" and are only for the Wii: http://127.0.0.1:8085/api?api_key=ikzFRzA1Y8I1UajNJAOQ803TbTYk1vLB64A9SxrAxAw&mode=search&term=super&system=wii
&nbsp;&nbsp;&Anbsp;Search for games that contain "Super" and are only for the Wii: http://127.0.0.1:8085/api?api_key=ikzFRzA1Y8I1UajNJAOQ803TbTYk1vLB64A9SxrAxAw&mode=search&term=super&system=wii

***GETREQUESTED***
To Be Added
<br />
***ADDREQUESTED***
To Be Added
<br />
***DELETEREQUESTED***
To Be Added
<br />
***UPDATEREQUESTEDSTATUS***
To Be Added
<br />
***UPDATEGAMELIST***
<br />
This mode updates the Game List in Gamez from the Gamez.org web service. A json response will be returned with either an error or success message. No additional parameters are needed.

Examples:
<br />
&nbsp;&nbsp;&nbsp;Update game list: http://127.0.0.1:8085/api?api_key=ikzFRzA1Y8I1UajNJAOQ803TbTYk1vLB64A9SxrAxAw&mode=UPDATEGAMELIST
<br />
</hr>
Binary file modified Gamez.db
Binary file not shown.
3 changes: 3 additions & 0 deletions Gamez.ini
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ prowl_enabled = 0
growl_enabled = 0
notifo_enabled = 0
blackhole_nzb_enabled = 0
blackhole_torrent_enabled = 1
torrent_kat_enabled = 1

[Notifications]
prowl_api = ""
Expand All @@ -47,4 +49,5 @@ notifo_apikey = ""

[Blackhole]
nzb_blackhole_path = ""
torrent_blackhole_path = ""

5 changes: 4 additions & 1 deletion Gamez.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,11 @@ def RunGameTask():
isNewznabEnabled = config.get('SystemGenerated','newznab_enabled').replace('"','')
isNzbBlackholeEnabled = config.get('SystemGenerated','blackhole_nzb_enabled').replace('"','')
nzbBlackholePath = config.get('Blackhole','nzb_blackhole_path').replace('"','')
isTorrentBlackholeEnabled = config.get('SystemGenerated','blackhole_torrent_enabled').replace('"','')
isTorrentKATEnabled = config.get('SystemGenerated','torrent_kat_enabled').replace('"','')
torrentBlackholePath = config.get('Blackhole','torrent_blackhole_path').replace('"','')
LogEvent("Searching for games")
lib.GameTasks.GameTasks().FindGames(nzbMatrixUser,nzbMatrixApi,sabnzbdApi,sabnzbdHost,sabnzbdPort,newznabWiiCat,newznabApi,newznabHost,newznabPort,newznabXbox360Cat,sabnzbdCategory,isSabEnabled,isNzbMatrixEnabled,isNewznabEnabled,isNzbBlackholeEnabled,nzbBlackholePath)
lib.GameTasks.GameTasks().FindGames(nzbMatrixUser,nzbMatrixApi,sabnzbdApi,sabnzbdHost,sabnzbdPort,newznabWiiCat,newznabApi,newznabHost,newznabPort,newznabXbox360Cat,sabnzbdCategory,isSabEnabled,isNzbMatrixEnabled,isNewznabEnabled,isNzbBlackholeEnabled,nzbBlackholePath,isTorrentBlackholeEnabled,isTorrentKATEnabled,torrentBlackholePath)
except:
errorMessage = "Major error occured when running scheduled tasks"
for message in sys.exc_info():
Expand Down
4 changes: 4 additions & 0 deletions lib/ConfigFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ def CheckConfigForAllKeys(app_path):
if(config.has_option('Blackhole','nzb_blackhole_path') == False):
config.set('Blackhole','nzb_blackhole_path','""')
changesMade = True

if(config.has_option('Blackhole','torrent_blackhole_path') == False):
config.set('Blackhole','torrent_blackhole_path','""')
changesMade = True

if(changesMade):
with open(configFilePath,'wb') as configFile:
Expand Down
Binary file modified lib/ConfigFunctions.pyc
Binary file not shown.
Binary file modified lib/Constants.pyc
Binary file not shown.
7 changes: 4 additions & 3 deletions lib/DBFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def AddEventToDB(message):

def GetLog():
db_path = os.path.join(os.path.abspath(""),"Gamez.db")
sql = "SELECT message,created_date FROM gamez_log order by created_date desc"
sql = "SELECT message,created_date FROM gamez_log order by created_date desc limit 1000"
data = ''
connection = sqlite3.connect(db_path)
cursor = connection.cursor()
Expand Down Expand Up @@ -460,7 +460,7 @@ def GetUpcomingGames():

def ApiGetGamesFromTerm(term,system):
db_path = os.path.join(os.path.abspath(""),"Gamez.db")
sql = "SELECT GAME_NAME,SYSTEM FROM GAMES where game_name like '%" + term.replace("'","''") + "%' AND SYSTEM LIKE '%" + system + "%' ORDER BY GAME_NAME ASC"
sql = "SELECT GAME_NAME,SYSTEM,COVER FROM GAMES where game_name like '%" + term.replace("'","''") + "%' AND SYSTEM LIKE '%" + system + "%' ORDER BY GAME_NAME ASC"
data = ""
connection = sqlite3.connect(db_path)
cursor = connection.cursor()
Expand All @@ -470,13 +470,14 @@ def ApiGetGamesFromTerm(term,system):
try:
game_name = str(record[0])
system = str(record[1])
cover = str(record[2])
rowdata = '{"GameTitle":"' + game_name + '","System":"' + system + '","GameCover":"' + cover + '"},'
data = data + rowdata
except:
continue
cursor.close()
data = data[:-1]
data = "[" + data + "]"
data = '["Games":' + data + ']'
return data


Binary file modified lib/DBFunctions.pyc
Binary file not shown.
49 changes: 44 additions & 5 deletions lib/GameTasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
from subprocess import call
from Logger import LogEvent
import json
import feedparser

class GameTasks():

def FindGames(self, nzbmatrixusername, nzbmatrixapi,sabnzbdApi,sabnzbdHost,sabnzbdPort,newznabWiiCat,newznabApi,newznabHost,newznabPort,newznabXbox360Cat,sabnzbdCategory,isSabEnabled,isNzbMatrixEnabled,isNewznabEnabled,isNzbBlackholeEnabled,nzbBlackholePath):
def FindGames(self, nzbmatrixusername, nzbmatrixapi,sabnzbdApi,sabnzbdHost,sabnzbdPort,newznabWiiCat,newznabApi,newznabHost,newznabPort,newznabXbox360Cat,sabnzbdCategory,isSabEnabled,isNzbMatrixEnabled,isNewznabEnabled,isNzbBlackholeEnabled,nzbBlackholePath,isTorrentBlackholeEnabled,isTorrentKATEnabled,torrentBlackholePath):
if(isSabEnabled == "1"):
GameTasks().CheckIfPostProcessExistsInSab(sabnzbdApi,sabnzbdHost,sabnzbdPort)
nzbmatrixusername = nzbmatrixusername.replace('"','')
Expand Down Expand Up @@ -40,7 +41,13 @@ def FindGames(self, nzbmatrixusername, nzbmatrixapi,sabnzbdApi,sabnzbdHost,sabnz
LogEvent("Checking for game [" + game_name + "] on Newznab")
isDownloaded = GameTasks().FindGameOnNewznabServer(game_name,game_id,sabnzbdApi,sabnzbdHost,sabnzbdPort,newznabWiiCat,newznabApi,newznabHost,newznabPort,system,newznabXbox360Cat,sabnzbdCategory,isSabEnabled,isNzbBlackholeEnabled,nzbBlackholePath)
else:
LogEvent("NZB Matrix Settings Incomplete.")
LogEvent("NZB Matrix Settings Incomplete.")

if(isTorrentBlackholeEnabled == "1"):
if(isTorrentKATEnabled == "1"):
if(isDownloaded == False):
LogEvent("Checking for game [" + game_name + "] on KickAss Torrents")
isDownloaded = GameTasks().FindGameOnKAT(game_id,game_name,system,torrentBlackholePath)
except:
continue
return
Expand Down Expand Up @@ -104,12 +111,10 @@ def FindGameOnNewznabServer(self,game_name,game_id,sabnzbdApi,sabnzbdHost,sabnzb
if(response == "[]"):
return False
jsonObject = json.loads(response)
LogEvent("JSON Parsed")
for item in jsonObject:
nzbID = item["guid"]
LogEvent("Game found on Newznab")
nzbUrl = "http://" + newznabHost + ":" + newznabPort + "/api?apikey=" + newznabApi + "&t=get&id=" + nzbID
LogEvent(nzbUrl)
result = GameTasks().DownloadNZB(nzbUrl,game_name,sabnzbdApi,sabnzbdHost,sabnzbdPort,game_id,sabnzbdCategory,isSabEnabled,isNzbBlackholeEnabled,nzbBlackholePath,system)
if(result):
UpdateStatus(game_id,"Snatched")
Expand All @@ -132,6 +137,7 @@ def DownloadNZB(self,nzbUrl,game_name,sabnzbdApi,sabnzbdHost,sabnzbdPort,game_id
return False

def AddNZBToSab(self,nzbUrl,game_name,sabnzbdApi,sabnzbdHost,sabnzbdPort,game_id,sabnzbdCategory):
nzbUrl = urllib.quote(nzbUrl)
url = "http://" + sabnzbdHost + ":" + sabnzbdPort + "/sabnzbd/api?mode=addurl&pp=3&apikey=" + sabnzbdApi + "&script=gamezPostProcess.py&name=" + nzbUrl + "&nzbname=[" + game_id + "] - "+ game_name
if(sabnzbdCategory <> ''):
url = url + "&cat=" + sabnzbdCategory
Expand All @@ -155,7 +161,40 @@ def AddNZBToBlackhole(self,nzbUrl,nzbBlackholePath,game_name,system):
LogEvent("Unable to download NZB to blackhole: " + url)
return False
return True


def FindGameOnKAT(self,game_id,game_name,system,torrentBlackholePath):
url = "http://www.kickasstorrents.com/json.php?q=" + game_name
try:
opener = urllib.FancyURLopener({})
responseObject = opener.open(url)
response = responseObject.read()
responseObject.close()
jsonObject = json.loads(response)
listObject = jsonObject['list']
for record in listObject:
title = record['title']
torrentLink = record['torrentLink']
category = record['category']
print category
if(category == "Games"):
result = GameTasks().DownloadTorrent(torrentLink,title,torrentBlackholePath)
if(result == True):
UpdateStatus(game_id,"Snatched")
return result
except:
LogEvent("Unable to connect to KickAss Torrents")
return

def DownloadTorrent(self,torrentUrl,title,torrentBlackholePath):
try:
dest = torrentBlackholePath + title + ".torrent"
urllib.urlretrieve(torrentUrl,dest)
LogEvent("Torrent Added To Blackhole")
except:
LogEvent("Unable to download torrent to blackhole: " + url)
return False
return True

def CheckIfPostProcessExistsInSab(self,sabnzbdApi,sabnzbdHost,sabnzbdPort):

path = os.path.abspath("postprocess")
Expand Down
Binary file modified lib/GameTasks.pyc
Binary file not shown.
66 changes: 60 additions & 6 deletions lib/WebRoot.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,8 @@ def settings(self):
prowlChecked = config.get('SystemGenerated','prowl_enabled').replace('"','')
notifoChecked = config.get('SystemGenerated','notifo_enabled').replace('"','')
nzbBlackholeChecked = config.get('SystemGenerated','blackhole_nzb_enabled').replace('"','')
torrentBlackholeChecked = config.get('SystemGenerated','blackhole_torrent_enabled').replace('"','')
katChecked = config.get('SystemGenerated','torrent_kat_enabled').replace('"','')
if(sabChecked == "1"):
sabChecked = "CHECKED"
else:
Expand Down Expand Up @@ -296,7 +298,15 @@ def settings(self):
nzbBlackholeChecked = "CHECKED"
else:
nzbBlackholeChecked = ""

if(torrentBlackholeChecked == "1"):
torrentBlackholeChecked = "CHECKED"
else:
torrentBlackholeChecked = ""
if(katChecked == "1"):
katChecked = "CHECKED"
else:
katChecked = ""

html = """
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
Expand Down Expand Up @@ -375,7 +385,7 @@ def settings(self):
<ul>
<li><a href="#gamez-tab">Gamez</a></li>
<li><a href="#downloaders-tab">Downloaders</a></li>
<li><a href="#searchproviders-tab">Search Providers+</a></li>
<li><a href="#searchproviders-tab">Search Providers</a></li>
<li><a href="#notifications-tab">Notifications</a></li>
</ul>
<form id="form" name="form" method="get" action="/savesettings">
Expand Down Expand Up @@ -491,6 +501,21 @@ def settings(self):
</td>
</tr>
</table>
<br />
<label style="float:left"><b><u>BitTorrent</u></b></label>
<div style="float:right">
<input type="checkbox" name="torrentBlackholeEnabled" id="torrentBlackholeEnabled" value="torrentBlackholeEnabled" """ + torrentBlackholeChecked + """ />Enabled
</div>
<br />
<table>
<tr>
<td>
<label><b>BitTorrent Blackhole Path</b></label>
<br />
<input style="width:400px" type="text" name="torrentBlackholePath" id="torrentBlackholePath" value='""" + config.get('Blackhole','torrent_blackhole_path').replace('"','') + """' />
</td>
</tr>
</table>
</td>
</tr>
</table>
Expand Down Expand Up @@ -525,7 +550,7 @@ def settings(self):
</table>
</td>
<td width="10px">&nbsp;</td>
<td style="border:solid 1px" valign="top">
<td style="border:solid 1px" valign="top" rowspan="3">
<label style="float:left"><b><u>Newznab</u></b></label>
<div style="float:right">
<input type="checkbox" name="newznabEnabled" id="newznabEnabled" value="newznabEnabled" """ + newznabChecked + """ />Enabled
Expand Down Expand Up @@ -568,6 +593,15 @@ def settings(self):
</table>
</td>
</tr>
<tr><td>&nbsp;</td></tr>
<tr>
<td style="border:solid 1px" width="45%" valign="top">
<label style="float:left"><b><u>BitTorrent</u></b></label>
<br />
<br />
<input type="checkbox" name="katEnabled" id="katEnabled" value="katEnabled" """ + katChecked + """ />&nbsp;<b>KickAss Torrents</b>
</td>
</tr>
</table>
</p>
</div>
Expand Down Expand Up @@ -930,7 +964,7 @@ def upgradetolatestversion(self,verification):
raise cherrypy.InternalRedirect("/?status_message=" + status)

@cherrypy.expose
def savesettings(self,cherrypyHost='', nzbMatrixUsername='', downloadInterval=3600, sabPort='', nzbMatrixApi='', sabApi='', cherrypyPort='', sabHost='',gamezApiKey='',newznabHost='',newznabPort='',newznabApi='',newznabWiiCat='',newznabXbox360Cat='',prowlApi='',gamezUsername='',gamezPassword='',gameListUpdateInterval='',sabCategory='',growlHost='',growlPort='',growlPassword='',sabnzbdEnabled='',nzbmatrixEnabled='',newznabEnabled='',growlEnabled='',prowlEnabled='',notifoEnabled='',notifoUsername='',notifoApi='',nzbBlackholeEnabled='',nzbBlackholePath=''):
def savesettings(self,cherrypyHost='', nzbMatrixUsername='', downloadInterval=3600, sabPort='', nzbMatrixApi='', sabApi='', cherrypyPort='', sabHost='',gamezApiKey='',newznabHost='',newznabPort='',newznabApi='',newznabWiiCat='',newznabXbox360Cat='',prowlApi='',gamezUsername='',gamezPassword='',gameListUpdateInterval='',sabCategory='',growlHost='',growlPort='',growlPassword='',sabnzbdEnabled='',nzbmatrixEnabled='',newznabEnabled='',growlEnabled='',prowlEnabled='',notifoEnabled='',notifoUsername='',notifoApi='',nzbBlackholeEnabled='',nzbBlackholePath='',torrentBlackholeEnabled='',torrentBlackholePath='',katEnabled=''):
cherrypyHost = '"' + cherrypyHost + '"'
nzbMatrixUsername = '"' + nzbMatrixUsername + '"'
nzbMatrixApi = '"' + nzbMatrixApi + '"'
Expand All @@ -950,6 +984,7 @@ def savesettings(self,cherrypyHost='', nzbMatrixUsername='', downloadInterval=36
notifoUsername = '"' + notifoUsername + '"'
notifoApi = '"' + notifoApi + '"'
nzbBlackholePath = '"' + nzbBlackholePath + '"'
torrentBlackholePath = '"' + torrentBlackholePath + '"'
if(sabnzbdEnabled == 'sabnzbdEnabled'):
sabnzbdEnabled = "1"
else:
Expand Down Expand Up @@ -977,7 +1012,15 @@ def savesettings(self,cherrypyHost='', nzbMatrixUsername='', downloadInterval=36
if(nzbBlackholeEnabled == 'nzbBlackholeEnabled'):
nzbBlackholeEnabled = "1"
else:
nzbBlackholeEnabled = "0"
nzbBlackholeEnabled = "0"
if(torrentBlackholeEnabled == 'torrentBlackholeEnabled'):
torrentBlackholeEnabled = "1"
else:
torrentBlackholeEnabled = "0"
if(katEnabled == 'katEnabled'):
katEnabled = "1"
else:
katEnabled = "0"
config = ConfigParser.RawConfigParser()
configFilePath = os.path.join(WebRoot.appPath,'Gamez.ini')
config.read(configFilePath)
Expand All @@ -1001,6 +1044,8 @@ def savesettings(self,cherrypyHost='', nzbMatrixUsername='', downloadInterval=36
config.set('SystemGenerated','prowl_enabled',prowlEnabled)
config.set('SystemGenerated','notifo_enabled',notifoEnabled)
config.set('SystemGenerated','blackhole_nzb_enabled',nzbBlackholeEnabled)
config.set('SystemGenerated','blackhole_torrent_enabled',torrentBlackholeEnabled)
config.set('SystemGenerated','torrent_kat_enabled',katEnabled)
config.set('Newznab','host',newznabHost)
config.set('Newznab','port',newznabPort)
config.set('Newznab','wii_category_id',newznabWiiCat)
Expand All @@ -1013,6 +1058,7 @@ def savesettings(self,cherrypyHost='', nzbMatrixUsername='', downloadInterval=36
config.set('Notifications','notifo_username',notifoUsername)
config.set('Notifications','notifo_apikey',notifoApi)
config.set('Blackhole','nzb_blackhole_path',nzbBlackholePath)
config.set('Blackhole','torrent_blackhole_path',torrentBlackholePath)
with open(configFilePath,'wb') as configFile:
config.write(configFile)
status = "Application Settings Updated Successfully. Gamez is restarting. If after 5 seconds, Gamez isn't working, update the Gamez.ini file and re-launch Gamez"
Expand All @@ -1034,8 +1080,16 @@ def api(self,api_key='',mode='',term='',system=''):
elif(api_key <> systemApiKey):
return json.dumps({"Error" : "Invalid API Key"})
else:
if(mode == 'search'):
if(mode == 'SEARCH'):
return ApiGetGamesFromTerm(term,system)
elif(mode == 'UPDATEGAMELIST'):
try:
AddWiiGamesIfMissing()
AddXbox360GamesIfMissing()
AddComingSoonGames()
return json.dumps({"Response":"Game list has been updated successfully"})
except:
return json.dumps({"Error" : "Error Updating Game List"})
else:
response = {"Error" : mode + " Mode Not Implemented"}

Expand Down
Binary file modified lib/WebRoot.pyc
Binary file not shown.
Loading

0 comments on commit 84e8f8a

Please sign in to comment.