def update(options, filenames):
    encoding = options.encoding or locale.getpreferredencoding()
    verbose = options.verbose
    noupdate = options.noupdate
    force_v1 = options.force_v1
    remove_v1 = options.remove_v1

    def conv(uni):
        #return uni.encode('iso-8859-1').decode(encoding)
        return h2p(uni)

    for filename in filenames:
        if verbose != "quiet":
            print "Updating", filename

        if has_id3v1(filename) and not noupdate and force_v1:
            mutagen.id3.delete(filename, False, True)

        try: id3 = mutagen.id3.ID3(filename)
        except mutagen.id3.ID3NoHeaderError:
            if verbose != "quiet":
                print "No ID3 header found; skipping..."
            continue
        except Exception, err:
            if verbose != "quiet":
                print str(err)
            continue

        for tag in filter(lambda t: t.startswith("T"), id3):
            frame = id3[tag]
            if isinstance(frame, mutagen.id3.TimeStampTextFrame):
                # non-unicode fields
                continue
            try:
                text = frame.text
            except AttributeError:
                continue
            try:
                text = map(conv, frame.text)
            except (UnicodeError, LookupError):
                continue
            else:
                frame.text = text
                if not text or min(map(isascii, text)):
                    frame.encoding = 3
                else:
                    frame.encoding = 1

        enc = locale.getpreferredencoding()
        if verbose == "debug":
            print id3.pprint().encode(enc, "replace")

        if not noupdate:
            if remove_v1: id3.save(filename, v1=False)
            else: id3.save(filename)
Exemple #2
0
def copy(src, dst, merge, write_v1=True, excluded_tags=None, verbose=False):
    """Returns 0 on success"""

    if excluded_tags is None:
        excluded_tags = []

    try:
        id3 = mutagen.id3.ID3(src, translate=False)
    except mutagen.id3.ID3NoHeaderError:
        print_(u"No ID3 header found in ", src, file=sys.stderr)
        return 1
    except Exception as err:
        print_(str(err), file=sys.stderr)
        return 1

    if verbose:
        print_(u"File", src, u"contains:", file=sys.stderr)
        print_(id3.pprint(), file=sys.stderr)

    for tag in excluded_tags:
        id3.delall(tag)

    if merge:
        try:
            target = mutagen.id3.ID3(dst, translate=False)
        except mutagen.id3.ID3NoHeaderError:
            # no need to merge
            pass
        except Exception as err:
            print_(str(err), file=sys.stderr)
            return 1
        else:
            for frame in id3.values():
                target.add(frame)

            id3 = target

    # if the source is 2.3 save it as 2.3
    if id3.version < (2, 4, 0):
        id3.update_to_v23()
        v2_version = 3
    else:
        id3.update_to_v24()
        v2_version = 4

    try:
        id3.save(dst, v1=(2 if write_v1 else 0), v2_version=v2_version)
    except Exception as err:
        print_(u"Error saving",
               dst,
               u":\n%s" % text_type(err),
               file=sys.stderr)
        return 1
    else:
        if verbose:
            print_(u"Successfully saved", dst, file=sys.stderr)
        return 0
Exemple #3
0
def update(options, filenames):
    encoding = options.encoding or getpreferredencoding()
    verbose = options.verbose
    noupdate = options.noupdate
    force_v1 = options.force_v1
    remove_v1 = options.remove_v1

    def conv(uni):
        return uni.encode('iso-8859-1').decode(encoding)

    for filename in filenames:
        with _sig.block():
            if verbose != "quiet":
                print_(u"Updating", filename)

            if has_id3v1(filename) and not noupdate and force_v1:
                mutagen.id3.delete(filename, False, True)

            try:
                id3 = mutagen.id3.ID3(filename)
            except mutagen.id3.ID3NoHeaderError:
                if verbose != "quiet":
                    print_(u"No ID3 header found; skipping...")
                continue
            except Exception as err:
                print_(text_type(err), file=sys.stderr)
                continue

            for tag in filter(lambda t: t.startswith(("T", "COMM")), id3):
                frame = id3[tag]
                if isinstance(frame, mutagen.id3.TimeStampTextFrame):
                    # non-unicode fields
                    continue
                try:
                    text = frame.text
                except AttributeError:
                    continue
                try:
                    text = [conv(x) for x in frame.text]
                except (UnicodeError, LookupError):
                    continue
                else:
                    frame.text = text
                    if not text or min(map(isascii, text)):
                        frame.encoding = 3
                    else:
                        frame.encoding = 1

            if verbose == "debug":
                print_(id3.pprint())

            if not noupdate:
                if remove_v1:
                    id3.save(filename, v1=False)
                else:
                    id3.save(filename)
