Beispiel #1
0
def main(argv):
    parser = ID3OptionParser()
    parser.add_option(
        "-e", "--encoding", metavar="ENCODING", action="store",
        type="string", dest="encoding",
        help=("Specify original tag encoding (default is %s)" % (
              getpreferredencoding())))
    parser.add_option(
        "-p", "--dry-run", action="store_true", dest="noupdate",
        help="Do not actually modify files")
    parser.add_option(
        "--force-v1", action="store_true", dest="force_v1",
        help="Use an ID3v1 tag even if an ID3v2 tag is present")
    parser.add_option(
        "--remove-v1", action="store_true", dest="remove_v1",
        help="Remove v1 tag after processing the files")
    parser.add_option(
        "-q", "--quiet", action="store_const", dest="verbose",
        const="quiet", help="Only output errors")
    parser.add_option(
        "-d", "--debug", action="store_const", dest="verbose",
        const="debug", help="Output updated tags")

    for i, arg in enumerate(argv):
        if arg == "-v1":
            argv[i] = fsnative(u"--force-v1")
        elif arg == "-removev1":
            argv[i] = fsnative(u"--remove-v1")

    (options, args) = parser.parse_args(argv[1:])

    if args:
        update(options, args)
    else:
        parser.print_help()
Beispiel #2
0
def main(argv):
    parser = ID3OptionParser()
    parser.add_option(
        "-e", "--encoding", metavar="ENCODING", action="store",
        type="string", dest="encoding",
        help=("Specify original tag encoding (default is %s)" % (
              getpreferredencoding())))
    parser.add_option(
        "-p", "--dry-run", action="store_true", dest="noupdate",
        help="Do not actually modify files")
    parser.add_option(
        "--force-v1", action="store_true", dest="force_v1",
        help="Use an ID3v1 tag even if an ID3v2 tag is present")
    parser.add_option(
        "--remove-v1", action="store_true", dest="remove_v1",
        help="Remove v1 tag after processing the files")
    parser.add_option(
        "-q", "--quiet", action="store_const", dest="verbose",
        const="quiet", help="Only output errors")
    parser.add_option(
        "-d", "--debug", action="store_const", dest="verbose",
        const="debug", help="Output updated tags")

    for i, arg in enumerate(argv):
        if arg == "-v1":
            argv[i] = fsnative(u"--force-v1")
        elif arg == "-removev1":
            argv[i] = fsnative(u"--remove-v1")

    (options, args) = parser.parse_args(argv[1:])

    if args:
        update(options, args)
    else:
        parser.print_help()
Beispiel #3
0
 def call2(self, *args):
     for arg in args:
         self.assertTrue(isinstance(arg, fsnative))
     old_stdout = sys.stdout
     old_stderr = sys.stderr
     try:
         out = StringIO()
         err = StringIO()
         sys.stdout = out
         sys.stderr = err
         try:
             ret = self._main([fsnative(self.TOOL_NAME)] + list(args))
         except SystemExit as e:
             ret = e.code
         ret = ret or 0
         out_val = out.getvalue()
         err_val = err.getvalue()
         if os.name == "nt" and PY2:
             encoding = getattr(sys.stdout, "encoding", None) or "mbcs"
             out_val = text_type(out_val, encoding)
             err_val = text_type(err_val, encoding)
         return (ret, out_val, err_val)
     finally:
         sys.stdout = old_stdout
         sys.stderr = old_stderr
Beispiel #4
0
 def call2(self, *args):
     for arg in args:
         self.assertTrue(isinstance(arg, fsnative))
     old_stdout = sys.stdout
     old_stderr = sys.stderr
     try:
         out = StringIO()
         err = StringIO()
         sys.stdout = out
         sys.stderr = err
         try:
             ret = self._main([fsnative(self.TOOL_NAME)] + list(args))
         except SystemExit as e:
             ret = e.code
         ret = ret or 0
         out_val = out.getvalue()
         err_val = err.getvalue()
         if os.name == "nt" and PY2:
             encoding = getattr(sys.stdout, "encoding", None) or "mbcs"
             out_val = text_type(out_val, encoding)
             err_val = text_type(err_val, encoding)
         return (ret, out_val, err_val)
     finally:
         sys.stdout = old_stdout
         sys.stderr = old_stderr
