Exemple #1
0
    def doRename(self):
        """
        Go find files and rename them!
        """

        if self.isDisabled():
            return

        allMovies = self.getMovies(self.conf("download"))

        if allMovies:
            log.debug("Ready to rename some files.")

        for movie in allMovies:

            if movie.get("match"):
                finalDestination = self.renameFiles(movie)

                # Search for trailer & subtitles
                cherrypy.config["cron"]["trailer"].forDirectory(finalDestination["directory"])
                cherrypy.config["cron"]["subtitle"].forDirectory(finalDestination["directory"])

                # Notify XBMC
                xbmc = XBMC()
                xbmc.notify("Downloaded %s (%s)" % (movie["movie"].name, movie["movie"].year))
                xbmc.updateLibrary()

                # Update Metadata
                if self.config.get("Meta", "enabled"):
                    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")

                    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)

            else:
                try:
                    path = movie["path"].split(os.sep)
                    path.extend(["_UNKNOWN_" + path.pop()])
                    shutil.move(movie["path"], os.sep.join(path))
                except IOError:
                    pass

                log.info("No Match found for: %s" % str(movie["info"]["name"]))

        # Cleanup
        if self.conf("cleanup"):
            path = self.conf("download")

            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
                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." % fullFilePath)

                if not root in path:
                    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)
Exemple #2
0
    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 Boxcar
                log.debug('Boxcar')
                boxcar = Boxcar()
                boxcar.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)
Exemple #3
0
    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'])

                # Notify XBMC
                log.debug('XBMC')
                xbmc = XBMC()
                xbmc.notify('Downloaded %s (%s)' % (movie['movie'].name, movie['movie'].year))
                xbmc.updateLibrary()

                # 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)
                        fail = False
                    except xmg.ApiError, e:
                        log.info('XMG TMDB API failure.  Please report to developers. API returned: %s' % e)
                        fail = True
                    if not fail:
                        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)

            else:
                try:
                    path = movie['path'].split(os.sep)
                    path.extend(['_UNKNOWN_' + path.pop()])
                    shutil.move(movie['path'], os.sep.join(path))
                except IOError:
                    pass

                log.info('No Match found for: %s' % str(movie['info']['name']))
Exemple #4
0
    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}
                        )

                        urlOnly = self.config.get("Meta", "urlOnly")
                        x.write_nfo(nfo_location, url=True, xml=False)

                        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())

                # Run post-processing Scripts
                self._run_extra_script(finalDestination)

                # 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 Boxcar
                log.debug("Boxcar")
                boxcar = Boxcar()
                boxcar.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"])

                # Notify Trakt
                log.debug("Trakt")
                trakt = Trakt()
                trakt.notify(movie["movie"].name, movie["movie"].year, movie["movie"].imdb)

            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)
Exemple #5
0
    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)
Exemple #6
0
    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 xmg.ApiError, 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()

            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"]))
Exemple #7
0
    def doRename(self):
        '''
        Go find files and rename them!
        '''

        if self.isDisabled():
            return

        allMovies = self.getMovies(self.conf('download'))

        if allMovies:
            log.debug("Ready to rename some files.")

        for movie in allMovies:

            if movie.get('match'):
                finalDestination = self.renameFiles(movie)

                # Search for trailer & subtitles
                cherrypy.config['cron']['trailer'].forDirectory(finalDestination['directory'])
                cherrypy.config['cron']['subtitle'].forDirectory(finalDestination['directory'])

                #Generate XBMC metadata
                if self.config.get('XBMC', 'metaEnabled'):
                    nfoFileName = self.config.get('XBMC', 'nfoFileName')
                    fanartFileNaming = self.config.get('XBMC', 'fanartFileName')
                    fanartMinHeight = self.config.get('XBMC', 'fanartMinHeight')
                    fanartMinWidth = self.config.get('XBMC', 'fanartMinWidth')
                    posterFileNaming = self.config.get('XBMC', 'posterFileName')
                    posterMinHeight = self.config.get('XBMC', 'posterMinHeight')
                    posterMinWidth = self.config.get('XBMC', 'posterMinWidth')

                    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)

                #Notify XBMC
                if self.config.get('XBMC', 'notify'):
                    xbmc.notifyXBMC('CouchPotato',
                                    'Downloaded %s (%s)' % (movie['movie'].name, movie['movie'].year),
                                    self.config.get('XBMC', 'host'),
                                    self.config.get('XBMC', 'username'),
                                    self.config.get('XBMC', 'password'))
                    log.info('XBMC notification sent to %s' % self.config.get('XBMC', 'host'))


                #Update XBMC Library
                if self.config.get('XBMC', 'updatelibrary'):
                    xbmc.updateLibrary(self.config.get('XBMC', 'host'),
                                       self.config.get('XBMC', 'username'),
                                       self.config.get('XBMC', 'password'))
                    log.info('XBMC library update initiated')

            else:
                try:
                    path = movie['path'].split(os.sep)
                    path.extend(['_UNKNOWN_' + path.pop()])
                    shutil.move(movie['path'], os.sep.join(path))

                except IOError:
                    pass

                log.info('No Match found for: %s' % str(movie['info']['name']))

        # Cleanup
        if self.conf('cleanup'):
            path = self.conf('download')

            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):
                log.debug(subfiles)

                # Stop if something is unpacking
                for ignore in self.ignoredInPath:
                    if ignore in root.lower():
                        break

                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' % fullFilePath)

                if not root in path:
                    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)