How to use ytmdl - 10 common examples

To help you get started, we’ve selected a few ytmdl examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github deepjyoti30 / ytmdl / ytmdl.py View on Github external
sys.exit(0)
    else:
        prepend.PREPEND(1)
        print('Downloaded!')

    prepend.PREPEND(1)
    print('Converting to mp3...')

    conv_name = utility.convert_to_mp3(path)

    if not conv_name:
        prepend.PREPEND(2)
        print('Something went wrong while converting!\a')
        exit(-1)

    prepend.PREPEND(1)
    print('Getting song data...')

    # TRACK_INFO = song.getData(song_name)
    TRACK_INFO = metadata.SEARCH_SONG(song_name, filters=[args.artist, args.album])

    # declare a variable to store the option
    option = 0

    if TRACK_INFO is False:
        # prepend.PREPEND(2)
        # print('Data \a')
        # exit(0)
        pass
    elif len(TRACK_INFO) == 0:
        prepend.PREPEND(2)
        print('No data was found!\a')
github deepjyoti30 / ytmdl / ytmdl.py View on Github external
option = song.setData(TRACK_INFO, is_quiet, conv_name)

        if type(option) is not int:
            prepend.PREPEND(2)
            print('Something went wrong while writing data!\a')
            sys.exit(0)

    # Get the directory where song is moved

    DIR = dir.cleanup(TRACK_INFO, option)
    prepend.PREPEND(1)
    print('Moving to {}...'.format(DIR))

    if not DIR:
        prepend.PREPEND(2)
        print('Something went wrong while moving!\a')
        sys.exit(0)
    else:
        prepend.PREPEND(1)
        print('Done')
github deepjyoti30 / ytmdl / ytmdl.py View on Github external
if is_quiet:
            prepend.PREPEND(1)
            print('Quiet is enabled')

        prepend.PREPEND(1)
        print('Searching Youtube for ', end='')
        print(Fore.LIGHTYELLOW_EX, end='')
        print(song_name, end='')
        print(Style.RESET_ALL)

        data, urls = yt.search(song_name, args.better_search,
                                kw=[args.artist, args.album])
        
        # Handle the exception if urls has len 0
        if len(urls) == 0:
            prepend.PREPEND(2)
            print("No song found. Please try again with a different keyword.")
            print(Style.RESET_ALL, end='')
            exit()

        if len(data) > 1 and not is_quiet:
            # Ask for a choice
            choice = song.getChoice(data, 'mp3')
        else:
            choice = 0

        link = 'https://youtube.com{}'.format(urls[int(choice)])

    # Declare a var to store the name of the yt video
    yt_title = data[choice]['title']

    prepend.PREPEND(1)
github deepjyoti30 / ytmdl / ytmdl / metadata.py View on Github external
def _search_tokens(song_name, song_list):
    """Search song in the cache based on simple each word matching."""
    song_name = remove_stopwords(remove_multiple_spaces(song_name).lower())
    tokens1 = song_name.split()
    cached_songs = song_list

    res = []
    for song in cached_songs:
        song_back = song
        song = song.track_name
        name = song.lower()
        name = remove_punct(name)
        name = remove_multiple_spaces(name)
        tokens2 = name.split()
        match = check_keywords(tokens1, tokens2)
        if match:
            dist = compute_jaccard(tokens1, tokens2)
            # if dist >= 1:
            res.append((song_back, dist))
github deepjyoti30 / ytmdl / ytmdl / cache.py View on Github external
def _search_tokens(self, song_name):
        """Search song in the cache based on simple each word matching."""
        song_name = remove_stopwords(remove_multiple_spaces(song_name).lower())
        tokens1 = song_name.split()
        cached_songs = self.list_mp3()

        res = []
        for song in cached_songs:
            name = os.path.splitext(song)[0].lower()
            title = name
            name = remove_punct(name)
            name = remove_multiple_spaces(name)
            tokens2 = name.split()
            match = check_keywords(tokens1, tokens2)
            if match:
                dist = compute_jaccard(tokens1, tokens2)
                res.append((song_name, song, title, dist))
        res = sorted(res, key=lambda x: x[-1], reverse=True)
        if res and res[0][-1] > 0:
