Exemplo n.º 1
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
Exemplo n.º 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
def list_tags_raw(filenames):
    for filename in filenames:
        print_("Raw 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:
            for frame in id3.values():
                print_(text_type(repr(frame)))
Exemplo n.º 4
0
def list_tags_raw(filenames):
    for filename in filenames:
        print_("Raw 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:
            for frame in id3.values():
                print_(text_type(repr(frame)))