Beispiel #1
0
  def move_downloaded(self):

    log.info("move_downloaded")
    dl = DownloadProvider.getProvider()
    to = TorrentProvider.getProvider()

    for series in self.subs.get_series():
      for episode in self.subs.get_episodes(series['tvdb_series']):
        series_name = series['series_name']
        season_number = episode['season_number']
        episode_number = episode['episode_number']

        if episode['state'] != "enqueued":
          continue

        ds = SimpleEpisodeDescriptor(series_name, 
              int(season_number), 
              int(episode_number), episode)
        try:

          f = get_file(ds)

          if len(f) == 1:
            log.info("found file for %s: %s" %(str(ds), repr(f)))
          else:
            raise RuntimeError("file not found")


          # pick first element of result array as file.
          # result will contain only one element anyhow
          f = f[0]

          targetdir = Db.get_config('sorted_dir')
          targetdir = os.path.join(targetdir, clean_fn(series_name), "Season %d" %(season_number,))
          if not os.path.isdir(targetdir):
            os.makedirs(targetdir)

          log.info("created directory")
          extension = os.path.splitext(f[0])[1][1:]
          src = os.path.join(f[1], f[0])
          dst = os.path.join(targetdir, ds.get_file_name(extension))
          log.info("moving file %s to %s" % (src, dst))
          shutil.move(src, dst)

          self.subs.update_episode_state(episode['tvdb_series'], 
              episode['tvdb_episode'], 
              "done")

        except Exception as ex:

          log.warn("failed to find file for %s/%s/%s: %s" % (series_name, season_number, episode_number, format_exc(ex)))
Beispiel #2
0
 def get_file_name(self, extension="avi"):
     return clean_fn(
         "%s S%02dE%02d %s.%s" %
         (self.series_name, self.season_number, self.episode_number,
          self.meta('episode_name', ''), extension))