<commit_before>from logzero import logger as log
import appdirs

import logging
import yaml
import argparse
import mimetypes
import os

import spotdl
from spotdl import internals


_LOG_LEVELS_STR = ["INFO", "WARNING", "ERROR", "DEBUG"]

default_conf = {
    "spotify-downloader": {
        "manual": False,
        "no-metadata": False,
        "no-fallback-metadata": False,
        "avconv": False,
        "folder": internals.get_music_dir(),
        "overwrite": "prompt",
        "input-ext": ".m4a",
        "output-ext": ".mp3",
        "write-to": None,
        "trim-silence": False,
        "download-only-metadata": False,
        "dry-run": False,
        "music-videos-only": False,
        "no-spaces": False,
        "file-format": "{artist} - {track_name}",
        "search-format": "{artist} - {track_name} lyrics",
        "youtube-api-key": None,
        "skip": None,
        "write-successful": None,
        "log-level": "INFO",
        "spotify_client_id": "4fe3fecfe5334023a1472516cc99d805",
        "spotify_client_secret": "<KEY>"
    }
}


def log_leveller(log_level_str):
    loggin_levels = [logging.INFO, logging.WARNING, logging.ERROR, logging.DEBUG]
    log_level_str_index = _LOG_LEVELS_STR.index(log_level_str)
    loggin_level = loggin_levels[log_level_str_index]
    return loggin_level


def merge(default, config):
    """ Override default dict with config dict. """
    merged = default.copy()
    merged.update(config)
    return merged


def get_config(config_file):
    try:
        with open(config_file, "r") as ymlfile:
            cfg = yaml.load(ymlfile)
    except FileNotFoundError:
        log.info("Writing default configuration to {0}:".format(config_file))
        with open(config_file, "w") as ymlfile:
            yaml.dump(default_conf, ymlfile, default_flow_style=False)
            cfg = default_conf

        for line in yaml.dump(
            default_conf["spotify-downloader"], default_flow_style=False
        ).split("\n"):
            if line.strip():
                log.info(line.strip())
        log.info(
            "Please note that command line arguments have higher priority "
            "than their equivalents in the configuration file"
        )

    return cfg["spotify-downloader"]


def override_config(config_file, parser, raw_args=None):
    """ Override default dict with config dict passed as comamnd line argument. """
    config_file = os.path.realpath(config_file)
    config = merge(default_conf["spotify-downloader"], get_config(config_file))
    parser.set_defaults(**config)
    return parser.parse_args(raw_args)


def get_arguments(raw_args=None, to_group=True, to_merge=True):
    parser = argparse.ArgumentParser(
        description="Download and convert tracks from Spotify, Youtube etc.",
        formatter_class=argparse.ArgumentDefaultsHelpFormatter,<commit_msg>Fix YAMLLoadWarning<commit_after>from logzero import logger as log
import appdirs

import logging
import yaml
import argparse
import mimetypes
import os

import spotdl
from spotdl import internals


_LOG_LEVELS_STR = ["INFO", "WARNING", "ERROR", "DEBUG"]

default_conf = {
    "spotify-downloader": {
        "manual": False,
        "no-metadata": False,
        "no-fallback-metadata": False,
        "avconv": False,
        "folder": internals.get_music_dir(),
        "overwrite": "prompt",
        "input-ext": ".m4a",
        "output-ext": ".mp3",
        "write-to": None,
        "trim-silence": False,
        "download-only-metadata": False,
        "dry-run": False,
        "music-videos-only": False,
        "no-spaces": False,
        "file-format": "{artist} - {track_name}",
        "search-format": "{artist} - {track_name} lyrics",
        "youtube-api-key": None,
        "skip": None,
        "write-successful": None,
        "log-level": "INFO",
        "spotify_client_id": "4fe3fecfe5334023a1472516cc99d805",
        "spotify_client_secret": "<KEY>"
    }
}


def log_leveller(log_level_str):
    loggin_levels = [logging.INFO, logging.WARNING, logging.ERROR, logging.DEBUG]
    log_level_str_index = _LOG_LEVELS_STR.index(log_level_str)
    loggin_level = loggin_levels[log_level_str_index]
    return loggin_level


def merge(default, config):
    """ Override default dict with config dict. """
    merged = default.copy()
    merged.update(config)
    return merged


def get_config(config_file):
    try:
        with open(config_file, "r") as ymlfile:
            cfg = yaml.safe_load(ymlfile)
    except FileNotFoundError:
        log.info("Writing default configuration to {0}:".format(config_file))
        with open(config_file, "w") as ymlfile:
            yaml.dump(default_conf, ymlfile, default_flow_style=False)
            cfg = default_conf

        for line in yaml.dump(
            default_conf["spotify-downloader"], default_flow_style=False
        ).split("\n"):
            if line.strip():
                log.info(line.strip())
        log.info(
            "Please note that command line arguments have higher priority "
            "than their equivalents in the configuration file"
        )

    return cfg["spotify-downloader"]


def override_config(config_file, parser, raw_args=None):
    """ Override default dict with config dict passed as comamnd line argument. """
    config_file = os.path.realpath(config_file)
    config = merge(default_conf["spotify-downloader"], get_config(config_file))
    parser.set_defaults(**config)
    return parser.parse_args(raw_args)


def get_arguments(raw_args=None, to_group=True, to_merge=True):
    parser = argparse.ArgumentParser(
        description="Download and convert tracks from Spotify, Youtube etc.",
        formatter_class=argparse.ArgumentDefaultsHelpFormatter,
{'fraction_non_alphanumeric': 0.11783161931322991, 'fraction_numerical': 0.00836674219975597, 'mean_word_length': 2.9958217270194987, 'pattern_counts': {'":': 46, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '717246', 'n_tokens_mistral': 1814, 'n_tokens_neox': 1735, 'n_words': 398}