Skip to content

Commit

Permalink
Added XBOX 360 games
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Dlesk committed Jan 2, 2012
1 parent e13517d commit 5b0d42a
Show file tree
Hide file tree
Showing 14 changed files with 73 additions and 31 deletions.
Binary file modified Gamez.db
Binary file not shown.
1 change: 1 addition & 0 deletions Gamez.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ api_key = ""
[Newznab]
api_key = ""
wii_category_id = "1030"
xbox360_category_id = "1050"
host = ""
port =

Expand Down
3 changes: 2 additions & 1 deletion Gamez.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,12 @@ def RunGameTask():
sabnzbdPort = config.get('Sabnzbd','port').replace('"','')
sabnzbdApi = config.get('Sabnzbd','api_key').replace('"','')
newznabWiiCat = config.get('Newznab','wii_category_id').replace('"','')
newznabXbox360Cat = config.get('Newznab','xbox360_category_id').replace('"','')
newznabApi = config.get('Newznab','api_key').replace('"','')
newznabHost = config.get('Newznab','host').replace('"','')
newznabPort = config.get('Newznab','port').replace('"','')
LogEvent("Searching for games")
lib.GameTasks.GameTasks().FindGames(nzbMatrixUser,nzbMatrixApi,sabnzbdApi,sabnzbdHost,sabnzbdPort,newznabWiiCat,newznabApi,newznabHost,newznabPort)
lib.GameTasks.GameTasks().FindGames(nzbMatrixUser,nzbMatrixApi,sabnzbdApi,sabnzbdHost,sabnzbdPort,newznabWiiCat,newznabApi,newznabHost,newznabPort,newznabXbox360Cat)
except:
errorMessage = "Major error occured when running scheduled tasks"
for message in sys.exc_info():
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Gamez is currently in *Alpha* release. There may be bugs in the application.

Gamez is an automated downloader for video games. The user adds the games they wish to download and Gamez will attempt to find the game and download it.

As of the current release, only Wii games are supported.
As of the current release, only Wii and Xbox 360 games are supported. More systems will be supported in future releases

Current Features:

Expand All @@ -16,6 +16,6 @@ Current Features:

***Dependencies***

Gamez requires Python and CherryPY
Gamez requires Python and CherryPY. The CherryPy module is included with Gamez. Python must be installed on the system on which Gamez will be ran.

<hr />
4 changes: 4 additions & 0 deletions lib/ConfigFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ def CheckConfigForAllKeys(app_path):
config.set('Newznab','wii_category_id','"1030"')
changesMade = True

if(config.has_option('Newznab','xbox360_category_id') == False):
config.set('Newznab','xbox360_category_id','"1050"')
changesMade = True

if(config.has_option('Newznab','host') == False):
config.set('Newznab','host','""')
changesMade = True
Expand Down
Binary file modified lib/ConfigFunctions.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion lib/Constants.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
def VersionNumber():
return "0.0.0.9"
return "0.0.1.0"
Binary file modified lib/Constants.pyc
Binary file not shown.
54 changes: 38 additions & 16 deletions lib/DBFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def RemoveGameFromDb(db_id):

def GetRequestedGamesAsArray():
db_path = os.path.join(os.path.abspath(""),"Gamez.db")
sql = "SELECT game_name,ID FROM requested_games WHERE status='Wanted' order by game_name asc"
sql = "SELECT game_name,ID,system FROM requested_games WHERE status='Wanted' order by game_name asc"
connection = sqlite3.connect(db_path)
cursor = connection.cursor()
cursor.execute(sql)
Expand Down Expand Up @@ -170,27 +170,21 @@ def ValidateDB():
cursor.execute(sql)
result = cursor.fetchall()
cursor.close()

#drop table
sql = "drop table requested_games"
connection = sqlite3.connect(db_path)
cursor = connection.cursor()
cursor.execute(sql)
connection.commit()
cursor.close()

#create table in new format
sql = "CREATE TABLE REQUESTED_GAMES (ID INTEGER PRIMARY KEY,GAME_NAME TEXT,SYSTEM TEXT,GAME_TYPE TEXT,STATUS TEXT)"
connection = sqlite3.connect(db_path)
cursor = connection.cursor()
cursor.execute(sql)
connection.commit()
cursor.close()

for record in result:
game_name = str(record[0])
status = str(record[1])
#insert into new table
sql = "insert into requested_games (game_name,game_type,system,status) values ('" + game_name.replace("'","''") + "','Game','Wii','" + status + "')"
connection = sqlite3.connect(db_path)
cursor = connection.cursor()
Expand All @@ -206,16 +200,12 @@ def ValidateDB():
cursor.execute(sql)
connection.commit()
cursor.close()

