예제 #1
0
    def SearchAndSendToSab(self, usenetCrawlerApiKey, sabnzbdApiKey, platform,
                           title, wantedGameId, sabnzbdBaseUrl):
        cat = self.categories.get(platform, self.defaultCategory)
        usenetCrawlerUrl = "https://www.usenet-crawler.com/api?apikey=" + usenetCrawlerApiKey + "&t=search&q=" + urllib.quote_plus(
            title) + "&sort=posted_desc&cat=" + cat

        webRequest = urllib2.Request(usenetCrawlerUrl, None,
                                     {'User-Agent': "GamezServer"})
        response = urllib2.urlopen(webRequest)
        gameData = response.read()
        treeData = ElementTree.fromstring(gameData)
        for matchedElement in treeData.findall('./channel/item'):
            nzbTitle = matchedElement.find('title').text
            nzbLink = matchedElement.find('link').text
            usenetCrawlerNzbId = matchedElement.find("guid").text.split('/')[
                len(matchedElement.find("guid").text.split('/')) - 1]
            if (self.forceNew):
                continue
            searchers = Searchers.Searchers()
            sabRespData = searchers.SendToSab(sabnzbdBaseUrl, sabnzbdApiKey,
                                              nzbLink, nzbTitle, wantedGameId)
            if (sabRespData == b'ok\n'):
                dao = DAO()
                dao.LogMessage("Snatched Game" + nzbTitle, "Info")
                dao.UpdateWantedGameStatus(wantedGameId, "Snatched")
                dao.AddSnatchedHistory("usenetCrawler", usenetCrawlerNzbId)
                return "Snatched Game: " + nzbTitle
예제 #2
0
 def Abgx360(self, folder):
     dao = DAO()
     abgxEnabled = dao.GetSiteMasterData("abgx360Enabled")
     abgxPath = dao.GetSiteMasterData("abgx360Path")
     abgxRegion = dao.GetSiteMasterData("abgx360Region")
     if (enabled == "true"):
         print ''
     else:
         return True
예제 #3
0
 def ForceGameSearch(self, gameId, forceNew=False):
     dao = DAO()
     searchNewOnly = dao.GetSiteMasterData("onlySearchNew")
     if (searchNewOnly != None and searchNewOnly == "true"):
         forceNew = True
     sabnzbdEnabled = dao.GetSiteMasterData("sabnzbdEnabled")
     if (sabnzbdEnabled == "true"):
         sabnzbdApiKey = dao.GetSiteMasterData("sabnzbdApiKey")
         if (sabnzbdApiKey == None):
             dao.LogMessage(
                 "No Sabnzbd+ API Key Configured. Unable to continue",
                 "Warning")
             return "No Sabnzbd+ API Key Configured. Unable to continue"
         else:
             game = dao.GetWantedGame(gameId)
             searchers = dao.GetSearcherPriority()
             result = ""
             for searcher in searchers:
                 if ("Snatched Game" not in result):
                     searchers = Searchers()
                     searcherInstance = searchers.GetSearcher(
                         searcher[0], forceNew)
                     if (searcherInstance != None):
                         tmpResult = searcherInstance.search(
                             game[1], game[2], game[0])
                         if (tmpResult != None):
                             result = result + tmpResult
             if (result != ""):
                 return result
             else:
                 return "Unable to find game"
     else:
         dao.LogMessage("No Downloaders Configured", "Warning")
         return "No Downloaders Configured"
예제 #4
0
 def UpdateMasterPlatforms(self):
     dao = DAO()
     dao.LogMessage("Updating Master Platforms", "Info")
     webRequest = urllib.request.Request(
         'http://thegamesdb.net/api/GetPlatformsList.php',
         headers={'User-Agent': "Magic Browser"})
     response = urllib2.urlopen(urllib2.urlopen(webRequest))
     platformData = response.read()
     treeData = ElementTree.fromstring(platformData)
     for matchedElement in treeData.findall('./Platforms/Platform'):
         if matchedElement.find('id') != None and matchedElement.find(
                 'alias') != None and matchedElement.find('name') != None:
             platformId = matchedElement.find('id').text
             platformName = matchedElement.find('name').text
             platformAlias = matchedElement.find('alias').text
             dao.UpdateMasterPlatform(platformId, platformName,
                                      platformAlias)
