Exemple #1
0
    def _add_metadata(self, show, file_name):
        if file_name is None:
            raise "file_name is not set - you cannot add metadata to None"

        config = Configuration()

        time_string = format_date(config.date_pattern, time.localtime(self.start_time))
        comment = config.comment_pattern % {
            'show': show.name,
            'date': time_string,
            'year': time.strftime('%Y', time.gmtime()),
            'station': show.station.name,
            'link_url': show.get_link_url()
        }

        audio = ID3()
        # See http://www.id3.org/id3v2.3.0 for details about the ID3 tags

        audio.add(TIT2(encoding=2, text=["%s, %s" % (show.name, time_string)]))
        audio.add(TDRC(encoding=2, text=[format_date('%Y-%m-%d %H:%M', self.start_time)]))
        audio.add(TCON(encoding=2, text=[u'Podcast']))
        audio.add(TALB(encoding=2, text=[show.name]))
        audio.add(TLEN(encoding=2, text=[show.duration * 1000]))
        audio.add(TPE1(encoding=2, text=[show.station.name]))
        audio.add(TCOP(encoding=2, text=[show.station.name]))
        audio.add(COMM(encoding=2, lang='eng', desc='desc', text=comment))
        audio.add(TCOM(encoding=2, text=[show.get_link_url()]))
        self._add_logo(show, audio)
        audio.save(file_name)
Exemple #2
0
    def _add_metadata(self, show, file_name):
        if file_name is None:
            raise "file_name is not set - you cannot add metadata to None"

        config = Configuration()

        time_string = format_date(config.date_pattern,
                                  time.localtime(self.start_time))
        comment = config.comment_pattern % {
            'show': show.name,
            'date': time_string,
            'year': time.strftime('%Y', time.gmtime()),
            'station': show.station.name,
            'link_url': show.get_link_url()
        }

        audio = ID3()
        # See http://www.id3.org/id3v2.3.0 for details about the ID3 tags

        audio.add(TIT2(encoding=2, text=["%s, %s" % (show.name, time_string)]))
        audio.add(
            TDRC(encoding=2,
                 text=[format_date('%Y-%m-%d %H:%M', self.start_time)]))
        audio.add(TCON(encoding=2, text=[u'Podcast']))
        audio.add(TALB(encoding=2, text=[show.name]))
        audio.add(TLEN(encoding=2, text=[show.duration * 1000]))
        audio.add(TPE1(encoding=2, text=[show.station.name]))
        audio.add(TCOP(encoding=2, text=[show.station.name]))
        audio.add(COMM(encoding=2, lang='eng', desc='desc', text=comment))
        audio.add(TCOM(encoding=2, text=[show.get_link_url()]))
        self._add_logo(show, audio)
        audio.save(file_name)
Exemple #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)
Exemple #4
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)
Exemple #5
0
    def extract_metadata(self, audiofile):
        """
        Extract the ID3 tags of the file 'audiofile' and store them as object
        attributes.
        """

        self.title = self._get_tag(audiofile, 'TIT2', self.basename[:-4])
        self.show = self._get_tag(audiofile, 'TALB', None)
        if self.show is None:
            self.show = self.basename[:-4]
        else:
            for s in self.config.shows.values():
                if unicode(s.name) == self.show:
                    self.link = s.get_link_url()
                    break
        default_date = format_date(self.config.date_pattern, time.time())
        self.date = self._get_tag(audiofile, 'TDRC', default_date)
        self.artist = self._get_tag(audiofile, 'TPE1', self.show)
        __playtime = self._get_tag(audiofile, 'TLEN', None)
        if __playtime is not None:
            self.playtime = int(__playtime) / 1000
        else:
            self.playtime = 0
        self.copyright = self._get_tag(
            audiofile,
            'TCOP',
            self.artist
        )
        __description = u'Show: %s<br>Episode: %s<br>Copyright: %s %s' % (
            self.show, self.title, self.date[:4], self.copyright)
        self.description = self._get_tag(
            audiofile,
            "COMM:desc:'eng'",
            __description
        )
        self.link = self._get_tag(
            audiofile,
            "TCOM",
            u'http://www.podcast.de/'
        )