backend/gitsound.py
def remove_song_from_playlist(self, uid, pid, songid):
        """Function to remove song from playlist

        :param uid: user ID
        :type uid: string
        :param pid: playlist ID to remove song from
        :type pid: string
        :param songid: ID of song to remove
        :type songid: string
        :raises: RuntimeError

        """

        playlist_path = uid + "/" + pid

        util.check_if_git_playlist(self.git_dir, playlist_path)

        with open(self.git_dir + playlist_path + "/index.txt", "r+") as f:
            songIds = []
            found_song = False
            for line in f.readlines():
                line = line.strip()

                if songid == line:
                    found_song = True
                else:
                    songIds.append(line)

            if found_song == False:
                raise RuntimeError("playlist does not have song.")

            # go to the start of the text file
            f.seek(0)

            for ID in songIds:
                print(ID, file=f)

            # ignore the rest of the text file (parts that were already there)
            f.truncate()

        repo = pygit2.Repository(self.git_dir + playlist_path)

        # create the file blob
        file_blob = repo.create_blob_fromdisk(
            self.git_dir + playlist_path + "/index.txt")

        new_tree = repo.TreeBuilder()

        # insert it into the tree
        new_tree.insert("index.txt", file_blob,
                        os.stat(self.git_dir + playlist_path + "/index.txt").st_mode)

        new_tree.write()
Function to remove song from playlist

        :param uid: user ID
        :type uid: string
        :param pid: playlist ID to remove song from
        :type pid: string
        :param songid: ID of song to remove
        :type songid: string
        :raises: RuntimeError

        
Function to remove song from playlist
Function to remove song from playlist
def remove_song_from_playlist(self, uid, pid, songid):
        playlist_path = uid + "/" + pid
        util.check_if_git_playlist(self.git_dir, playlist_path)
        with open(self.git_dir + playlist_path + "/index.txt", "r+") as f:
            songIds = []
            found_song = False
            for line in f.readlines():
                line = line.strip()
                if songid == line:
                    found_song = True
                else:
                    songIds.append(line)
            if found_song == False:
                raise RuntimeError("playlist does not have song.")
            f.seek(0)
            for ID in songIds:
                print(ID, file=f)
            f.truncate()
        repo = pygit2.Repository(self.git_dir + playlist_path)
        file_blob = repo.create_blob_fromdisk(
            self.git_dir + playlist_path + "/index.txt")
        new_tree = repo.TreeBuilder()
        new_tree.insert("index.txt", file_blob,
                        os.stat(self.git_dir + playlist_path + "/index.txt").st_mode)
        new_tree.write()
def remove_song_from_playlist ( self , uid , pid , songid ) : playlist_path = uid + "/" + pid util . check_if_git_playlist ( self . git_dir , playlist_path ) with open ( self . git_dir + playlist_path + "/index.txt" , "r+" ) as f : songIds = [ ] found_song = False for line in f . readlines ( ) : line = line . strip ( ) if songid == line : found_song = True else : songIds . append ( line ) if found_song == False : raise RuntimeError ( "playlist does not have song." ) f . seek ( 0 ) for ID in songIds : print ( ID , file = f ) f . truncate ( ) repo = pygit2 . Repository ( self . git_dir + playlist_path ) file_blob = repo . create_blob_fromdisk ( self . git_dir + playlist_path + "/index.txt" ) new_tree = repo . TreeBuilder ( ) new_tree . insert ( "index.txt" , file_blob , os . stat ( self . git_dir + playlist_path + "/index.txt" ) . st_mode ) new_tree . write ( )
Function to remove song from playlist
Function to remove song from playlist
"""Function to remove song from playlist

        :param uid: user ID
        :type uid: string
        :param pid: playlist ID to remove song from
        :type pid: string
        :param songid: ID of song to remove
        :type songid: string
        :raises: RuntimeError

        """ # go to the start of the text file # ignore the rest of the text file (parts that were already there) # create the file blob # insert it into the tree
None
self
uid
None
pid
playlist ID to remove song from
playlist ID to remove song from
songid
ID of song to remove
ID of song to remove