Exemple #4
0
def update(options, filenames):
    encoding = options.encoding or getpreferredencoding()
    verbose = options.verbose
    noupdate = options.noupdate
    force_v1 = options.force_v1
    remove_v1 = options.remove_v1

    def conv(uni):
        return uni.encode('iso-8859-1').decode(encoding)

    for filename in filenames:
        with _sig.block():
            if verbose != "quiet":
                print_(u"Updating", filename)

            if has_id3v1(filename) and not noupdate and force_v1:
                mutagen.id3.delete(filename, False, True)

            try:
                id3 = mutagen.id3.ID3(filename)
            except mutagen.id3.ID3NoHeaderError:
                if verbose != "quiet":
                    print_(u"No ID3 header found; skipping...")
                continue
            except Exception as err:
                print_(text_type(err), file=sys.stderr)
                continue

            for tag in filter(lambda t: t.startswith(("T", "COMM")), id3):
                frame = id3[tag]
                if isinstance(frame, mutagen.id3.TimeStampTextFrame):
                    # non-unicode fields
                    continue
                try:
                    text = frame.text
                except AttributeError:
                    continue
                try:
                    text = [conv(x) for x in frame.text]
                except (UnicodeError, LookupError):
                    continue
                else:
                    frame.text = text
                    if not text or min(map(isascii, text)):
                        frame.encoding = 3
                    else:
                        frame.encoding = 1

            if verbose == "debug":
                print_(id3.pprint())

            if not noupdate:
                if remove_v1:
                    id3.save(filename, v1=False)
                else:
                    id3.save(filename)
Exemple #5
0
def copy(src, dst, merge, write_v1=True, excluded_tags=None, verbose=False):
    """Returns 0 on success"""

    if excluded_tags is None:
        excluded_tags = []

    try:
        id3 = mutagen.id3.ID3(src, translate=False)
    except mutagen.id3.ID3NoHeaderError:
        print_(u"No ID3 header found in ", src, file=sys.stderr)
        return 1
    except Exception as err:
        print_(str(err), file=sys.stderr)
        return 1

    if verbose:
        print_(u"File", src, u"contains:", file=sys.stderr)
        print_(id3.pprint(), file=sys.stderr)

    for tag in excluded_tags:
        id3.delall(tag)

    if merge:
        try:
            target = mutagen.id3.ID3(dst, translate=False)
        except mutagen.id3.ID3NoHeaderError:
            # no need to merge
            pass
        except Exception as err:
            print_(str(err), file=sys.stderr)
            return 1
        else:
            for frame in id3.values():
                target.add(frame)

            id3 = target

    # if the source is 2.3 save it as 2.3
    if id3.version < (2, 4, 0):
        id3.update_to_v23()
        v2_version = 3
    else:
        id3.update_to_v24()
        v2_version = 4

    try:
        id3.save(dst, v1=(2 if write_v1 else 0), v2_version=v2_version)
    except Exception as err:
        print_(u"Error saving", dst, u":\n%s" % text_type(err),
               file=sys.stderr)
        return 1
    else:
        if verbose:
            print_(u"Successfully saved", dst, file=sys.stderr)
        return 0
def list_tags(filenames):
    for filename in filenames:
        print_("IDv2 tag info for", filename)
        try:
            id3 = mutagen.id3.ID3(filename, translate=False)
        except mutagen.id3.ID3NoHeaderError:
            print_(u"No ID3 header found; skipping.")
        except Exception as err:
            print_(text_type(err), file=sys.stderr)
            raise SystemExit(1)
        else:
            print_(id3.pprint())
Exemple #7
0
def list_tags(filenames):
    for filename in filenames:
        print_("IDv2 tag info for", filename)
        try:
            id3 = mutagen.id3.ID3(filename, translate=False)
        except mutagen.id3.ID3NoHeaderError:
            print_(u"No ID3 header found; skipping.")
        except Exception as err:
            print_(text_type(err), file=sys.stderr)
            raise SystemExit(1)
        else:
            print_(id3.pprint())
Exemple #8
0
        id3 = mutagen.id3.ID3(f)
      except mutagen.id3.ID3NoHeaderError:
        id3 = mutagen.id3.ID3()

    if ft == u'mp3':
      # adding new id3 frames
      id3.add(TIT2(encoding=3, text=disc.track_list[c].title))
      id3.add(TPE1(encoding=3, text=disc.track_list[c].artist))
      id3.add(TALB(encoding=3, text=disc.title))
      id3.add(TCOM(encoding=3, text=disc.artist))
      id3.add(TPUB(encoding=3, text=disc.label))
      id3.add(TDRC(encoding=3, text=disc.year))
      id3.add(TXXX(encoding=3, desc='Catalog #', text=disc.cat_num))
      id3.add(TCON(encoding=3, text=disc.genre))
      id3.add(TRCK(encoding=3, text=str(disc.track_list[c][0]) + "/" + tot))
      id3.pprint()
      id3.save(f,0)
    elif ft == u'flac':
      disc.track_list[c].title
      audio["TITLE"] = disc.track_list[c].title
      audio["ARTIST"] = disc.track_list[c].artist.artistString
      audio["ALBUM"] = disc.title
      audio["COMPOSER"] = disc.artist.artistString
      audio["ORGANIZATION"] = disc.label
      audio["CATALOGNUM"] = disc.cat_num
      audio["GENRE"] = disc.genre
      if(len(disc.style) != 0):
        audio["STYLE"] = disc.style
      audio["YEAR"] = disc.year
      audio["DATE"] = disc.date
      audio["TRACKNUMBER"] = str(disc.track_list[c].position)