예제 #1
0
def _migrate_files_to_episodesdb(config):
    "Method to import files residing in the filesystem into the episodes_db"

    show_mappings = {}
    for show in config.shows.values():
        old_path = os.path.join(
            slugify(show.author),
            slugify(show.name)
        )
        show_mappings[old_path] = show
        show_mappings[show.slug] = show

    import glob

    with database.open('episodes_db') as db:
        episode_filenames = db.keys()
        for filename in glob.glob(os.path.join(config.destination, "*", "*", "*.*")):
            relative_filename = filename.replace(config.destination + '/', '')
            if filename.endswith('.xml'):
                continue

            if relative_filename in episode_filenames:
                continue

            show_slug = os.path.dirname(relative_filename)
            if show_slug not in show_mappings.keys():
                logging.warning(
                    "Could not migrate {} to episode_db".format(filename))
                continue

            logging.info("Migrate {}".format(filename))

            show = show_mappings[show_slug]
            episode = migrate_mediafile_to_episode(config, filename, show)
            db[episode.slug] = episode
예제 #2
0
    def capture(self, show):
        config = Configuration()

        self.log.info(u'capture "%s" from "%s" for %s seconds to %s' %\
                      (show.name, show.station.name, show.duration, config.destination))

        self.start_time = time.time()
        file_name = u"%s/capturadio_%s.mp3" % (config.tempdir, os.getpid())
        try:
            self._write_stream_to_file(show.get_stream_url(), file_name, show.duration)

            time_string = format_date(config.date_pattern, time.localtime(self.start_time))
            target_file = u"%(station)s/%(show)s/%(show)s_%(time)s.mp3" %\
                   { 'station' : show.station.name,
                     'show': show.name,
                     'time': time_string,
                   }
            target_file = os.path.join(config.destination, slugify(target_file))
            final_file_name = self._copy_file_to_destination(file_name, target_file)
            self._add_metadata(show, final_file_name)
            self.start_time = None
        except Exception as e:
            message = "Could not complete capturing, because an exception occured: %s" % e
            self.log.error(message)
            raise e
        finally:
            if os.path.exists(file_name):
                os.remove(file_name)
예제 #3
0
    def capture(self, show):
        config = Configuration()

        self.log.info(u'capture "%s" from "%s" for %s seconds to %s' %\
                      (show.name, show.station.name, show.duration, config.destination))

        self.start_time = time.time()
        file_name = u"%s/capturadio_%s.mp3" % (config.tempdir, os.getpid())
        try:
            self._write_stream_to_file(show.get_stream_url(), file_name,
                                       show.duration)

            time_string = format_date(config.date_pattern,
                                      time.localtime(self.start_time))
            target_file = u"%(station)s/%(show)s/%(show)s_%(time)s.mp3" %\
                   { 'station' : show.station.name,
                     'show': show.name,
                     'time': time_string,
                   }
            target_file = os.path.join(config.destination,
                                       slugify(target_file))
            final_file_name = self._copy_file_to_destination(
                file_name, target_file)
            self._add_metadata(show, final_file_name)
            self.start_time = None
        except Exception as e:
            message = "Could not complete capturing, because an exception occured: %s" % e
            self.log.error(message)
            raise e
        finally:
            if os.path.exists(file_name):
                os.remove(file_name)
예제 #4
0
 def __init__(self, config, id, stream_url, name):
     super(Station, self).__init__(id, name)
     self.stream_url = stream_url
     self.logo_url = config.feed["default_logo_url"]
     self.link_url = config.feed["base_url"]
     self.language = config.feed["language"]
     self.shows = []
     self.date_pattern = config.date_pattern
     self.slug = slugify(self.id)
     self.filename = os.path.join(config.destination, self.slug)
예제 #5
0
파일: entities.py 프로젝트: sit79/podhorst
 def __init__(self, config, id, stream_url, name):
     super(Station, self).__init__(id, name)
     self.stream_url = stream_url
     self.logo_url = config.feed['default_logo_url']
     self.link_url = config.feed['base_url']
     self.language = config.feed['language']
     if 'endurance' in config.feed:
         self.endurance = config.feed['endurance']
     self.shows = []
     self.date_pattern = config.date_pattern
     self.slug = slugify(self.id)
     self.filename = os.path.join(config.destination, self.slug)
