예제 #1
0
class Mover(object):

    __dstFolders = {}
    __IgnoreFolders = ('_', '@')
    dst = u''

    def __init__(self, RootDestination):
        #Root Folder has to Contain Folders like this A-D, E-G etc.
        if self.__ContainsGroupFolders(RootDestination) is False:
            self.__dstFolders['root'] = RootDestination
        else:
            self.__GetDstFolders(RootDestination)

        self.log = TNGLog()

    def move(self, src, forceOverwrite):
        if self.__dstFolders.has_key('root'):
            dst = os.path.join(self.__dstFolders['root'],
                               os.path.basename(src))
        else:
            try:
                dst = os.path.join(self.__ChooseDestination(src),
                                   os.path.basename(src))
            except AttributeError:
                self.log.error('Could not move %s' % os.path.basename(src))
                return False

        if os.path.isdir(dst):
            #There exists already a Movie
            #we compare the resolution or size using the metadata of the movie
            try:
                compare = Comparer(src, dst)

                if compare.hasResolution():
                    if compare.item[src]['resolution'] > compare.item[dst][
                            'resolution']:
                        overwrite = True
                    else:
                        overwrite = False
                else:
                    if compare.item[src]['size'] > compare.item[dst]['size']:
                        overwrite = True
                    else:
                        overwrite = False
            except Exception, e:
                overwrite = False
                self.log.error(unicode(e))

            if overwrite or forceOverwrite:
                self.log.info('Overwriting existing Movie : %s' % dst)
                shutil.rmtree(dst)
                shutil.move(src, dst)
            else:
                self.log.warning(
                    'Existing Movie has same or better quality, ignoring it : %s'
                    % os.path.basename(dst))
                return False

        else:
예제 #2
0
파일: mover.py 프로젝트: pheelee/tinynfogen
class Mover(object):

    __dstFolders = {}
    __IgnoreFolders = ('_','@')
    dst = u''

    def __init__(self,RootDestination):
        #Root Folder has to Contain Folders like this A-D, E-G etc.
        if self.__ContainsGroupFolders(RootDestination) is False:
            self.__dstFolders['root'] = RootDestination
        else:
            self.__GetDstFolders(RootDestination)

        self.log = TNGLog()
        
    def move(self,src,forceOverwrite):
        if self.__dstFolders.has_key('root'):
            dst = os.path.join(self.__dstFolders['root'],os.path.basename(src))
        else:
            try:
                dst = os.path.join(self.__ChooseDestination(src),os.path.basename(src))
            except AttributeError:
                self.log.error('Could not move %s' % os.path.basename(src))
                return False
        
        if os.path.isdir(dst):
            #There exists already a Movie
            #we compare the resolution or size using the metadata of the movie
            try:
                compare = Comparer(src,dst)
	
                if compare.hasResolution():
                    if compare.item[src]['resolution'] > compare.item[dst]['resolution']:
                        overwrite = True
                    else:
                        overwrite = False
                else:
                    if compare.item[src]['size'] > compare.item[dst]['size']:
                        overwrite = True
                    else:
                        overwrite = False
            except Exception, e:
                overwrite = False
                self.log.error(unicode(e))
                
            if overwrite or forceOverwrite:
                self.log.info('Overwriting existing Movie : %s' % dst)
                shutil.rmtree(dst)
                shutil.move(src, dst)
            else:
                self.log.warning('Existing Movie has same or better quality, ignoring it : %s' % os.path.basename(dst))
                return False
                
        else:
예제 #3
0
        if os.path.isdir(os.path.join(rootPath, item)) and not item.startswith(filterext):

            log.debug("Processing: %s" % item)

            try:
                #===================================================================
                # Create the Movie Object
                #===================================================================
                movie = Movie(os.path.join(rootPath, item), args.language, config.get('TMDB', 'apikey'))
                #===================================================================
                # Rename the Folder and Files
                #===================================================================
                movie.rename(args.forceRename)

            except Exception as e:
                log.error(str(e))
                continue

            #===================================================================
            # Prepare NFO name and check if already created by tinynfogen
            #===================================================================
            if args.globalNFOName:
                movie.newFiles['nfo'][0] = os.path.join(movie.path, args.globalNFOName)

            movie.NFO = NFO(movie.newFiles['nfo'][0], movie.infos)

            #===================================================================
            # Remove unwanted files from directory
            #===================================================================
            movie.clean(('srf', 'sub', 'srr', 'sfv', 'sft', 'jpg', 'tbn', 'idx', 'nfo', 'html', 'url', 'par2', 'rar'))
            log.debug('Cleaned files: %s' % (movie.Name + movie.Year))