예제 #5
0
 def SendToSab(self, sabnzbdBaseUrl, sabnzbdApiKey, nzbLink, nzbTitle,
               wantedGameId):
     dao = DAO()
     nzbTitle = "[" + str(wantedGameId) + "] - " + nzbTitle
     category = dao.GetSiteMasterData('sabnzbdCategory')
     sabUrl = sabnzbdBaseUrl
     if (sabUrl.endswith('/') == False):
         sabUrl = sabUrl + "/"
     sabUrl = sabUrl + "sabnzbd/api"
     sabUrl = sabUrl + "?apikey=" + sabnzbdApiKey
     sabUrl = sabUrl + "&mode=addurl&name=" + urllib.quote_plus(nzbLink)
     sabUrl = sabUrl + "&nzbname=" + urllib.quote_plus(nzbTitle)
     if (category != None and category != ""):
         sabUrl = sabUrl + "&cat=" + category
     sabRequest = urllib2.Request(sabUrl,
                                  headers={'User-Agent': "GamezServer"})
     response = urllib2.urlopen(sabRequest)
     sabRespData = response.read()
     return sabRespData
예제 #6
0
 def UpdateMasterGames(self):
     try:
         dao = DAO()
         dao.LogMessage("Updating Master Games", "Info")
         platforms = dao.GetMasterPlatforms()
         for platform in platforms:
             platformId = platform[1]
             url = 'http://thegamesdb.net/api/GetPlatformGames.php?platform=' + platformId
             webRequest = urllib2.request.Request(
                 url, headers={'User-Agent': "Magic Browser"})
             response = urllib2.urlopen(urllib2.urlopen(webRequest))
             gameData = response.read()
             treeData = ElementTree.fromstring(gameData)
             for matchedElement in treeData.findall('./Game'):
                 if matchedElement.find(
                         'id') != None and matchedElement.find(
                             'GameTitle') != None and matchedElement.find(
                                 'ReleaseDate') != None:
                     gameId = matchedElement.find('id').text
                     gameTitle = matchedElement.find(
                         'GameTitle').text.encode('ascii',
                                                  'ignore').decode('ascii')
                     releaseDate = matchedElement.find('ReleaseDate').text
                     dao.UpdateMasterGame(platformId, gameId, gameTitle,
                                          releaseDate)
     except:
         e = sys.exc_info()[0]
         dao.LogMessage(e, "Error")
예제 #7
0
 def search(self, platform, title, wantedGameId):
     dao = DAO()
     usenetCrawlerEnabled = dao.GetSiteMasterData("usenetCrawlerEnabled")
     usenetCrawlerApiKey = dao.GetSiteMasterData("usenetCrawlerApiKey")
     sabnzbdEnabled = dao.GetSiteMasterData("sabnzbdEnabled")
     sabnzbdApiKey = dao.GetSiteMasterData("sabnzbdApiKey")
     sabnzbdBaseUrl= dao.GetSiteMasterData("sabnzbdBaseUrl")
     if(usenetCrawlerEnabled != None and usenetCrawlerEnabled == "true" and usenetCrawlerApiKey != None and usenetCrawlerApiKey != "" and sabnzbdEnabled != None and sabnzbdEnabled == "true" and sabnzbdApiKey != None and sabnzbdApiKey != "" and sabnzbdBaseUrl != None and sabnzbdBaseUrl != ""): 
         return self.SearchAndSendToSab(usenetCrawlerApiKey, sabnzbdApiKey, platform, title, wantedGameId,sabnzbdBaseUrl)
     else:
         return ""