github deepjyoti30 / ytmdl / ytmdl / metadata.py View on Github external
def _search_tokens(song_name, song_list):
    """Search song in the cache based on simple each word matching."""
    song_name = remove_stopwords(remove_multiple_spaces(song_name).lower())
    tokens1 = song_name.split()
    cached_songs = song_list

    res = []
    for song in cached_songs:
        song_back = song
        song = song.track_name
        name = song.lower()
        name = remove_punct(name)
        name = remove_multiple_spaces(name)
        tokens2 = name.split()
        match = check_keywords(tokens1, tokens2)
        if match:
            dist = compute_jaccard(tokens1, tokens2)
            # if dist >= 1:
            res.append((song_back, dist))
    res = sorted(res, key=lambda x: x[1], reverse=True)

    # Return w/o the dist values
    for i in range(0, len(res)):
        res[i] = res[i][0]
    return res
github deepjyoti30 / ytmdl / ytmdl / cache.py View on Github external
def _search_tokens(self, song_name):
        """Search song in the cache based on simple each word matching."""
        song_name = remove_stopwords(remove_multiple_spaces(song_name).lower())
        tokens1 = song_name.split()
        cached_songs = self.list_mp3()

        res = []
        for song in cached_songs:
            name = os.path.splitext(song)[0].lower()
            title = name
            name = remove_punct(name)
            name = remove_multiple_spaces(name)
            tokens2 = name.split()
            match = check_keywords(tokens1, tokens2)
            if match:
                dist = compute_jaccard(tokens1, tokens2)
                res.append((song_name, song, title, dist))
        res = sorted(res, key=lambda x: x[-1], reverse=True)
        if res and res[0][-1] > 0:
            return res[0][2], self.get_full_location(res[0][1])
        else:
            return None
github deepjyoti30 / ytmdl / ytmdl.py View on Github external
else:
            choice = 0

        link = 'https://youtube.com{}'.format(urls[int(choice)])

    # Declare a var to store the name of the yt video
    yt_title = data[choice]['title']

    prepend.PREPEND(1)
    print('Downloading ', end='')
    print(Fore.LIGHTMAGENTA_EX, end='')
    print(yt_title, end=' ')
    print(Style.RESET_ALL, end='')
    print('in', end=' ')
    print(Fore.LIGHTYELLOW_EX, end='')
    print(defaults.DEFAULT.SONG_QUALITY + 'kbps', end='')
    print(Style.RESET_ALL)
    path = yt.dw(link, yt_title)

    if not path:
        prepend.PREPEND(2)
        print('Something went wrong while downloading!\a')
        sys.exit(0)
    else:
        prepend.PREPEND(1)
        print('Downloaded!')

    prepend.PREPEND(1)
    print('Converting to mp3...')

    conv_name = utility.convert_to_mp3(path)
github deepjyoti30 / ytmdl / ytmdl / yt.py View on Github external
def get_youtube_streams(url):
    """Get both audio & video stream urls for youtube using youtube-dl.

    PS: I don't know how youtube-dl does the magic
    """
    cli = "youtube-dl -g {}".format(url)
    output, error = utility.exe(cli)
    stream_urls = output.split("\n")

    url = stream_urls[1]
    return url
github deepjyoti30 / ytmdl / ytmdl / yt.py View on Github external
def get_youtube_streams(url):
    """Get both audio & video stream urls for youtube using youtube-dl.

    PS: I don't know how youtube-dl does the magic
    """
    cli = "youtube-dl -g {}".format(url)
    output, error = utility.exe(cli)
    stream_urls = output.split("\n")

    url = stream_urls[1]
    return url