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 add_from_playlist(self, name, channel=None): if channel is None: channel = self.channel lines = read_lines(os.path.join(self.playlist_path, name)) if lines is None: return await self.send('Invalid playlist name', channel=channel) await self.send('Processing {} songs'.format(len(lines)), delete_after=60, channel=channel) for line in lines: await self._add_url(line, no_message=True) await self.send('Enqueued %s' % name, 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 _get_playlist(self, name): playlist = os.path.join(self.playlist_path, name) lines = read_lines(playlist) return lines
def reload_gachilist(self): self.bot.gachilist = read_lines(os.path.join(PLAYLISTS, 'gachi.txt')) self.gachilist = self.bot.gachilist
def delete_from_list(deleted_vids): songs = set(read_lines(gachilist)) songs = songs - set(deleted_vids) write_playlist(gachilist, songs)