예제 #8
0
 def WantedGameSearch(self):
     dao = DAO()
     sabnzbdEnabled = dao.GetSiteMasterData("sabnzbdEnabled")
     if (sabnzbdEnabled == "true"):
         sabnzbdApiKey = dao.GetSiteMasterData("sabnzbdApiKey")
         if (sabnzbdApiKey == None):
             dao.LogMessage(
                 "No Sabnzbd+ API Key Configured. Unable to continue",
                 "Warning")
         else:
             wantedGames = dao.GetNeededGames()
             searchers = dao.GetSearcherPriority()
             result = ""
             searchers = Searchers()
             for game in wantedGames:
                 for searcher in searchers:
                     searcherInstance = searchers.GetSearcher(searcher[0])
                     if (searcherInstance != None):
                         tmpResult = searcherInstance.search(
                             game[1], game[2], game[0])
                         if (tmpResult != None):
                             result = result + tmpResult
     else:
         dao.LogMessage("No Downloaders Configured", "Warning")
예제 #9
0
    def Start(self,configPath):
        rootPath = os.path.dirname(configPath)
        GamezServer.Service.DBPATH = os.path.join(rootPath, "GamezServer.db")
        GamezServer.Service.APPPATH = rootPath
        dao = DAO()
        dao.VerifyStructue()

        staticContentPath = os.path.join(rootPath, os.path.join("GamezServer","static-web"))
        appConfig = {'/static': {'tools.staticdir.on': True, 'tools.staticdir.dir': staticContentPath}}
        cherrypy.config.update(configPath)
        cherrypy.tree.mount(WebServe.WebServe(), '/', appConfig)
        
        dao.LogMessage("Registering Background Processes", "Info")
        Monitor(cherrypy.engine, GamezServer.Task.Task().UpdateMasterPlatforms, frequency=86400).subscribe()
        Monitor(cherrypy.engine, GamezServer.Task.Task().UpdateMasterGames, frequency=86400).subscribe()
        Monitor(cherrypy.engine, GamezServer.Task.Task().WantedGameSearch, frequency=86400).subscribe()
        dao.LogMessage("Starting Service", "Info")
        cherrypy.engine.start()
        launchBrowser = dao.GetSiteMasterData("launchBrowser")
        if(launchBrowser == "true"):
            webbrowser.open("http://" + cherrypy.server.socket_host + ":" + str(cherrypy.server.socket_port) + '/')
        cherrypy.engine.block()
        
        
