Beispiel #1
0
def cl_main():
  # parse args
  arg_parser = argparse.ArgumentParser(description="SACAD (recursive tool) v%s.%s" % (sacad.__version__,
                                                                                      __doc__),
                                       formatter_class=argparse.ArgumentDefaultsHelpFormatter)
  arg_parser.add_argument("lib_dir",
                          help="Music library directory to recursively analyze")
  arg_parser.add_argument("size",
                          type=int,
                          help="Target image size")
  arg_parser.add_argument("filename",
                          help="Cover image filename")
  sacad.setup_common_args(arg_parser)
  args = arg_parser.parse_args()
  args.format = os.path.splitext(args.filename)[1][1:].lower()
  try:
    args.format = sacad.SUPPORTED_IMG_FORMATS[args.format]
  except KeyError:
    print("Unable to guess image format from extension, or unknown format: %s" % (args.format))
    exit(1)

  # silence the logger
  logging.getLogger().setLevel(logging.ERROR)

  # do the job
  work = analyze_lib(args.lib_dir, args.filename)
  get_covers(work, args)
Beispiel #2
0
def cl_main():
    # parse args
    arg_parser = argparse.ArgumentParser(
        description="SACAD (recursive tool) v%s.%s" %
        (sacad.__version__, __doc__),
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    arg_parser.add_argument(
        "lib_dir", help="Music library directory to recursively analyze")
    arg_parser.add_argument("size", type=int, help="Target image size")
    arg_parser.add_argument("filename", help="Cover image filename")
    sacad.setup_common_args(arg_parser)
    args = arg_parser.parse_args()
    args.format = os.path.splitext(args.filename)[1][1:].lower()
    try:
        args.format = sacad.SUPPORTED_IMG_FORMATS[args.format]
    except KeyError:
        print(
            "Unable to guess image format from extension, or unknown format: %s"
            % (args.format))
        exit(1)

    # silence the logger
    logging.getLogger().setLevel(logging.ERROR)

    # do the job
    work = analyze_lib(args.lib_dir, args.filename)
    get_covers(work, args)
Beispiel #3
0
def cl_main():
  # parse args
  arg_parser = argparse.ArgumentParser(description="SACAD (recursive tool) v%s.%s" % (sacad.__version__,
                                                                                      __doc__),
                                       formatter_class=argparse.ArgumentDefaultsHelpFormatter)
  arg_parser.add_argument("lib_dir",
                          help="Music library directory to recursively analyze")
  arg_parser.add_argument("size",
                          type=int,
                          help="Target image size")
  arg_parser.add_argument("filename",
                          help="Cover image filename ('%s' to embed JPEG into audio files)" % (EMBEDDED_ALBUM_ART_SYMBOL))
  arg_parser.add_argument("-i",
                          "--ignore-existing",
                          action="store_true",
                          default=False,
                          help="Ignore existing covers and force search and download for all files")
  sacad.setup_common_args(arg_parser)
  arg_parser.add_argument("-v",
                          "--verbose",
                          action="store_true",
                          default=False,
                          dest="verbose",
                          help="Enable verbose output")
  args = arg_parser.parse_args()
  if args.filename == EMBEDDED_ALBUM_ART_SYMBOL:
    args.format = "jpg"
  else:
    args.format = os.path.splitext(args.filename)[1][1:].lower()
  try:
    args.format = sacad.SUPPORTED_IMG_FORMATS[args.format]
  except KeyError:
    print("Unable to guess image format from extension, or unknown format: %s" % (args.format))
    exit(1)

  # setup logger
  if not args.verbose:
    logging.getLogger("sacad_r").setLevel(logging.WARNING)
    logging.getLogger().setLevel(logging.ERROR)
    logging.getLogger("asyncio").setLevel(logging.CRITICAL + 1)
    fmt = "%(name)s: %(message)s"
  else:
    logging.getLogger("sacad_r").setLevel(logging.DEBUG)
    logging.getLogger().setLevel(logging.DEBUG)
    logging.getLogger("asyncio").setLevel(logging.WARNING)
    fmt = "%(asctime)s %(levelname)s [%(name)s] %(message)s"
  logging_formatter = colored_logging.ColoredFormatter(fmt=fmt)
  logging_handler = logging.StreamHandler()
  logging_handler.setFormatter(logging_formatter)
  logging.getLogger().addHandler(logging_handler)

  # do the job
  work = analyze_lib(args.lib_dir, args.filename, ignore_existing=args.ignore_existing)
  get_covers(work, args)
Beispiel #4
0
def cl_main():
    # parse args
    arg_parser = argparse.ArgumentParser(
        description="SACAD (recursive tool) v%s.%s" %
        (sacad.__version__, __doc__),
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    arg_parser.add_argument(
        "lib_dir", help="Music library directory to recursively analyze")
    arg_parser.add_argument("size", type=int, help="Target image size")
    arg_parser.add_argument(
        "filename",
        help="Cover image filename ('%s' to embed JPEG into audio files)" %
        (EMBEDDED_ALBUM_ART_SYMBOL))
    sacad.setup_common_args(arg_parser)
    arg_parser.add_argument(
        "-i",
        "--ignore-existing",
        action="store_true",
        default=False,
        help=
        "Ignore existing covers and force search and download for all files")
    args = arg_parser.parse_args()
    if args.filename == EMBEDDED_ALBUM_ART_SYMBOL:
        args.format = "jpg"
    else:
        args.format = os.path.splitext(args.filename)[1][1:].lower()
    try:
        args.format = sacad.SUPPORTED_IMG_FORMATS[args.format]
    except KeyError:
        print(
            "Unable to guess image format from extension, or unknown format: %s"
            % (args.format))
        exit(1)

    # silence the logger
    logging.basicConfig(
        format="%(asctime)s %(process)d %(threadName)s: %(message)s",
        level=logging.ERROR)
    logging.getLogger("asyncio").setLevel(logging.CRITICAL + 1)

    # do the job
    work = analyze_lib(args.lib_dir,
                       args.filename,
                       ignore_existing=args.ignore_existing)
    get_covers(work, args)
Beispiel #5
0
def cl_main():
    # parse args
    arg_parser = argparse.ArgumentParser(
        description="SACAD (recursive tool) v%s.%s" %
        (sacad.__version__, __doc__),
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    arg_parser.add_argument(
        "lib_dir", help="Music library directory to recursively analyze")
    arg_parser.add_argument("size", type=int, help="Target image size")
    arg_parser.add_argument("cover_pattern",
                            help="""Cover image path pattern.
                                  {artist} and {album} are replaced by their tag value.
                                  You can set an absolute path, otherwise destination directory is relative to the audio files.
                                  Use single character '%s' to embed JPEG into audio files."""
                            % (EMBEDDED_ALBUM_ART_SYMBOL))
    arg_parser.add_argument(
        "-i",
        "--ignore-existing",
        action="store_true",
        default=False,
        help=
        "Ignore existing covers and force search and download for all files")
    arg_parser.add_argument(
        "-f",
        "--full-scan",
        action="store_true",
        default=False,
        help="""Enable scanning of all audio files in each directory.
                                  By default the scanner will assume all audio files in a single directory are part of
                                  the same album, and only read metadata for the first file.
                                  Enable this if your files are organized in a way than allows files for different
                                  albums to be in the same directory level.
                                  WARNING: This will make the initial scan much slower."""
    )
    sacad.setup_common_args(arg_parser)
    arg_parser.add_argument("-v",
                            "--verbose",
                            action="store_true",
                            default=False,
                            dest="verbose",
                            help="Enable verbose output")
    args = arg_parser.parse_args()
    if args.cover_pattern == EMBEDDED_ALBUM_ART_SYMBOL:
        args.format = "jpg"
    else:
        args.format = os.path.splitext(args.cover_pattern)[1][1:].lower()
    try:
        args.format = sacad.SUPPORTED_IMG_FORMATS[args.format]
    except KeyError:
        print(
            "Unable to guess image format from extension, or unknown format: %s"
            % (args.format))
        exit(1)

    # setup logger
    if not args.verbose:
        logging.getLogger("sacad_r").setLevel(logging.WARNING)
        logging.getLogger().setLevel(logging.ERROR)
        logging.getLogger("asyncio").setLevel(logging.CRITICAL + 1)
        fmt = "%(name)s: %(message)s"
    else:
        logging.getLogger("sacad_r").setLevel(logging.DEBUG)
        logging.getLogger().setLevel(logging.DEBUG)
        logging.getLogger("asyncio").setLevel(logging.WARNING)
        fmt = "%(asctime)s %(levelname)s [%(name)s] %(message)s"
    logging_formatter = colored_logging.ColoredFormatter(fmt=fmt)
    logging_handler = logging.StreamHandler()
    logging_handler.setFormatter(logging_formatter)
    logging.getLogger().addHandler(logging_handler)

    # bump nofile ulimit
    try:
        import resource
        soft_lim, hard_lim = resource.getrlimit(resource.RLIMIT_NOFILE)
        if ((soft_lim != resource.RLIM_INFINITY) and
            ((soft_lim < hard_lim) or (hard_lim == resource.RLIM_INFINITY))):
            resource.setrlimit(resource.RLIMIT_NOFILE, (hard_lim, hard_lim))
            logging.getLogger().debug(
                "Max open files count set from %u to %u" %
                (soft_lim, hard_lim))
    except (AttributeError, ImportError, OSError, ValueError):
        # not supported on system
        pass

    # do the job
    work = analyze_lib(args.lib_dir,
                       args.cover_pattern,
                       ignore_existing=args.ignore_existing,
                       full_scan=args.full_scan,
                       all_formats=args.preserve_format)
    get_covers(work, args)