Beispiel #5
0
def get_var(tool_name, entry="main"):
    tool_path = os.path.join(mutagen.__path__[0], "..", "tools",
                             fsnative(tool_name))
    dont_write_bytecode = sys.dont_write_bytecode
    sys.dont_write_bytecode = True
    try:
        with warnings.catch_warnings():
            warnings.simplefilter("ignore", DeprecationWarning)
            mod = imp.load_source(tool_name, tool_path)
    finally:
        sys.dont_write_bytecode = dont_write_bytecode
    return getattr(mod, entry)
Beispiel #6
0
 def call2(self, *args):
     for arg in args:
         self.assertTrue(isinstance(arg, fsnative))
     old_stdout = sys.stdout
     old_stderr = sys.stderr
     try:
         out = StringIO()
         err = StringIO()
         sys.stdout = out
         sys.stderr = err
         try:
             ret = self._main([fsnative(self.TOOL_NAME)] + list(args))
         except SystemExit as e:
             ret = e.code
         ret = ret or 0
         out_val = out.getvalue()
         err_val = err.getvalue()
         return (ret, out_val, err_val)
     finally:
         sys.stdout = old_stdout
         sys.stderr = old_stderr
def main(argv):
    parser = ID3OptionParser()
    parser.add_option("-v",
                      "--verbose",
                      action="store_true",
                      dest="verbose",
                      default=False,
                      help="be verbose")
    parser.add_option("-q",
                      "--quiet",
                      action="store_false",
                      dest="verbose",
                      help="be quiet (the default)")
    parser.add_option("-e",
                      "--escape",
                      action="store_true",
                      default=False,
                      help="enable interpretation of backslash escapes")
    parser.add_option("-f",
                      "--list-frames",
                      action="callback",
                      callback=list_frames,
                      help="Display all possible frames for ID3v2.3 / ID3v2.4")
    parser.add_option("--list-frames-v2.2",
                      action="callback",
                      callback=list_frames_2_2,
                      help="Display all possible frames for ID3v2.2")
    parser.add_option("-L",
                      "--list-genres",
                      action="callback",
                      callback=list_genres,
                      help="Lists all ID3v1 genres")
    parser.add_option("-l",
                      "--list",
                      action="store_const",
                      dest="action",
                      const="list",
                      help="Lists the tag(s) on the open(s)")
    parser.add_option("--list-raw",
                      action="store_const",
                      dest="action",
                      const="list-raw",
                      help="Lists the tag(s) on the open(s) in Python format")
    parser.add_option("-d",
                      "--delete-v2",
                      action="store_const",
                      dest="action",
                      const="delete-v2",
                      help="Deletes ID3v2 tags")
    parser.add_option("-s",
                      "--delete-v1",
                      action="store_const",
                      dest="action",
                      const="delete-v1",
                      help="Deletes ID3v1 tags")
    parser.add_option("-D",
                      "--delete-all",
                      action="store_const",
                      dest="action",
                      const="delete-v1-v2",
                      help="Deletes ID3v1 and ID3v2 tags")
    parser.add_option('--delete-frames',
                      metavar='FID1,FID2,...',
                      action='store',
                      dest='deletes',
                      default='',
                      help="Delete the given frames")
    parser.add_option(
        "-C",
        "--convert",
        action="store_const",
        dest="action",
        const="convert",
        help="Convert tags to ID3v2.4 (any editing will do this)")

    parser.add_option("-a",
                      "--artist",
                      metavar='"ARTIST"',
                      action="callback",
                      help="Set the artist information",
                      type="string",
                      callback=lambda *args: args[3].edits.append(
                          (fsnative(u"--TPE1"), args[2])))
    parser.add_option("-A",
                      "--album",
                      metavar='"ALBUM"',
                      action="callback",
                      help="Set the album title information",
                      type="string",
                      callback=lambda *args: args[3].edits.append(
                          (fsnative(u"--TALB"), args[2])))
    parser.add_option("-t",
                      "--song",
                      metavar='"SONG"',
                      action="callback",
                      help="Set the song title information",
                      type="string",
                      callback=lambda *args: args[3].edits.append(
                          (fsnative(u"--TIT2"), args[2])))
    parser.add_option("-c",
                      "--comment",
                      metavar='"DESCRIPTION":"COMMENT":"LANGUAGE"',
                      action="callback",
                      help="Set the comment information",
                      type="string",
                      callback=lambda *args: args[3].edits.append(
                          (fsnative(u"--COMM"), args[2])))
    parser.add_option(
        "-p",
        "--picture",
        metavar='"FILENAME":"DESCRIPTION":"IMAGE-TYPE":"MIME-TYPE"',
        action="callback",
        help="Set the picture",
        type="string",
        callback=lambda *args: args[3].edits.append(
            (fsnative(u"--APIC"), args[2])))
    parser.add_option("-g",
                      "--genre",
                      metavar='"GENRE"',
                      action="callback",
                      help="Set the genre or genre number",
                      type="string",
                      callback=lambda *args: args[3].edits.append(
                          (fsnative(u"--TCON"), args[2])))
    parser.add_option("-y",
                      "--year",
                      "--date",
                      metavar='YYYY[-MM-DD]',
                      action="callback",
                      help="Set the year/date",
                      type="string",
                      callback=lambda *args: args[3].edits.append(
                          (fsnative(u"--TDRC"), args[2])))
    parser.add_option("-T",
                      "--track",
                      metavar='"num/num"',
                      action="callback",
                      help="Set the track number/(optional) total tracks",
                      type="string",
                      callback=lambda *args: args[3].edits.append(
                          (fsnative(u"--TRCK"), args[2])))

    for key, frame in mutagen.id3.Frames.items():
        if (issubclass(frame, mutagen.id3.TextFrame)
                or issubclass(frame, mutagen.id3.UrlFrame)
                or issubclass(frame, mutagen.id3.POPM)
                or frame in (mutagen.id3.APIC, mutagen.id3.UFID)):
            parser.add_option(
                "--" + key,
                action="callback",
                help=SUPPRESS_HELP,
                type='string',
                metavar="value",  # optparse blows up with this
                callback=lambda *args: args[3].edits.append(args[1:3]))

    (options, args) = parser.parse_args(argv[1:])
    global verbose
    verbose = options.verbose

    if args:
        if parser.edits or options.deletes:
            if options.deletes:
                delete_frames(options.deletes, args)
            if parser.edits:
                write_files(parser.edits, args, options.escape)
        elif options.action in [None, 'list']:
            list_tags(args)
        elif options.action == "list-raw":
            list_tags_raw(args)
        elif options.action == "convert":
            write_files([], args, options.escape)
        elif options.action.startswith("delete"):
            delete_tags(args, "v1" in options.action, "v2" in options.action)
        else:
            parser.print_help()
    else:
        parser.print_help()
