Giter Club home page Giter Club logo

Comments (1)

TheShadowtf avatar TheShadowtf commented on July 25, 2024

Hi
I had the same problem and I figure it out why this is happening. This is because the spotify API can only do 100 tracks at a time and if your playlist have more then 100 it will crash. You can make multiple playlist with 100 songs and do them one by one. I fixed the problem in the code by creating a counter to go from 100 to 0 so it will still download and not crash but will only download the first 100 songs. The problem is in write_tracks and this is the code that I have:

def write_tracks(text_file: str, tracks: dict):
    # This includins the name, artist, and spotify URL. Each is delimited by a comma.
    with open(text_file, 'w+', encoding='utf-8') as file_out:
        count = 100 #this is the counter from 100
        while count > 0: #will run until is 0
            for item in tracks['items']:
                count = -1 #subtract one from it each time
                if 'track' in item:
                    track = item['track']
                else:
                    track = item
                try:
                    track_url = track['external_urls']['spotify']
                    track_name = track['name']
                    track_artist = track['artists'][0]['name']
                    album_art_url = track['album']['images'][0]['url']
                    csv_line = track_name + "," + track_artist + "," + track_url + "," + album_art_url + "\n"
                    try:
                        file_out.write(csv_line)
                    except UnicodeEncodeError:  # Most likely caused by non-English song names
                        print("Track named {} failed due to an encoding error. This is \
                            most likely due to this song having a non-English name.".format(track_name))
                except KeyError:
                    print(u'Skipping track {0} by {1} (local only?)'.format(
                            track['name'], track['artists'][0]['name']))
            # 1 page = 50 results, check if there are more pages
            if tracks['next']:
                tracks = spotify.next(tracks)
            else:
                break

I will try to make it download more then that but I don't have time now:)
I hope the creator of this will fix this soon:)
Hope it "helps" a bit:)

from spotify-to-mp3-python.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.