async def delete_all(self, ctx): """Delete pending songs from autoplaylist""" delete_songs = set(read_lines(DELETE_AUTOPLAYLIST)) _songs = read_lines(AUTOPLAYLIST) songs = set(_songs) duplicates = len(_songs) - len(songs) failed = 0 succeeded = 0 for song in delete_songs: try: songs.remove(song) succeeded += 1 except KeyError as e: failed += 1 terminal.exception('Failed to delete all from autoplaylist') write_playlist(AUTOPLAYLIST, songs) empty_file(DELETE_AUTOPLAYLIST) await ctx.send( 'Successfully deleted {0} songs, {1} duplicates and failed {2}'. format(succeeded, duplicates, failed))
async def current_to_file(self, name=None, channel=None): if name == 'autoplaylist.txt': return await self.send('autoplaylist.txt is not a valid name', channel=channel) if not self.playlist: return await self.send('Empty playlist', delete_after=60, channel=channel) lines = [song.webpage_url for song in self.playlist] if not name: name = 'playlist-{}'.format(timestamp()) file = os.path.join(self.playlist_path, name) write_playlist(file, lines) await self.send(f'Playlist {name} created', channel=channel)
def delete_from_ap(deleted_vids): songs = set(read_lines(AUTOPLAYLIST)) changed = False for song in deleted_vids: try: songs.remove(song) changed = True except KeyError: pass if not changed: return write_playlist(AUTOPLAYLIST, songs)
async def add_all(self, ctx): """Add the pending songs to autoplaylist""" songs = set(read_lines(ADD_AUTOPLAYLIST)) invalid = [] for song in list(songs): if not test_url(song): songs.remove(song) invalid.append(song) if invalid: await ctx.send('Invalid url(s):\n%s' % ', '.join(invalid), delete_after=40) write_playlist(AUTOPLAYLIST, songs, mode='a') empty_file(ADD_AUTOPLAYLIST) amount = len(songs) await ctx.send('Added %s song(s) to autoplaylist' % amount)
def add_to_ap(new_vids): write_playlist(AUTOPLAYLIST, new_vids, mode='a')
def delete_from_list(deleted_vids): songs = set(read_lines(gachilist)) songs = songs - set(deleted_vids) write_playlist(gachilist, songs)
def add_to_list(new_vids): write_playlist(gachilist, new_vids, mode='a')