예제 #4
0
파일: movie.py 프로젝트: pheelee/tinynfogen
class tmdb():

    urls = {
        'search': '/3/search/movie?api_key=%s&query=',
        'detail': '/3/movie/%s?api_key=%s&language=%s',
        'config': '/3/configuration?api_key=%s'
    }

    headers = {"Accept": "application/json"}

    apikey = ''
    host = 'http://api.themoviedb.org'
    port = 80

    def __init__(self, apikey):
        try:
            self.apikey = apikey
            self.log = TNGLog()
            self.urls['images'] = self.__GetImageURL() + 'original'
        except Exception as e:
            self.log.error(unicode(e))
            raise

    def search(self, string):
        """
        :param string: movie name
        :return: imdb id
        """
        self.log.debug('Search String:%s' % string)
        url = self.host + self.urls[
            'search'] % self.apikey + self.__CreateQuery(string)
        self.log.debug('Search URL:%s' % url)
        request = urllib2.Request(url, headers=self.headers)
        resp = urllib2.urlopen(request)
        data = resp.read()
        result = json.loads(data)

        if result['total_results'] == 1:
            return result['results'][0]['id']
        elif result['total_results'] > 1:
            for res in result['results']:
                if res['original_title'] == string:
                    return res['id']
                elif res['title'] == string:
                    return res['id']
        return False

    def GetMovieDetails(self, movieID, lang):
        data = ''
        url = self.host + self.urls['detail'] % (movieID, self.apikey, lang)
        self.log.debug('Search Request: %s' % url)
        try:
            request = urllib2.Request(url, headers=self.headers)
            resp = urllib2.urlopen(request)
            data = resp.read()
        except urllib2.HTTPError:
            self.log.error('HTTPError (searchURL): %s' % url)
        finally:
            if data != '':
                return data
            else:
                return False

    @staticmethod
    def __CreateQuery(string):
        return string.replace(' ', '+').replace('(', '').replace(')', '')

    def __GetImageURL(self):
        url = self.host + self.urls['config'] % self.apikey
        request = urllib2.Request(url, headers=self.headers)
        resp = urllib2.urlopen(request)
        data = json.loads(resp.read())
        return data['images']['base_url']
예제 #5
0
            log.debug("Processing: %s" % item)

            try:
                #===================================================================
                # Create the Movie Object
                #===================================================================
                movie = Movie(os.path.join(rootPath, item), args.language,
                              config.get('TMDB', 'apikey'))
                #===================================================================
                # Rename the Folder and Files
                #===================================================================
                movie.rename(args.forceRename)

            except Exception as e:
                log.error(str(e))
                continue

            #===================================================================
            # Prepare NFO name and check if already created by tinynfogen
            #===================================================================
            if args.globalNFOName:
                movie.newFiles['nfo'][0] = os.path.join(
                    movie.path, args.globalNFOName)

            movie.NFO = NFO(movie.newFiles['nfo'][0], movie.infos)

            #===================================================================
            # Remove unwanted files from directory
            #===================================================================
            movie.clean(('srf', 'sub', 'srr', 'sfv', 'sft', 'jpg', 'tbn',
예제 #6
0
파일: movie.py 프로젝트: pheelee/tinynfogen
class tmdb():
    
    urls        = {
                   'search':'/3/search/movie?api_key=%s&query=',
                   'detail':'/3/movie/%s?api_key=%s&language=%s',
                   'config':'/3/configuration?api_key=%s'
                   }
    
    headers = {"Accept": "application/json"}
    
    apikey      = ''
    host        = 'http://api.themoviedb.org'
    port        = 80
    
    def __init__(self,apikey):
        try:
            self.apikey = apikey
            self.log = TNGLog()
            self.urls['images'] = self.__GetImageURL() + 'original'
        except Exception as e:
            self.log.error(unicode(e))
            raise

    def search(self, string):
        """
        :param string: movie name
        :return: imdb id
        """
        self.log.debug('Search String:%s' % string)
        url = self.host + self.urls['search'] % self.apikey + self.__CreateQuery(string)
        self.log.debug('Search URL:%s' % url)
        request = urllib2.Request(url, headers=self.headers)
        resp = urllib2.urlopen(request)
        data = resp.read()
        result = json.loads(data)

        if result['total_results'] == 1:
            return result['results'][0]['id']
        elif result['total_results'] > 1:
            for res in result['results']:
                if res['original_title'] == string:
                    return res['id']
                elif res['title'] == string:
                    return res['id']
        return False

    def GetMovieDetails(self, movieID, lang):
        data = ''
        url = self.host + self.urls['detail'] % (movieID, self.apikey, lang)
        self.log.debug('Search Request: %s' % url)
        try:
            request = urllib2.Request(url, headers=self.headers)
            resp = urllib2.urlopen(request)
            data = resp.read()
        except urllib2.HTTPError:
            self.log.error('HTTPError (searchURL): %s' % url)
        finally:   
            if data != '':
                return data
            else:
                return False

    @staticmethod
    def __CreateQuery(string):
        return string.replace(' ','+').replace('(','').replace(')','')
    
    def __GetImageURL(self):
        url = self.host + self.urls['config'] % self.apikey
        request = urllib2.Request(url, headers=self.headers)
        resp = urllib2.urlopen(request)
        data = json.loads(resp.read())
        return data['images']['base_url']