Exemplo n.º 1
0
Arquivo: yt.py Projeto: mig2902/ytmdl
def dw(value, proxy=None, song_name='ytmdl_temp.mp3'):
    """Download the song."""
    try:
        # If song_name doesn't have mp3 extension, add it
        if not song_name.endswith('.mp3'):
            song_name += '.mp3'

        # Replace the spaces with hashes
        song_name = stringutils.remove_unwanted_chars(song_name)

        # The directory where we will download to.
        dw_dir = defaults.DEFAULT.SONG_TEMP_DIR
        logger.info("Saving the files to: {}".format(dw_dir))

        if not os.path.exists(dw_dir):
            os.makedirs(dw_dir)

        # Name of the temp file
        name = os.path.join(dw_dir, song_name)
        logger.debug(name)

        # Start downloading the song
        dw_using_yt(value, proxy, name)

        return name

    except Exception as e:
        # traceback.print_exception(e)
        return e
Exemplo n.º 2
0
def dw(value,
       proxy=None,
       song_name='ytmdl_temp.mp3',
       datatype='mp3',
       no_progress=False,
       ytdl_config: str = None):
    """
    Download the song.

    The song can be downloaded in various types.

    Default type is mp3 as ytmdl was solely designed to download
    MP3 songs, however due to user requests other formats are
    added.
    """
    # If song_name doesn't have mp3 extension, add it
    if datatype == "mp3" and not song_name.endswith(datatype):
        song_name += '.' + datatype
    elif datatype == "m4a" and not song_name.endswith(datatype):
        song_name += '.' + datatype

    try:
        # Replace the spaces with hashes
        song_name = stringutils.remove_unwanted_chars(song_name)

        # The directory where we will download to.
        dw_dir = defaults.DEFAULT.SONG_TEMP_DIR
        logger.info("Saving the files to: {}".format(dw_dir))

        if not os.path.exists(dw_dir):
            os.makedirs(dw_dir)

        # Name of the temp file
        name = os.path.join(dw_dir, song_name)
        logger.debug(name)

        # Start downloading the song
        status = dw_using_yt(value, proxy, name, datatype, no_progress,
                             ytdl_config)

        if status == 0:
            return name
        else:
            return status

    except Exception as e:
        # traceback.print_exception(e)
        return e
Exemplo n.º 3
0
def dw(value, proxy=None, song_name='ytmdl_temp.mp3'):
    """Download the song."""
    try:
        # Get the audio stream link
        url = get_audio_URL(value, proxy)
        logger.debug("Audio URL is: {}".format(url))
        logger.hold()

        # If song_name doesn't have mp3 extension, add it
        if not song_name.endswith('.mp3'):
            song_name += '.mp3'

        # Replace the spaces with hashes
        song_name = stringutils.remove_unwanted_chars(song_name)

        # The directory where we will download to.
        dw_dir = defaults.DEFAULT.SONG_TEMP_DIR
        logger.info("Saving the files to: {}".format(dw_dir))

        if not os.path.exists(dw_dir):
            os.makedirs(dw_dir)

        # Name of the temp file
        name = os.path.join(dw_dir, song_name)

        # Start downloading the song
        status = Download(url, name).download()

        if status:
            return name
        else:
            logger.critical("Downloader returned false!")

    except Exception as e:
        # traceback.print_exception(e)
        return e