backend/gitsound.py
def add_song_to_playlist(self, uid, pid, songid):
        """Function to add song to playlist

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

        """

        playlist_path = os.path.join(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 = []
            for line in f.readlines():
                line = line.strip()
                songIds.append(line)

                if songid == line:
                    raise RuntimeError("Song is already in playlist")
            print(songid, file=f)

        # get the repo
        repo = pygit2.Repository(self.git_dir + playlist_path)

        # create a new blob for our new index
        file_blob = repo.create_blob_fromdisk(
            self.git_dir + playlist_path + "/index.txt")

        # build the tree
        new_tree = repo.TreeBuilder()

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

        new_tree.write()
Function to add song to playlist

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

        
Function to add song to playlist
Function to add song to playlist
def add_song_to_playlist(self, uid, pid, songid):
        playlist_path = os.path.join(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 = []
            for line in f.readlines():
                line = line.strip()
                songIds.append(line)
                if songid == line:
                    raise RuntimeError("Song is already in playlist")
            print(songid, file=f)
        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 add_song_to_playlist ( self , uid , pid , songid ) : playlist_path = os . path . join ( 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 = [ ] for line in f . readlines ( ) : line = line . strip ( ) songIds . append ( line ) if songid == line : raise RuntimeError ( "Song is already in playlist" ) print ( songid , file = f ) 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 add song to playlist
Function to add song to playlist
"""Function to add song to playlist

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

        """ # get the repo # create a new blob for our new index # build the tree # add the index file
None
self
uid
None
pid
playlist ID to add song to
playlist ID to add song to
songid
ID of song to add
ID of song to add