Beispiel #8
0
def main(argv):
    parser = ID3OptionParser()
    parser.add_option(
        "-v", "--verbose", action="store_true", dest="verbose", default=False,
        help="be verbose")
    parser.add_option(
        "-q", "--quiet", action="store_false", dest="verbose",
        help="be quiet (the default)")
    parser.add_option(
        "-e", "--escape", action="store_true", default=False,
        help="enable interpretation of backslash escapes")
    parser.add_option(
        "-f", "--list-frames", action="callback", callback=list_frames,
        help="Display all possible frames for ID3v2.3 / ID3v2.4")
    parser.add_option(
        "--list-frames-v2.2", action="callback", callback=list_frames_2_2,
        help="Display all possible frames for ID3v2.2")
    parser.add_option(
        "-L", "--list-genres", action="callback", callback=list_genres,
        help="Lists all ID3v1 genres")
    parser.add_option(
        "-l", "--list", action="store_const", dest="action", const="list",
        help="Lists the tag(s) on the open(s)")
    parser.add_option(
        "--list-raw", action="store_const", dest="action", const="list-raw",
        help="Lists the tag(s) on the open(s) in Python format")
    parser.add_option(
        "-d", "--delete-v2", action="store_const", dest="action",
        const="delete-v2", help="Deletes ID3v2 tags")
    parser.add_option(
        "-s", "--delete-v1", action="store_const", dest="action",
        const="delete-v1", help="Deletes ID3v1 tags")
    parser.add_option(
        "-D", "--delete-all", action="store_const", dest="action",
        const="delete-v1-v2", help="Deletes ID3v1 and ID3v2 tags")
    parser.add_option(
        '--delete-frames', metavar='FID1,FID2,...', action='store',
        dest='deletes', default='', help="Delete the given frames")
    parser.add_option(
        "-C", "--convert", action="store_const", dest="action",
        const="convert",
        help="Convert tags to ID3v2.4 (any editing will do this)")

    parser.add_option(
        "-a", "--artist", metavar='"ARTIST"', action="callback",
        help="Set the artist information", type="string",
        callback=lambda *args: args[3].edits.append((fsnative(u"--TPE1"),
                                                     args[2])))
    parser.add_option(
        "-A", "--album", metavar='"ALBUM"', action="callback",
        help="Set the album title information", type="string",
        callback=lambda *args: args[3].edits.append((fsnative(u"--TALB"),
                                                     args[2])))
    parser.add_option(
        "-t", "--song", metavar='"SONG"', action="callback",
        help="Set the song title information", type="string",
        callback=lambda *args: args[3].edits.append((fsnative(u"--TIT2"),
                                                     args[2])))
    parser.add_option(
        "-c", "--comment", metavar='"DESCRIPTION":"COMMENT":"LANGUAGE"',
        action="callback", help="Set the comment information", type="string",
        callback=lambda *args: args[3].edits.append((fsnative(u"--COMM"),
                                                     args[2])))
    parser.add_option(
        "-p", "--picture",
        metavar='"FILENAME":"DESCRIPTION":"IMAGE-TYPE":"MIME-TYPE"',
        action="callback", help="Set the picture", type="string",
        callback=lambda *args: args[3].edits.append((fsnative(u"--APIC"),
                                                     args[2])))
    parser.add_option(
        "-g", "--genre", metavar='"GENRE"', action="callback",
        help="Set the genre or genre number", type="string",
        callback=lambda *args: args[3].edits.append((fsnative(u"--TCON"),
                                                     args[2])))
    parser.add_option(
        "-y", "--year", "--date", metavar='YYYY[-MM-DD]', action="callback",
        help="Set the year/date", type="string",
        callback=lambda *args: args[3].edits.append((fsnative(u"--TDRC"),
                                                     args[2])))
    parser.add_option(
        "-T", "--track", metavar='"num/num"', action="callback",
        help="Set the track number/(optional) total tracks", type="string",
        callback=lambda *args: args[3].edits.append((fsnative(u"--TRCK"),
                                                     args[2])))

    for key, frame in mutagen.id3.Frames.items():
        if (issubclass(frame, mutagen.id3.TextFrame)
                or issubclass(frame, mutagen.id3.UrlFrame)
                or issubclass(frame, mutagen.id3.POPM)
                or frame in (mutagen.id3.APIC, mutagen.id3.UFID,
                             mutagen.id3.USLT)):
            parser.add_option(
                "--" + key, action="callback", help=SUPPRESS_HELP,
                type='string', metavar="value",  # optparse blows up with this
                callback=lambda *args: args[3].edits.append(args[1:3]))

    (options, args) = parser.parse_args(argv[1:])
    global verbose
    verbose = options.verbose

    if args:
        if parser.edits or options.deletes:
            if options.deletes:
                delete_frames(options.deletes, args)
            if parser.edits:
                write_files(parser.edits, args, options.escape)
        elif options.action in [None, 'list']:
            list_tags(args)
        elif options.action == "list-raw":
            list_tags_raw(args)
        elif options.action == "convert":
            write_files([], args, options.escape)
        elif options.action.startswith("delete"):
            delete_tags(args, "v1" in options.action, "v2" in options.action)
        else:
            parser.print_help()
    else:
        parser.print_help()
 def test_basic(self):
     base = os.path.join(fsnative(u'tests'), fsnative(u'data'))
     res, out = self.call(base)
     self.failIf(res)
     self.failUnless("Report for %s" % base in out)