#create table in new format
sql = "CREATE TABLE GAMES (ID INTEGER PRIMARY KEY,GAME_NAME TEXT,SYSTEM TEXT,GAME_TYPE TEXT)"
connection = sqlite3.connect(db_path)
cursor = connection.cursor()
cursor.execute(sql)
connection.commit()
cursor.close()

#Populate with data
AddWiiGamesIfMissing()
print "Database upgrade complete"

Expand Down Expand Up @@ -262,9 +252,9 @@ def ClearDBLog():
cursor.close()
return

def ClearWiiGames():
def ClearGames(system):
db_path = os.path.join(os.path.abspath(""),"Gamez.db")
sql = "delete from games where system = 'Wii'"
sql = "delete from games where system = '" + system + "'"
connection = sqlite3.connect(db_path)
cursor = connection.cursor()
cursor.execute(sql)
Expand All @@ -283,12 +273,12 @@ def AddWiiGamesIfMissing():
LogEvent("Unable to connect to web service: " + wiiWebServiceUrl)
return
json_data = json.loads(response)
ClearWiiGames()
ClearGames("Wii")
for data in json_data:
game_name = data['GameTitle']
game_type = data['GameType']
db_path = os.path.join(os.path.abspath(""),"Gamez.db")
sql = "SELECT count(ID) from games where game_name = '" + game_name.replace("'","''") + "'"
sql = "SELECT count(ID) from games where game_name = '" + game_name.replace("'","''") + "' AND system='Wii'"
connection = sqlite3.connect(db_path)
cursor = connection.cursor()
cursor.execute(sql)
Expand All @@ -302,4 +292,36 @@ def AddWiiGamesIfMissing():
cursor.execute(sql)
connection.commit()
cursor.close()
return
return

def AddXbox360GamesIfMissing():
url = "http://www.gamezapp.org/webservice/xbox360"
response = ''
try:
responseObject = urllib.FancyURLopener({}).open(url)
response = responseObject.read()
responseObject.close()
except:
LogEvent("Unable to connect to web service: " + url)
return
json_data = json.loads(response)
ClearGames("Xbox360")
for data in json_data:
game_name = data['GameTitle']
game_type = data['GameType']
db_path = os.path.join(os.path.abspath(""),"Gamez.db")
sql = "SELECT count(ID) from games where game_name = '" + game_name.replace("'","''") + "' AND system='Xbox360'"
connection = sqlite3.connect(db_path)
cursor = connection.cursor()
cursor.execute(sql)
result = cursor.fetchall()
recordCount = result[0][0]
cursor.close()
if(str(recordCount) == "0"):
LogEvent("Adding XBOX 360 Game [" + game_name.replace("'","''") + "] to Game List")
sql = "INSERT INTO games (game_name,game_type,system) values('" + game_name.replace("'","''") + "','" + game_type + "','Xbox360')"
cursor = connection.cursor()
cursor.execute(sql)
connection.commit()
cursor.close()
return
Binary file modified lib/DBFunctions.pyc
Binary file not shown.
31 changes: 23 additions & 8 deletions lib/GameTasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class GameTasks():

