Beispiel #1
0
def console_entry_point():
    '''
    This is where all the console processing magic happens.
    Its super simple, rudimentary even but, it's dead simple & it works.
    '''

    if '--help' in sys.argv or '-h' in sys.argv or len(sys.argv) == 1:
        print(help_notice)

        #! We use 'return None' as a convenient exit/break from the function
        return None

    spotifyClient.initialize(
        clientId='4fe3fecfe5334023a1472516cc99d805',
        clientSecret='0f02b7c483c04257984695007a4a8d5c'
        )

    downloader = DownloadManager()

    for request in sys.argv[1:]:
        if 'open.spotify.com' in request and 'track' in request:
            print('Fetching Song...')
            song = SongObj.from_url(request)

            if song.get_youtube_link() != None:
                downloader.download_single_song(song)
            else:
                print('Skipping %s (%s) as no match could be found on youtube' % (
                    song.get_song_name(), request
                ))

        elif 'open.spotify.com' in request and 'album' in request:
            print('Fetching Album...')
            songObjList = get_album_tracks(request)

            downloader.download_multiple_songs(songObjList)

        elif 'open.spotify.com' in request and 'playlist' in request:
            print('Fetching Playlist...')
            songObjList = get_playlist_tracks(request)

            downloader.download_multiple_songs(songObjList)

        elif request.endswith('.spotdlTrackingFile'):
            print('Preparing to resume download...')
            downloader.resume_download_from_tracking_file(request)

        else:
            print('Searching for song "%s"...' % request)
            try:
                song = search_for_song(request)
                downloader.download_single_song(song)

            except Exception:
                print('No song named "%s" could be found on spotify' % request)

    downloader.close()
Beispiel #2
0
def dlmusic():
    Dir=Dirfield.get()
    url=musfield.get()
    temp=SongObj.from_url(url)
    currdir=os.getcwd()
    os.chdir(Dir)
    download=DownloadManager()
    download.download_single_song(songObj=temp)
    os.remove('./Temp')
    os.chdir(currdir)
    return
Beispiel #3
0
def console_entry_point():
    '''
    This is where all the console processing magic happens.
    Its super simple, rudimentary even but, it's dead simple & it works.
    '''

    if '--help' in cliArgs or '-h' in cliArgs:
        print(help_notice)

        #! We use 'return None' as a convenient exit/break from the function
        return None

    if '--quiet' in cliArgs:
        #! removing --quiet so it doesnt mess up with the download
        cliArgs.remove('--quiet')
        #! make stdout & stderr silent
        sys.stdout = quiet()
        sys.stderr = quiet()

    initialize(clientId='4fe3fecfe5334023a1472516cc99d805',
               clientSecret='0f02b7c483c04257984695007a4a8d5c')

    downloader = DownloadManager()

    for request in cliArgs[1:]:
        if ('open.spotify.com' in request
                and 'track' in request) or 'spotify:track:' in request:
            print('Fetching Song...')
            song = SongObj.from_url(request)

            if song.get_youtube_link() != None:
                downloader.download_single_song(song)
            else:
                print(
                    'Skipping %s (%s) as no match could be found on youtube' %
                    (song.get_song_name(), request))

        elif ('open.spotify.com' in request
              and 'album' in request) or 'spotify:album:' in request:
            print('Fetching Album...')
            songObjList = get_album_tracks(request)

            downloader.download_multiple_songs(songObjList)

        elif ('open.spotify.com' in request
              and 'playlist' in request) or 'spotify:playlist:' in request:
            print('Fetching Playlist...')
            songObjList = get_playlist_tracks(request)

            downloader.download_multiple_songs(songObjList)

        elif request.endswith('.txt'):
            print('Fetching songs from %s...' % request)
            songObjList = []

            with open(request, 'r') as songFile:
                for songLink in songFile.readlines():
                    song = SongObj.from_url(songLink)
                    songObjList.append(song)

            downloader.download_multiple_songs(songObjList)

        elif request.endswith('.spotdlTrackingFile'):
            print('Preparing to resume download...')
            downloader.resume_download_from_tracking_file(request)

        else:
            print('Searching for song "%s"...' % request)
            try:
                song = search_for_song(request)
                downloader.download_single_song(song)

            except Exception:
                print('No song named "%s" could be found on spotify' % request)

    downloader.close()
