def testXBMC(self, **data): xbmc = XBMC() xbmc.test(data.get('XBMC.host'), data.get('XBMC.username'), data.get('XBMC.password')) return ''
def _checkMovieExists(self, movie): if cherrypy.config.get('config').get('XBMC', 'dbpath'): dbfile = None for root, dirs, files in os.walk( cherrypy.config.get('config').get('XBMC', 'dbpath')): for file in files: if file.startswith('MyVideos'): dbfile = os.path.join(root, file) if dbfile: #------Opening connection to XBMC DB------ connXbmc = MySqlite.connect(dbfile) if connXbmc: log.debug('Checking if movie exists in XBMC by IMDB id:' + movie.imdb) connXbmc.row_factory = MySqlite.Row cXbmc = connXbmc.cursor() cXbmc.execute('select c09 from movie where c09="' + movie.imdb + '"') #------End of Opening connection to XBMC DB------ inXBMC = False for rowXbmc in cXbmc: # do a final check just to be sure log.debug('Found in XBMC:' + rowXbmc["c09"]) if movie.imdb == rowXbmc["c09"]: inXBMC = True else: inXBMC = False cXbmc.close() if inXBMC: log.info('Movie already exists in XBMC, skipping.') return True else: log.info( 'Could not connect to the XBMC database at ' + cherrypy.config.get('config').get('XBMC', 'dbpath')) else: log.info('Could not find the XBMC MyVideos db at ' + cherrypy.config.get('config').get('XBMC', 'dbpath')) xbmc = XBMC() xbmcResults = xbmc.queryVideoDatabase( 'select c09 from movie where c09="' + movie.imdb + '"') if xbmcResults: for xmbcResult in xbmcResults: c09 = xmbcResult.replace("<field>", "").replace("</field>", "").strip() if c09 == movie.imdb: log.info( 'Movie already exists in XBMC (web API call), skipping.' ) return True # log.info("'%s' %s" % (c09, c09==movie.imdb)) return False
def _checkMovieExists(self, movie): if cherrypy.config.get('config').get('XBMC', 'dbpath'): dbfile = None for root, dirs, files in os.walk(cherrypy.config.get('config').get('XBMC', 'dbpath')): for file in files: if file.startswith('MyVideos'): dbfile = os.path.join(root, file) if dbfile: #------Opening connection to XBMC DB------ connXbmc = MySqlite.connect(dbfile) if connXbmc: log.debug('Checking if movie exists in XBMC by IMDB id:' + movie.imdb) connXbmc.row_factory = MySqlite.Row cXbmc = connXbmc.cursor() cXbmc.execute('select c09 from movie where c09="' + movie.imdb + '"') #------End of Opening connection to XBMC DB------ inXBMC = False for rowXbmc in cXbmc: # do a final check just to be sure log.debug('Found in XBMC:' + rowXbmc["c09"]) if movie.imdb == rowXbmc["c09"]: inXBMC = True else: inXBMC = False cXbmc.close() if inXBMC: log.info('Movie already exists in XBMC, skipping.') return True else: log.info('Could not connect to the XBMC database at ' + cherrypy.config.get('config').get('XBMC', 'dbpath')) else: log.info('Could not find the XBMC MyVideos db at ' + cherrypy.config.get('config').get('XBMC', 'dbpath')) if cherrypy.config.get('config').get('XBMC', 'useWebAPIExistingCheck'): xbmc = XBMC() xbmcResultsHosts = xbmc.queryVideoDatabase('select c09 from movie where c09="' + movie.imdb + '"') if xbmcResultsHosts: for xmbcResults in xbmcResultsHosts: for xmbcResult in [x.strip() for x in xmbcResults.strip().split('\n')]: if xmbcResult == "": continue c09 = xmbcResult.replace("<record><field>", "").replace("</field></record>", "").replace("<field>", "").replace("</field>", "").strip() if c09==movie.imdb: log.info('Movie already exists in XBMC (web API call), skipping.') return True return False
def _checkMovieExists(self, movie, qualityId): if cherrypy.config.get('config').get('XBMC', 'dbpath'): dbfile = None for root, dirs, files in os.walk( cherrypy.config.get('config').get('XBMC', 'dbpath')): for file in files: if file.startswith('MyVideos'): dbfile = os.path.join(root, file) if dbfile: #------Opening connection to XBMC DB------ connXbmc = MySqlite.connect(dbfile) if connXbmc: log.debug('Checking if movie exists in XBMC by IMDB id:' + movie.imdb) connXbmc.row_factory = MySqlite.Row cXbmc = connXbmc.cursor() #sqlQuery = 'select c09 from movie where c09="' + movie.imdb + '"' sqlQuery = self._generateSQLQuery(movie) cXbmc.execute(sqlQuery) #------End of Opening connection to XBMC DB------ inXBMC = False for rowXbmc in cXbmc: # do a final check just to be sure log.debug('Found in XBMC:' + rowXbmc["c09"]) if movie.imdb == rowXbmc["c09"]: inXBMC = True else: inXBMC = False cXbmc.close() if inXBMC: log.info('Movie already exists in XBMC, skipping.') return True else: log.info( 'Could not connect to the XBMC database at ' + cherrypy.config.get('config').get('XBMC', 'dbpath')) else: log.info('Could not find the XBMC MyVideos db at ' + cherrypy.config.get('config').get('XBMC', 'dbpath')) if cherrypy.config.get('config').get('XBMC', 'useWebAPIExistingCheck'): quality = Db.query(QualityTemplate).filter_by(id=qualityId).one() acceptableQualities = [ x.type for x in filter(lambda x: x.markComplete, quality.types) ] log.debug( "acceptableQualities = %s" % acceptableQualities ) # log.info(["%s %s %s %s %s" % (x.id, x.markComplete, x.order, x.quality, x.type) for x in sorted(quality.types, key=lambda x:x.order)]) xbmc = XBMC() sqlQuery = self._generateSQLQuery(movie) xbmcResultsHosts = xbmc.queryVideoDatabase(sqlQuery) if xbmcResultsHosts: for xmbcResults in xbmcResultsHosts: records = xmbcResults.strip().split("<record>") for xmbcResult in records: xmbcResult = xmbcResult.replace("</record>", "") if xmbcResult == "": continue fields = [ x.replace("<field>", "") for x in filter(lambda x: x.startswith("<field>"), xmbcResult.split("</field>")) ] log.debug("fields = %s" % fields) if len(fields) < 5: log.error("Invalid response: %s" % xmbcResult) continue imdbId, strVideoCodec, fVideoAspect, iVideoWidth, iVideoHeight = fields[: 5] if imdbId == movie.imdb: existingMovieQuality = self._classifyQuality( strVideoCodec, fVideoAspect, iVideoWidth, iVideoHeight) if existingMovieQuality == "Unknown": log.info( "Unable to classify movie: strVideoCodec=%s, fVideoAspect=%s, iVideoWidth=%s, iVideoHeight=%s" % (strVideoCodec, fVideoAspect, iVideoWidth, iVideoHeight)) treatUnknownAs = cherrypy.config.get('config').get( 'XBMC', 'unknown') if treatUnknownAs and treatUnknownAs != '': existingMovieQuality = treatUnknownAs if existingMovieQuality in acceptableQualities: log.info( 'Movie already exists in XBMC (web API call), with acceptable quality (%s), skipping.' % (existingMovieQuality)) return True else: log.info( 'Movie already exists in XBMC (web API call), but quality (%s) incorrect (require: %s).' % (existingMovieQuality, acceptableQualities)) return False
def _search(self, movie, force=False): # Stop caching ffs! Db.expire_all() # Check release date and search for appropriate qualities preReleaseSearch = False dvdReleaseSearch = False now = int(time.time()) # Search all if ETA is unknow, but try update ETA for next time. log.debug('Calculate ETA') checkETA = False if not movie.eta: checkETA = True preReleaseSearch = True dvdReleaseSearch = True else: # Prerelease 1 week before theaters if movie.eta.theater <= now + 604800: preReleaseSearch = True # dvdRelease 6 weeks before dvd release if movie.eta.dvd <= now + 3628800: preReleaseSearch = True dvdReleaseSearch = True # Dvd date is unknown but movie is in theater already if movie.eta.dvd == 0 and movie.eta.theater > now: dvdReleaseSearch = False # Force ETA check if movie.eta.lastCheck < now: checkETA = True # Minimal week interval for ETA check if checkETA and self.config.get('MovieETA', 'enabled'): cherrypy.config.get('searchers').get('etaQueue').put( {'id': movie.id}) for queue in movie.queue: # Movie already found, don't search further if queue.completed: log.debug( '%s already completed for "%s". Not searching for any qualities below.' % (queue.qualityType, movie.name)) return True # only search for active and not completed, minimal 1 min since last search if queue.active and not queue.completed and not self.abort and not self.stop: #skip if no search is set log.debug('Needs a search?') if (not ((preReleaseSearch and queue.qualityType in Qualities.preReleases) or (dvdReleaseSearch and not queue.qualityType in Qualities.preReleases)) ) and not queue.lastCheck < (now - int( self.config.get('Intervals', 'search')) * 7200): continue log.debug('Start searching for movie: %s' % movie.name) highest = self.provider.find(movie, queue) log.debug('End searching for movie: %s' % movie.name) #send highest to SABnzbd & mark as snatched if highest: log.debug('Found highest') #update what I found queue.name = latinToAscii(highest.name) queue.link = highest.detailUrl Db.flush() waitFor = queue.waitFor * (60 * 60 * 24) if queue.markComplete or ( not queue.markComplete and highest.date + waitFor < time.time()): time.sleep(10) # Give these APIs air! if self.config.get( 'NZB', 'sendTo' ) == 'Sabnzbd' and highest.type == 'nzb': success = self.sabNzbd.send(highest, movie.imdb) elif self.config.get( 'NZB', 'sendTo' ) == 'Nzbget' and highest.type == 'nzb': success = self.nzbGet.send(highest) elif self.config.get( 'Torrents', 'sendTo' ) == 'Transmission' and highest.type == 'torrent': success = self.transmission.send( highest, movie.imdb) else: success = self.blackHole(highest) else: success = False log.info('Found %s but waiting for %d hours.' % (highest.name, ((highest.date + waitFor) - time.time()) / (60 * 60))) # Set status if success: log.debug('Success') movie.status = u'snatched' if queue.markComplete else u'waiting' movie.dateChanged = datetime.datetime.now() queue.lastCheck = now queue.completed = True Db.flush() # Add to history h = History() h.movie = movie.id h.value = str(highest.id) + '-' + str(highest.size) h.status = u'snatched' Db.add(h) Db.flush() # Notify PROWL if self.config.get('PROWL', 'onSnatch'): log.debug('PROWL') prowl = PROWL() prowl.notify(highest.name, 'Download Started') # Notify XBMC if self.config.get('XBMC', 'onSnatch'): log.debug('XBMC') xbmc = XBMC() xbmc.notify('Snatched %s' % highest.name) # Notify GROWL if self.config.get('GROWL', 'onSnatch'): log.debug('GROWL') growl = GROWL() growl.notify('Snatched %s' % highest.name, 'Download Started') # Notify Notifo if self.config.get('Notifo', 'onSnatch'): log.debug('Notifo') notifo = Notifo() notifo.notify('%s' % highest.name, "Snatched:") # Notify SNS if self.config.get('SNS', 'onSnatch'): log.debug('SNS') sns = SNS() sns.notify('%s' % highest.name, "Snatched:") # Notify Boxcar if self.config.get('Boxcar', 'onSnatch'): log.debug('Boxcar') boxcar = Boxcar() boxcar.notify('%s' % highest.name, "Snatched:") # Notify NotifyMyAndroid if self.config.get('NMA', 'onSnatch'): log.debug('NotifyMyAndroid') nma = NMA() nma.notify('Download Started', 'Snatched %s' % highest.name) # Notify NotifyMyWindowsPhone if self.config.get('NMWP', 'onSnatch'): log.debug('NotifyMyWindowsPhone') nmwp = NMWP() nmwp.notify('Download Started', 'Snatched %s' % highest.name) # Notify Twitter if self.config.get('Twitter', 'onSnatch'): log.debug('Twitter') twitter = Twitter() twitter.notify('Download Started', 'Snatched %s' % highest.name) return True queue.lastCheck = now Db.flush() return False
def testXBMC(self, **data): xbmc = XBMC() xbmc.test(data.get("XBMC.host"), data.get("XBMC.username"), data.get("XBMC.password")) return ""
def doRename(self): ''' Go find files and rename them! ''' log.debug('Starting renaming') if self.isDisabled(): log.debug('Renaming is disabled') return allMovies = self.getMovies(self.conf('download')) log.debug('Movies: %s' % allMovies) if allMovies: log.debug("Ready to rename some files.") for movie in allMovies: if movie.get('match'): log.debug('self.renameFiles(movie)') finalDestination = self.renameFiles(movie) # Search for trailer & subtitles log.debug('crons') cherrypy.config['cron']['trailer'].forDirectory(finalDestination['directory']) cherrypy.config['cron']['subtitle'].forDirectory(finalDestination['directory']) # Update Metadata if self.config.get('Meta', 'enabled'): log.debug('metadata') nfoFileName = self.config.get('Meta', 'nfoFileName') fanartFileNaming = self.config.get('Meta', 'fanartFileName') fanartMinHeight = self.config.get('Meta', 'fanartMinHeight') fanartMinWidth = self.config.get('Meta', 'fanartMinWidth') posterFileNaming = self.config.get('Meta', 'posterFileName') posterMinHeight = self.config.get('Meta', 'posterMinHeight') posterMinWidth = self.config.get('Meta', 'posterMinWidth') try: x = xmg.MetaGen(movie['movie'].imdb) fanartOrigExt = os.path.splitext(x.get_fanart_url(fanartMinHeight, fanartMinWidth))[-1][1:] posterOrigExt = os.path.splitext(x.get_poster_url(posterMinHeight, posterMinWidth))[-1][1:] nfo_location = os.path.join(finalDestination['directory'], self.genMetaFileName(movie, nfoFileName)) fanart_filename = self.genMetaFileName(movie, fanartFileNaming, add_tags = {'orig_ext': fanartOrigExt}) poster_filename = self.genMetaFileName(movie, posterFileNaming, add_tags = {'orig_ext': posterOrigExt}) x.write_nfo(nfo_location) x.write_fanart(fanart_filename, finalDestination['directory'], fanartMinHeight, fanartMinWidth) x.write_poster(poster_filename, finalDestination['directory'], posterMinHeight, posterMinWidth) log.info('XBMC metainfo for imdbid, %s, generated' % movie['movie'].imdb) except Exception, e: log.error('XMG TMDB API failure. Please report to developers. API returned: %s' % e) log.error(traceback.format_exc()) # Notify XBMC log.debug('XBMC') xbmc = XBMC() xbmc.notify('Downloaded %s (%s)' % (movie['movie'].name, movie['movie'].year)) xbmc.updateLibrary() # Notify NMJ log.debug('NMJ') nmj = NMJ() nmj.updateLibrary() # Notify PLEX log.debug('PLEX') plex = PLEX() plex.updateLibrary() # Notify PROWL log.debug('PROWL') prowl = PROWL() prowl.notify('Downloaded %s (%s)' % (movie['movie'].name, movie['movie'].year), 'Download Complete') # Notify GROWL log.debug('GROWL') growl = GROWL() growl.notify('Downloaded %s (%s)' % (movie['movie'].name, movie['movie'].year), 'Download Complete') # Notify Notifo log.debug('Notifo') notifo = Notifo() notifo.notify('%s (%s)' % (movie['movie'].name, movie['movie'].year), "Downloaded:") #Notify NotifyMyAndroid log.debug('NotifyMyAndroid') nma = NMA() nma.notify('Download Complete', 'Downloaded %s (%s)' % (movie['movie'].name, movie['movie'].year)) # Notify Twitter log.debug('Twitter') twitter = Twitter() twitter.notify('Download Finished', 'Downloaded %s (%s)' % (movie['movie'].name, movie['movie'].year)) # Notify Synoindex log.debug('Synoindex') synoindex = Synoindex() synoindex.addToLibrary(finalDestination['directory']) else: path = movie['path'].split(os.sep) path.extend(['_UNKNOWN_' + path.pop()]) target = os.sep.join(path) _move(movie['path'], target) log.info('No Match found for: %s' % str(movie['info']['name'])) #Cleanup if self.conf('cleanup'): log.debug('cleanup') path = movie['path'] # if self.conf('destination') == path: # log.error('Download folder and movie destination shouldn\'t be the same. Change it in Settings >> Renaming.') # return for root, subfiles, filenames in os.walk(path): skip = False # Stop if something is in ignored list for ignore in self.ignoredInPath: if ignore in root.lower(): skip = True # Ignore full directory names for dir in os.path.split(root): if dir in self.ignoreNames: skip = True # ignore if the current dir is the blackhole if root in self.conf('download'): skip = True if skip: continue for filename in filenames: fullFilePath = os.path.join(root, filename) fileSize = os.path.getsize(fullFilePath) if fileSize < 157286400: try: os.remove(fullFilePath) log.info('Removing file %s.' % fullFilePath) except OSError: log.error('Couldn\'t remove file %s. Too large.' % fullFilePath) try: os.rmdir(root) log.info('Removing dir: %s in download dir.' % root) except OSError: log.error("Tried to clean-up download folder, but '%s' isn't empty." % root)
def _checkMovieExists(self, movie, qualityId): if cherrypy.config.get('config').get('XBMC', 'dbpath'): dbfile = None for root, dirs, files in os.walk(cherrypy.config.get('config').get('XBMC', 'dbpath')): for file in files: if file.startswith('MyVideos'): dbfile = os.path.join(root, file) if dbfile: #------Opening connection to XBMC DB------ connXbmc = MySqlite.connect(dbfile) if connXbmc: log.debug('Checking if movie exists in XBMC by IMDB id:' + movie.imdb) connXbmc.row_factory = MySqlite.Row cXbmc = connXbmc.cursor() #sqlQuery = 'select c09 from movie where c09="' + movie.imdb + '"' sqlQuery = self._generateSQLQuery(movie) cXbmc.execute(sqlQuery) #------End of Opening connection to XBMC DB------ inXBMC = False for rowXbmc in cXbmc: # do a final check just to be sure log.debug('Found in XBMC:' + rowXbmc["c09"]) if movie.imdb == rowXbmc["c09"]: inXBMC = True else: inXBMC = False cXbmc.close() if inXBMC: log.info('Movie already exists in XBMC, skipping.') return True else: log.info('Could not connect to the XBMC database at ' + cherrypy.config.get('config').get('XBMC', 'dbpath')) else: log.info('Could not find the XBMC MyVideos db at ' + cherrypy.config.get('config').get('XBMC', 'dbpath')) if cherrypy.config.get('config').get('XBMC', 'useWebAPIExistingCheck'): quality = Db.query(QualityTemplate).filter_by(id = qualityId).one() acceptableQualities = [x.type for x in filter(lambda x: x.markComplete, quality.types)] log.debug("acceptableQualities = %s" % acceptableQualities) # log.info(["%s %s %s %s %s" % (x.id, x.markComplete, x.order, x.quality, x.type) for x in sorted(quality.types, key=lambda x:x.order)]) xbmc = XBMC() sqlQuery = self._generateSQLQuery(movie) xbmcResultsHosts = xbmc.queryVideoDatabase(sqlQuery) if xbmcResultsHosts: for xmbcResults in xbmcResultsHosts: records = xmbcResults.strip().split("<record>") for xmbcResult in records: xmbcResult = xmbcResult.replace("</record>", "") if xmbcResult == "": continue fields = [x.replace("<field>", "") for x in filter(lambda x: x.startswith("<field>"), xmbcResult.split("</field>"))] log.debug("fields = %s" % fields) if len(fields) < 5: log.error("Invalid response: %s" % xmbcResult) continue imdbId, strVideoCodec, fVideoAspect, iVideoWidth, iVideoHeight = fields[:5] if imdbId==movie.imdb: existingMovieQuality = self._classifyQuality(strVideoCodec, fVideoAspect, iVideoWidth, iVideoHeight) if existingMovieQuality == "Unknown": log.info("Unable to classify movie: strVideoCodec=%s, fVideoAspect=%s, iVideoWidth=%s, iVideoHeight=%s" % (strVideoCodec, fVideoAspect, iVideoWidth, iVideoHeight)) treatUnknownAs = cherrypy.config.get('config').get('XBMC', 'unknown') if treatUnknownAs and treatUnknownAs != '': existingMovieQuality = treatUnknownAs if existingMovieQuality in acceptableQualities: log.info('Movie already exists in XBMC (web API call), with acceptable quality (%s), skipping.' % (existingMovieQuality)) return True else: log.info('Movie already exists in XBMC (web API call), but quality (%s) incorrect (require: %s).' % (existingMovieQuality, acceptableQualities)) return False
def _checkMovieExists(self, movie): if cherrypy.config.get('config').get('XBMC', 'dbpath'): dbfile = None for root, dirs, files in os.walk( cherrypy.config.get('config').get('XBMC', 'dbpath')): for file in files: if file.startswith('MyVideos'): dbfile = os.path.join(root, file) if dbfile: #------Opening connection to XBMC DB------ connXbmc = MySqlite.connect(dbfile) if connXbmc: log.debug('Checking if movie exists in XBMC by IMDB id:' + movie.imdb) connXbmc.row_factory = MySqlite.Row cXbmc = connXbmc.cursor() #sqlQuery = 'select c09 from movie where c09="' + movie.imdb + '"' sqlQuery = self._generateSQLQuery(movie) cXbmc.execute(sqlQuery) #------End of Opening connection to XBMC DB------ inXBMC = False for rowXbmc in cXbmc: # do a final check just to be sure log.debug('Found in XBMC:' + rowXbmc["c09"]) if movie.imdb == rowXbmc["c09"]: inXBMC = True else: inXBMC = False cXbmc.close() if inXBMC: log.info('Movie already exists in XBMC, skipping.') return True else: log.info( 'Could not connect to the XBMC database at ' + cherrypy.config.get('config').get('XBMC', 'dbpath')) else: log.info('Could not find the XBMC MyVideos db at ' + cherrypy.config.get('config').get('XBMC', 'dbpath')) if cherrypy.config.get('config').get('XBMC', 'useWebAPIExistingCheck'): xbmc = XBMC() #sqlQuery = 'select c09 from movie where c09="' + movie.imdb + '"' sqlQuery = self._generateSQLQuery(movie) xbmcResultsHosts = xbmc.queryVideoDatabase(sqlQuery) if xbmcResultsHosts: for xmbcResults in xbmcResultsHosts: records = xmbcResults.strip().split("<record>") for xmbcResult in records: # xmbcResult = xmbcResult.strip() xmbcResult = xmbcResult.replace("</record>", "") # xmbcResult = xmbcResult.strip() if xmbcResult == "": continue fields = filter(lambda x: x != "", [ field.replace("</field>", "") for field in xmbcResult.split("<field>") ]) log.debug("fields = %s" % fields) c09 = fields[0] if c09 == movie.imdb: log.info( 'Movie already exists in XBMC (web API call), skipping.' ) return True return False