Beispiel #1
0
def _update_process_step(info):

    chans = info.vdr.channels.values()
    for c in chans:
        if c.id in info.exclude_channels: continue

        if string.lower(info.limit_channels) == 'epg' and not c.in_epg:
            continue
        elif string.lower(info.limit_channels) == 'conf' and not c.in_conf:
            continue
        elif string.lower(info.limit_channels) == 'both' and \
                 not (c.in_conf and c.in_epg):
            continue

        if info.access_by == 'name':
            access_id = c.name
        elif info.access_by == 'rid':
            access_id = c.rid
        else:
            access_id = c.sid

        log.info('Adding channel: %s as %s' % (c.id, access_id))

        chan_db_id = info.epg.add_channel(
            tuner_id=strutils.str_to_unicode(access_id),
            name=strutils.str_to_unicode(c.name),
            long_name=None)

        for e in c.events:
            subtitle = e.subtitle
            if not subtitle:
                subtitle = ''
            desc = e.desc
            if not desc:
                desc = ''

            info.epg.add_program(chan_db_id,
                                 e.start,
                                 int(e.start + e.dur),
                                 strutils.str_to_unicode(e.title),
                                 desc=strutils.str_to_unicode(desc))
    return False
Beispiel #2
0
def _update_process_step(info):

    chans = info.vdr.channels.values()
    for c in chans:
        if c.id in info.exclude_channels:  continue

        if string.lower(info.limit_channels) == 'epg' and not c.in_epg:
            continue
        elif string.lower(info.limit_channels) == 'conf' and not c.in_conf:
            continue
        elif string.lower(info.limit_channels) == 'both' and \
                 not (c.in_conf and c.in_epg):
            continue

        if info.access_by == 'name':
            access_id = c.name
        elif info.access_by == 'rid':
            access_id = c.rid
        else:
            access_id = c.sid

        log.info('Adding channel: %s as %s' % (c.id, access_id))

        chan_db_id = info.epg.add_channel(tuner_id=strutils.str_to_unicode(access_id),
                                          name=strutils.str_to_unicode(c.name),
                                          long_name=None)

        for e in c.events:
            subtitle = e.subtitle
            if not subtitle:
                subtitle = ''
            desc = e.desc
            if not desc:
                desc = ''

            info.epg.add_program(chan_db_id, e.start, int(e.start+e.dur),
                                 strutils.str_to_unicode(e.title),
                                 desc=strutils.str_to_unicode(desc))
    return False
Beispiel #3
0
Datei: mp3.py Projekt: clones/kaa
    def __init__(self, file, tagVersion = eyeD3_tag.ID3_ANY_VERSION):
        core.Music.__init__(self)
        self.fileName = file.name;
        self.codec = 0x0055 # fourcc code of mp3
        self.mime = 'audio/mpeg'

        #if not eyeD3_tag.isMp3File(file.name):
        #   raise core.ParseError()

        id3 = None
        try:
            id3 = eyeD3_tag.Mp3AudioFile(file.name)
        except eyeD3_tag.InvalidAudioFormatException:
            # File is not an MP3
            raise core.ParseError()
        except eyeD3_tag.TagException:
            # The MP3 tag decoder crashed, assume the file is still
            # MP3 and try to play it anyway
            if log.level < 30:
                log.exception('mp3 tag parsing %s failed!' % file.name)
        except Exception:
            # The MP3 tag decoder crashed, assume the file is still
            # MP3 and try to play it anyway
            if log.level < 30:
                log.exception('mp3 tag parsing %s failed!' % file.name)

        if not id3:
            # let's take a look at the header
            s = file.read(4096)
            if not s[:3] == 'ID3':
                # no id3 tag header, not good
                if not re.compile(r'0*\xFF\xFB\xB0\x04$').search(s):
                    # again, not good
                    if not re.compile(r'0*\xFF\xFA\xB0\x04$').search(s):
                        # that's it, it is no mp3 at all
                        raise core.ParseError()

        try:
            if id3 and id3.tag:
                log.debug(id3.tag.frames)

                # Grip unicode bug workaround: Grip stores text data as UTF-8
                # and flags it as latin-1.  This workaround tries to decode
                # these strings as utf-8 instead.
                # http://sourceforge.net/tracker/index.php?func=detail&aid=1196919&group_id=3714&atid=103714
                for frame in id3.tag.frames['COMM']:
                    if "created by grip" not in frame.comment.lower():
                        continue
                    for frame in id3.tag.frames:
                        if hasattr(frame, "text") and isinstance(frame.text, unicode):
                            try:
                                frame.text = frame.text.encode('latin-1').decode('utf-8')
                            except UnicodeError:
                                pass

                for k, var in MP3_INFO_TABLE.items():
                    if id3.tag.frames[k]:
                        self._set(var,id3.tag.frames[k][0].text)
                if id3.tag.frames['APIC']:
                    pic = id3.tag.frames['APIC'][0]
                    if pic.imageData:
                        self.thumbnail = pic.imageData
                if id3.tag.getYear():
                    self.userdate = id3.tag.getYear()
                tab = {}
                for f in id3.tag.frames:
                    if f.__class__ is eyeD3_frames.TextFrame:
                        tab[f.header.id] = f.text
                    elif f.__class__ is eyeD3_frames.UserTextFrame:
                        #userTextFrames : debug: id  starts with _
                        self._set('_'+f.description,f.text)
                        tab['_'+f.description] = f.text
                    elif f.__class__ is eyeD3_frames.DateFrame:
                        tab[f.header.id] = f.date_str
                    elif f.__class__ is eyeD3_frames.CommentFrame:
                        tab[f.header.id] = f.comment
                        self.comment = str_to_unicode(f.comment)
                    elif f.__class__ is eyeD3_frames.URLFrame:
                        tab[f.header.id] = f.url
                    elif f.__class__ is eyeD3_frames.UserURLFrame:
                        tab[f.header.id] = f.url
                    elif f.__class__ is eyeD3_frames.ImageFrame:
                        tab[f.header.id] = f
                    else:
                        log.debug(f.__class__)
                self._appendtable('id3v2', tab)

                if id3.tag.frames['TCON']:
                    genre = None
                    tcon = id3.tag.frames['TCON'][0].text
                    # TODO: could handle id3v2 genre refinements.
                    try:
                        # Assume integer.
                        genre = int(tcon)
                    except ValueError:
                        # Nope, maybe it's in '(N)' format.
                        try:
                            genre = int(tcon[1:tcon.find(')')])
                        except ValueError:
                            # Nope.  Treat as a string.
                            self.genre = str_to_unicode(tcon)

                    if genre is not None:
                        try:
                            self.genre = ID3.GENRE_LIST[genre]
                        except KeyError:
                            # Numeric genre specified but not one of the known genres,
                            # use 'Unknown' as per ID3v1.
                            self.genre = u'Unknown'

                # and some tools store it as trackno/trackof in TRCK
                if not self.trackof and self.trackno and \
                       self.trackno.find('/') > 0:
                    self.trackof = self.trackno[self.trackno.find('/')+1:]
                    self.trackno = self.trackno[:self.trackno.find('/')]
            if id3:
                self.length = id3.getPlayTime()
        except Exception:
            if log.level < 30:
                log.exception('parse error')

        offset, header = self._find_header(file)
        if offset == -1 or header is None:
            return

        self._parse_header(header)

        if id3:
            # Note: information about variable bitrate or not should
            # be handled somehow.
            (vbr, self.bitrate) = id3.getBitRate()