backend/gitsound.py
def pull_spotify_playlist(self, uid, pid):
        """Function to pull playlist from Spotify

        :param uid: user ID
        :type uid: string
        :param pid: playlist ID
        :type pid: string
        :returns: string -- stating status of pull (either successfull or not)

        """

        playlist_path = uid + "/" + pid

        util.check_if_git_playlist(self.git_dir, playlist_path)

        # grab tracks from spotify from pid
        results = self.sp.user_playlist_tracks(self.username, pid)
        results = results["items"]

        # get just a list of the track ids from the response
        remote_tracks = []
        for track in results:
            if track["track"]["id"] != None:  # only take spotify tracks
                remote_tracks.append(track["track"]["id"])

        # get local track ids
        with open(self.git_dir + playlist_path + "/index.txt") as f:
            local_tracks = f.read().splitlines()

        # merge tracks by adding if not added already. local takes precendence
        # does not preserve position of new remote tracks
        diff = False
        for remoteTrack in remote_tracks:
            if remoteTrack not in local_tracks:
                local_tracks.append(remoteTrack)
                diff = True

        # write tracks back to file
        with open(self.git_dir + playlist_path + "/index.txt", "w") as f:
            for track in local_tracks:
                print(track, file=f)

        # commit playlist changes if needed
        if diff:
            self.commit_changes_to_playlist(uid, pid)
            return 'Added and committed changes from remote.'
        return 'No changes committed, up to date with remote.'
Function to pull playlist from Spotify

        :param uid: user ID
        :type uid: string
        :param pid: playlist ID
        :type pid: string
        :returns: string -- stating status of pull (either successfull or not)

        
Function to pull playlist from Spotify
Function to pull playlist from Spotify
def pull_spotify_playlist(self, uid, pid):
        playlist_path = uid + "/" + pid
        util.check_if_git_playlist(self.git_dir, playlist_path)
        results = self.sp.user_playlist_tracks(self.username, pid)
        results = results["items"]
        remote_tracks = []
        for track in results:
            if track["track"]["id"] != None:  
                remote_tracks.append(track["track"]["id"])
        with open(self.git_dir + playlist_path + "/index.txt") as f:
            local_tracks = f.read().splitlines()
        diff = False
        for remoteTrack in remote_tracks:
            if remoteTrack not in local_tracks:
                local_tracks.append(remoteTrack)
                diff = True
        with open(self.git_dir + playlist_path + "/index.txt", "w") as f:
            for track in local_tracks:
                print(track, file=f)
        if diff:
            self.commit_changes_to_playlist(uid, pid)
            return 'Added and committed changes from remote.'
        return 'No changes committed, up to date with remote.'
def pull_spotify_playlist ( self , uid , pid ) : playlist_path = uid + "/" + pid util . check_if_git_playlist ( self . git_dir , playlist_path ) results = self . sp . user_playlist_tracks ( self . username , pid ) results = results [ "items" ] remote_tracks = [ ] for track in results : if track [ "track" ] [ "id" ] != None : remote_tracks . append ( track [ "track" ] [ "id" ] ) with open ( self . git_dir + playlist_path + "/index.txt" ) as f : local_tracks = f . read ( ) . splitlines ( ) diff = False for remoteTrack in remote_tracks : if remoteTrack not in local_tracks : local_tracks . append ( remoteTrack ) diff = True with open ( self . git_dir + playlist_path + "/index.txt" , "w" ) as f : for track in local_tracks : print ( track , file = f ) if diff : self . commit_changes_to_playlist ( uid , pid ) return 'Added and committed changes from remote.' return 'No changes committed, up to date with remote.'
Function to pull playlist from Spotify
Function to pull playlist from Spotify
"""Function to pull playlist from Spotify

        :param uid: user ID
        :type uid: string
        :param pid: playlist ID
        :type pid: string
        :returns: string -- stating status of pull (either successfull or not)

        """ # grab tracks from spotify from pid # get just a list of the track ids from the response # only take spotify tracks # get local track ids # merge tracks by adding if not added already. local takes precendence # does not preserve position of new remote tracks # write tracks back to file # commit playlist changes if needed
- stating status of pull (either successfull or not)
- stating status of pull ( either successfull or not )
self
uid
None
pid
None