示例#1
0
文件: utils.py 项目: ercool/pandore
def get_size(start_path, app_code=log.MOVIES):
    total_size = 0
    for dirpath, dirnames, filenames in os.walk(start_path):
        for f in filenames:
            fp = os.path.join(dirpath, f)
            try:
                total_size += os.path.getsize(fp)
            except OSError:
                l = log.logger(app_code)
                l.warning("Broken link found at %s" % (fp), BROKEN_LINK_CODE)
    return total_size
示例#2
0
 def __init__(self):
     self.log = logger('EARSmilter')
示例#3
0
    def process(self, directory, series_bdd, series_imdb):
        self.reset_infos()
        self.path = os.path.abspath(directory).replace(
            settings.FTP_ROOT, '', 1)
        self.filename = os.path.basename(self.path)
        self.season_directory = os.path.dirname(self.path)

        # Check if the episode is already in database
        filter = EpisodeDirectory.objects.filter(location=self.path)
        if filter.exists():
            return filter[0]

        # Extract infos from directory name
        guess = guessit.guess_episode_info(self.filename)
        if 'season' in guess.keys() and 'episodeNumber' in guess.keys():
            self.season_nb = guess['season']
            self.episode_nb = guess['episodeNumber']
        else:
            print self.path
            print 'Error: Episode wrongly named'
            return
        self.quality = guess['screenSize'] if 'screenSize' in guess else 'SD'

        # Create Season
        filter = Season.objects.filter(series=series_bdd,
                                       season_number=self.season_nb)
        if filter.exists():
            self.season = filter[0]
        else:
            self.season = Season.objects.create(series=series_bdd,
                                                season_number=self.season_nb,
                                                number_of_episodes=0)

        filter = SeasonDirectory.objects.filter(season=self.season,
                                                location=self.season_directory,
                                                quality=self.quality)
        if filter.exists():
            self.season_dir = filter[0]
        else:
            self.season_dir = SeasonDirectory.objects.create(
                    season=self.season, location=self.season_directory,
                    quality=self.quality)

        filter = Episode.objects.filter(season=self.season,
                                        episode_number=self.episode_nb)
        if filter.exists():
            self.episode = filter[0]
        else:
            if (self.season_nb in series_imdb.keys() and
                    self.episode_nb in series_imdb[self.season_nb].keys()):
                self.episode = self.episode_processor.process(
                        series_imdb[self.season_nb][self.episode_nb].movieID,
                        self.season, self.episode_nb)
            else:
                print "Episode doesn't exists in IMDb database: %s"%(
                        self.filename)
                l = log.logger(log.SERIES)
                l.error("Episode doesn't exists in IMDb database: %s"%(
                        self.filename), NOT_ON_IMDB_CODE)
                return None

        #Size of the directory in Mo
        #TODO understand why the result is different from du
        self.size = (get_size(directory, log.SERIES) + 500000) // 1000000

        # Finally, create the EpisodeDirectory
        return EpisodeDirectory.objects.create(episode=self.episode,
                                               location=self.path,
                                               quality=self.quality,
                                               size=self.size)