예제 #6
0
 def __init__(self, config, id, stream_url, name):
     super(Station, self).__init__(id, name)
     self.stream_url = stream_url
     self.logo_url = config.feed['default_logo_url']
     self.link_url = config.feed['base_url']
     self.language = config.feed['language']
     if 'endurance' in config.feed:
         self.endurance = config.feed['endurance']
     self.shows = []
     self.date_pattern = config.date_pattern
     self.slug = slugify(self.id)
     self.filename = os.path.join(config.destination, self.slug)
예제 #7
0
def config_update(args):
    """Usage:
    recorder config update

Update program settings and episodes database.

    """
    config = Configuration()

    show_mappings = {}
    for show in config.shows.values():
        old_path = os.path.join(slugify(show.author), slugify(show.name))
        show_mappings[old_path] = show
        show_mappings[show.slug] = show

    import glob

    with database.open('episodes_db') as db:
        episode_filenames = db.keys()
        for filename in glob.glob(
                os.path.join(config.destination, "*", "*", "*.*")):
            relative_filename = filename.replace(config.destination + '/', '')
            if filename.endswith('.xml'):
                continue

            if relative_filename in episode_filenames:
                continue

            show_slug = os.path.dirname(relative_filename)
            if show_slug not in show_mappings.keys():
                logging.warning(
                    "Could not migrate {} to episode_db".format(filename))
                continue

            logging.info("Migrate {}".format(filename))

            show = show_mappings[show_slug]
            episode = migrate_mediafile_to_episode(config, filename, show)
            db[episode.slug] = episode
예제 #8
0
    def __init__(self, config, show):
        if not isinstance(show, Show):
            raise TypeError('show has to be of type "Show"')

        super(Episode, self).__init__(show.id)
        self.__dict__ = show.__dict__.copy()
        self.show = show
        self.name = "{}, {}".format(show.name, time.strftime(config.date_pattern, self.starttime))
        self.pubdate = time.strftime("%c", self.starttime)
        self.slug = os.path.join(
            show.slug, "{}_{}.mp3".format(slugify(self.show.id), time.strftime("%Y-%m-%d_%H-%M", self.starttime))
        )
        self.filename = os.path.join(config.destination, self.slug)
        self.duration_string = str(datetime.timedelta(seconds=self.duration))
예제 #9
0
 def __init__(self, config, station, id, name, duration):
     if not isinstance(station, Station):
         raise TypeError('station has to be of type "Station"')
     super(Show, self).__init__(id, name)
     self.station = station
     self.stream_url = station.stream_url
     self.link_url = station.link_url
     self.logo_url = station.logo_url
     self.language = station.language
     self.date_pattern = station.date_pattern
     self.author = station.name
     self.duration = duration
     self.slug = os.path.join(station.slug, slugify(self.id))
     self.filename = os.path.join(config.destination, self.slug)
     station.shows.append(self)
예제 #10
0
파일: entities.py 프로젝트: sit79/podhorst
 def __init__(self, config, station, id, name, duration):
     if not isinstance(station, Station):
         raise TypeError('station has to be of type "Station"')
     super(Show, self).__init__(id, name)
     self.station = station
     self.stream_url = station.stream_url
     self.link_url = station.link_url
     self.logo_url = station.logo_url
     self.language = station.language
     self.date_pattern = station.date_pattern
     self.author = station.name
     self.duration = duration
     self.endurance = station.endurance
     self.slug = os.path.join(station.slug, slugify(self.id))
     self.filename = os.path.join(config.destination, self.slug)
     station.shows.append(self)
예제 #11
0
파일: entities.py 프로젝트: sit79/podhorst
    def __init__(self, config, show):
        if not isinstance(show, Show):
            raise TypeError('show has to be of type "Show"')

        super(Episode, self).__init__(show.id)
        self.__dict__ = show.__dict__.copy()

        self.starttime = time.localtime()
        self.show = show
        self.name = "{}, {}".format(
            show.name, time.strftime(config.date_pattern, self.starttime))
        self.pubdate = time.strftime('%a, %d %b %Y %X %z', self.starttime)
        self.slug = os.path.join(
            show.slug,
            "{}_{}.mp3".format(slugify(self.show.id),
                               time.strftime('%Y-%m-%d_%H-%M',
                                             self.starttime)))
        self.filename = os.path.join(config.destination, self.slug)
        self.duration_string = str(
            datetime.timedelta(seconds=self.duration)).split(".")[0]