def console_entry_point():
    '''
    This is where all the console processing magic happens.
    Its super simple, rudimentary even but, it's dead simple & it works.
    '''
    arguments = parse_arguments()

    spotifyClient.initialize(clientId='03eb56e5ab2843e98507b3a6a0359a56',
                             clientSecret='4e6600fae80845ef8dab67ccaaecee4d')

    if arguments.path:
        if not os.path.isdir(arguments.path):
            sys.exit("The output directory doesn't exist.")
        print(f"Will download to: {os.path.abspath(arguments.path)}")
        os.chdir(arguments.path)

    downloader = DownloadManager()

    for request in arguments.url:
        if 'open.spotify.com' in request and 'track' in request:
            print('Fetching Song...')
            song = SongObj.from_url(request)

            if song.get_youtube_link() is not None:
                downloader.download_single_song(song)
            else:
                print(
                    'Skipping %s (%s) as no match could be found on youtube' %
                    (song.get_song_name(), request))

        elif 'open.spotify.com' in request and 'album' in request:
            print('Fetching Album...')
            songObjList = get_album_tracks(request)

            downloader.download_multiple_songs(songObjList)

        elif 'open.spotify.com' in request and 'playlist' in request:
            print('Fetching Playlist...')
            songObjList = get_playlist_tracks(request)

            downloader.download_multiple_songs(songObjList)

        elif 'open.spotify.com' in request and 'artist' in request:
            print('Fetching artist...')
            artistObjList = get_artist_tracks(request)

            downloader.download_multiple_songs(artistObjList)

        elif request.endswith('.spotdlTrackingFile'):
            print('Preparing to resume download...')
            downloader.resume_download_from_tracking_file(request)

        else:
            print('Searching for song "%s"...' % request)
            try:
                song = search_for_song(request)
                downloader.download_single_song(song)

            except Exception:
                print('No song named "%s" could be found on spotify' % request)

    downloader.close()
Beispiel #5
0
def console_entry_point():
    """
    This is where all the console processing magic happens.
    Its super simple, rudimentary even but, it's dead simple & it works.
    """

    if "--help" in cliArgs or "-h" in cliArgs:
        print(help_notice)

        #! We use 'return None' as a convenient exit/break from the function
        return None

    initialize(
        clientId="4fe3fecfe5334023a1472516cc99d805",
        clientSecret="0f02b7c483c04257984695007a4a8d5c",
    )

    downloader = DownloadManager()

    for request in cliArgs[1:]:
        if "?" in request:
            # strip unnecessary data for both url and uri
            # e.g https://open.spotify.com/track/4Q34FP1AT7GEl9oLgNtiWj?context=spotify%3Aplaylist%3A37i9dQZF1DXcBWIGoYBM5M&si=DlMAsJ5pSD6tdUSn2XqB0g
            # becomes https://open.spotify.com/track/4Q34FP1AT7GEl9oLgNtiWj
            # e.g spotify:track:4Q34FP1AT7GEl9oLgNtiWj?context=spotify%3Aplaylist%3A37i9dQZF1DXcBWIGoYBM5M
            # becomes spotify:track:4Q34FP1AT7GEl9oLgNtiWj

            request = request[:request.find("?")]
        if "open.spotify.com" in request:
            # it's a url
            if "track" in request:
                print("Fetching Song...")
                song = SongObj.from_url(request)

                if song.get_youtube_link() != None:
                    downloader.download_single_song(song)
                else:
                    print(
                        "Skipping %s (%s) as no match could be found on youtube"
                        % (song.get_song_name(), request))

            elif "album" in request:
                print("Fetching Album...")
                songObjList = get_album_tracks(request)

                downloader.download_multiple_songs(songObjList)

            elif "playlist" in request:
                print("Fetching Playlist...")
                songObjList = get_playlist_tracks(request)

                downloader.download_multiple_songs(songObjList)
        elif "spotify:" in request:
            # it's a URI with format Spotify:...:ID
            if "track:" in request:
                print("Fetching Song...")
                # yes, passing a URI to this function still works coz it relies on another
                # spotipy function that simply extracts the ID, ideally u can just pass the ID
                # and the track downloads
                song = SongObj.from_url(request)

                if song.get_youtube_link() != None:
                    downloader.download_single_song(song)
                else:
                    print(
                        f"Skipping {song.get_song_name()} ({request}) as no match could be found on youtube"
                    )

            elif "album:" in request:
                print("Fetching Album...")
                songObjList = get_album_tracks(request)

                downloader.download_multiple_songs(songObjList)

            elif "playlist:" in request:
                print("Fetching Playlist...")
                songObjList = get_playlist_tracks(request)

                downloader.download_multiple_songs(songObjList)

        elif request.endswith(".spotdlTrackingFile"):
            print("Preparing to resume download...")
            downloader.resume_download_from_tracking_file(request)

        else:
            print('Searching for song "%s"...' % request)
            try:
                song = search_for_song(request)
                downloader.download_single_song(song)

            except Exception:
                print('No song named "%s" could be found on spotify' % request)

    downloader.close()