예제 #10
0
    def PostProcess(self, folder, gameId):

        result = ""
        limitExtensions = ""
        dao = DAO()
        game = dao.GetWantedGame(gameId)
        genericProcessing = True
        result = result + 'Processing folder: ' + folder + '\n'
        platformName = game[1]
        gameTitle = game[2]
        result = result + 'Processing Game: ' + gameTitle + '\n'
        destFolderRoot = dao.GetSiteMasterData("destinationFolder")
        if 'win' in sys.platform:
            destFolderRoot = destFolderRoot[1:]
        if (destFolderRoot == None or destFolderRoot == ""):
            return "Destination Folder Missing"
        destFolderPlatform = os.path.join(destFolderRoot, platformName)
        destFolderGame = os.path.join(destFolderPlatform,
                                      gameTitle.replace(":", ""))
        if not os.path.exists(destFolderGame):
            result = result + 'Creating Game Folder\n'
            os.makedirs(destFolderGame)

        if (platformName == "Microsoft Xbox 360"):
            failedFile = False
            fileCount = 0
            abgxEnabled = dao.GetSiteMasterData("abgx360Enabled")
            abgxPath = dao.GetSiteMasterData("abgx360Path")
            abgxRegion = dao.GetSiteMasterData("abgx360Region")
            xbox360Extensions = dao.GetSiteMasterData("xbox360Extensions")
            limitExtensions = xbox360Extensions
            if (abgxEnabled and abgxPath != None):
                if (os.path.exists(folder)):
                    for file in os.listdir(folder):
                        fileToProcess = os.path.join(folder, file)
                        if (os.path.isfile(fileToProcess)):
                            validFile = False
                            if (limitExtensions != ""):
                                for extension in limitExtensions.split(','):
                                    if (fileToProcess.endswith(extension)):
                                        validFile = True
                            else:
                                validFile = True
                            if (validFile):
                                #Run abgx against file
                                regionFree = False
                                discNumber = None
                                command = abgxPath + ' --noverify --noupdate --stayoffline --nowrite --noautofix --norebuild --nofixdrt --nofixdev --noverbose "' + fileToProcess + '"'
                                p = subprocess.Popen(command,
                                                     stdout=subprocess.PIPE,
                                                     shell=True)
                                lines = p.stdout.readlines()
                                for line in lines:
                                    if (line.startswith("Game Name:")):
                                        gameName = line.replace(
                                            "Game Name: ",
                                            "").lstrip().rstrip()
                                    if (line.startswith("Disc Number:")):
                                        discNumber = line.replace(
                                            "Disc Number: ",
                                            "").lstrip().rstrip()
                                    if (line.startswith("SS looks valid")):
                                        validSs = True
                                    if (line.startswith("DMI looks valid")):
                                        validDmi = True
                                    if (line.startswith("Region Code:")):
                                        regionCode = line.replace(
                                            "Region Code: ",
                                            "").lstrip().rstrip().replace(
                                                "0x", "")
                                    if (line.lstrip().startswith("Region Free")
                                        ):
                                        regionFree = True

                                processFile = False
                                if (regionFree == False):
                                    if (abgxRegion == ""):
                                        processFile = True
                                    else:
                                        if (abgxRegion == regionCode):
                                            processFile = True
                                else:
                                    processFile = True
                                if (processFile and gameName != "" and validSs
                                        and validDmi):
                                    result = result + 'Copying file: ' + file + '\n'
                                    extension = os.path.splitext(
                                        fileToProcess
                                    )[len(os.path.splitext(fileToProcess)) - 1]
                                    finalFileName = os.path.join(
                                        destFolderGame, gameName)
                                    if (discNumber != None):
                                        finalFileName = finalFileName + ' - ' + str(
                                            discNumber)
                                    finalFileName = finalFileName + extension
                                    buffer_size = 1024
                                    with open(fileToProcess, 'rb') as fsrc:
                                        with open(finalFileName,
                                                  'wb') as fdest:
                                            shutil.copyfileobj(
                                                fsrc, fdest, buffer_size)
                                    fileCount = fileCount + 1
                                else:
                                    failedFile = True
                                    result = result + 'Unable to verify. Skipping file: ' + file + '\n'
                genericProcessing = False
            if (fileCount == 0):
                failedFile = True
        if (genericProcessing):
            result = result + "No specific processing defined. Just copying files\n"
            if (os.path.exists(folder)):
                for file in os.listdir(folder):
                    fileToProcess = os.path.join(folder, file)
                    if (os.path.isfile(fileToProcess)):
                        validFile = False
                        if (limitExtensions != ""):
                            for extension in limitExtensions.split(','):
                                if (fileToProcess.endswith(extension)):
                                    validFile = True
                        else:
                            validFile = True
                        if (validFile):
                            result = result + 'Copying file: ' + file + '\n'
                            shutil.copy2(fileToProcess, destFolderGame)
        if (failedFile):
            result = result + "Unable to completely process game: " + gameTitle
        else:
            dao.UpdateWantedGameStatus(gameId, "Downloaded")
            if (os.path.exists(folder)):
                shutil.rmtree(folder)
            result = result + "Processed " + gameTitle + " Succesfully"
        return result