def FindGames(self, nzbmatrixusername, nzbmatrixapi,sabnzbdApi,sabnzbdHost,sabnzbdPort,newznabWiiCat,newznabApi,newznabHost,newznabPort):
def FindGames(self, nzbmatrixusername, nzbmatrixapi,sabnzbdApi,sabnzbdHost,sabnzbdPort,newznabWiiCat,newznabApi,newznabHost,newznabPort,newznabXbox360Cat):
GameTasks().CheckIfPostProcessExistsInSab(sabnzbdApi,sabnzbdHost,sabnzbdPort)
nzbmatrixusername = nzbmatrixusername.replace('"','')
nzbmatrixapi = nzbmatrixapi.replace('"','')
Expand All @@ -21,23 +21,31 @@ def FindGames(self, nzbmatrixusername, nzbmatrixapi,sabnzbdApi,sabnzbdHost,sabnz
try:
game_name = str(game[0])
game_id = str(game[1])
system = str(game[2])
LogEvent("Searching for game: " + game_name)
isDownloaded = False

if(nzbmatrixusername <> '' and nzbmatrixapi <> ''):
LogEvent("Checking for game [" + game_name + "] on NZB Matrix")
isDownloaded = GameTasks().FindGameOnNZBMatrix(game_name,game_id,nzbmatrixusername,nzbmatrixapi,sabnzbdApi,sabnzbdHost,sabnzbdPort)
isDownloaded = GameTasks().FindGameOnNZBMatrix(game_name,game_id,nzbmatrixusername,nzbmatrixapi,sabnzbdApi,sabnzbdHost,sabnzbdPort,system)

if(newznabWiiCat <> '' and newznabWiiApi <> '' and newznabHost <> '' and newznabPort <> ''):
if(newznabWiiCat <> '' and newznabXbox360Cat <> '' and newznabApi <> '' and newznabHost <> '' and newznabPort <> ''):
if(isDownloaded == False):
LogEvent("Checking for game [" + game_name + "] on Newznab")
isDownloaded = FindGameOnNewznabServer(game_name,game_id,sabnzbdApi,sabnzbdHost,sabnzbdPort,newznabWiiCat,newznabApi,newznabHost,newznabPort)
isDownloaded = FindGameOnNewznabServer(game_name,game_id,sabnzbdApi,sabnzbdHost,sabnzbdPort,newznabWiiCat,newznabApi,newznabHost,newznabPort,system,newznabXbox360Cat)
except:
continue
return

def FindGameOnNZBMatrix(self,game_name,game_id,username,api,sabnzbdApi,sabnzbdHost,sabnzbdPort):
url = "http://api.nzbmatrix.com/v1.1/search.php?search=" + game_name + "&num=1&cat=44&username=" + username + "&apikey=" + api
def FindGameOnNZBMatrix(self,game_name,game_id,username,api,sabnzbdApi,sabnzbdHost,sabnzbdPort,system):
if(system == "Wii"):
catToUse = "44"
elif(systyem == "Xbox360"):
catToUse = "14"
else:
LogEvent("Unrecognized System")
return False
url = "http://api.nzbmatrix.com/v1.1/search.php?search=" + game_name + "&num=1&cat=" + catToUse + "&username=" + username + "&apikey=" + api
try:
opener = urllib.FancyURLopener({})
responseObject = opener.open(url)
Expand All @@ -64,8 +72,15 @@ def FindGameOnNZBMatrix(self,game_name,game_id,username,api,sabnzbdApi,sabnzbdHo
LogEvent("Error getting game [" + game_name + "] from NZB Matrix")
return False

def FindGameOnNewznabServer(self,game_name,game_id,sabnzbdApi,sabnzbdHost,sabnzbdPort,newznabWiiCat,newznabApi,newznabHost,newznabPort):
url = "http://" + newznabHost + ":" + newznabPort + "/api?apikey=" + newznabApi + "&t=search&cat=" + newznabWiiCat + "&q=" + game_name + "&o=json"
def FindGameOnNewznabServer(self,game_name,game_id,sabnzbdApi,sabnzbdHost,sabnzbdPort,newznabWiiCat,newznabApi,newznabHost,newznabPort,system,newznabXbox360Cat):
if(system == "Wii"):
catToUse = newznabWiiCat
elif(system == "Xbox360"):
catToUse = newznabXbox360Cat
else:
LogEvent("Unrecognized System")
return False
url = "http://" + newznabHost + ":" + newznabPort + "/api?apikey=" + newznabApi + "&t=search&cat=" + catToUse + "&q=" + game_name + "&o=json"
try:
opener = urllib.FancyURLopener({})
responseObject = opener.open(url)
Expand Down
Binary file modified lib/GameTasks.pyc
Binary file not shown.
5 changes: 2 additions & 3 deletions lib/WebRoot.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import cherrypy
import json
import os
from DBFunctions import GetGamesFromTerm, GetGameDataFromTerm, AddGameToDb, GetRequestedGames, RemoveGameFromDb, UpdateStatus, GetLog, ClearDBLog,AddWiiGamesIfMissing
from DBFunctions import GetGamesFromTerm, GetGameDataFromTerm, AddGameToDb, GetRequestedGames, RemoveGameFromDb, UpdateStatus, GetLog, ClearDBLog,AddWiiGamesIfMissing,AddXbox360GamesIfMissing
from UpgradeFunctions import CheckForNewVersion,IgnoreVersion,UpdateToLatestVersion
import ConfigParser
from time import sleep
Expand Down Expand Up @@ -560,7 +560,6 @@ def api(self,api_key=''):
@cherrypy.expose
def updategamelist(self):
AddWiiGamesIfMissing()
#TODO: Add Other Systems
#TODO: Copy requested from old structure to new structure
AddXbox360GamesIfMissing()
status = "Game list has been updated successfully"
raise cherrypy.InternalRedirect("/?status_message=" + status)
Binary file modified lib/WebRoot.pyc
Binary file not shown.

0 comments on commit 5b0d42a

Please sign in to comment.