async def play(self, ctx, *, query: str): """Plays a song. If there is a song currently in the queue, then it is queued until the next song is done playing. This command automatically searches as well from YouTube. The list of supported sites can be found here: https://rg3.github.io/youtube-dl/supportedsites.html """ if ctx.author.voice is None: return await ctx.send('You need to be in a voice channel.') vc = ctx.guild.voice_client if vc is None: vc = await ctx.invoke(self.summon) if vc is None: return try: source = await YTDLSource.from_url(ctx, query) except youtube_dl.DownloadError as e: return await ctx.send(e) embed = source.embed() queue = self.get_queue(ctx.guild) if not vc.is_playing() and not vc.is_paused(): time_until = 'Up next!' else: length = queue.songs.duration + vc.source.remaining time_until = utils.human_time(length) embed.add_field(name='Time until playing', value=time_until) await ctx.send(embed=embed) await queue.songs.put(source)
def mode_list(session_dir, args): """ List available sessions to stdout, if session name is set only list that session. """ if args.session: if not os.path.exists(os.path.join(session_dir, args.session)): fail("Invalid Session", logger=logger) sessions = [args.session] else: sessions = [] for d in os.listdir(session_dir): if d != ".keys": sessions.append(d) output = [] for session in sessions: # Session Volume Last Processed volnames = os.listdir(os.path.join(session_dir, session)) for volname in volnames: if args.volume and args.volume != volname: continue status_file = os.path.join(session_dir, session, volname, "status") last_processed = None try: with open(status_file) as f: last_processed = f.read().strip() except (OSError, IOError) as e: if e.errno == ENOENT: continue else: raise output.append((session, volname, last_processed)) if output: sys.stdout.write("%s %s %s\n" % ("SESSION".ljust(25), "VOLUME".ljust(25), "SESSION TIME".ljust(25))) sys.stdout.write("-" * 75) sys.stdout.write("\n") for session, volname, last_processed in output: sess_time = 'Session Corrupted' if last_processed: try: sess_time = human_time(last_processed) except TypeError: sess_time = 'Session Corrupted' sys.stdout.write( "%s %s %s\n" % (session.ljust(25), volname.ljust(25), sess_time.ljust(25))) if not output: if args.session or args.volume: fail("Invalid Session", logger=logger) else: sys.stdout.write("No sessions found.\n")
def mode_list(session_dir, args): """ List available sessions to stdout, if session name is set only list that session. """ if args.session: if not os.path.exists(os.path.join(session_dir, args.session)): fail("Invalid Session", logger=logger) sessions = [args.session] else: sessions = [] for d in os.listdir(session_dir): if d != ".keys": sessions.append(d) output = [] for session in sessions: # Session Volume Last Processed volnames = os.listdir(os.path.join(session_dir, session)) for volname in volnames: if args.volume and args.volume != volname: continue status_file = os.path.join(session_dir, session, volname, "status") last_processed = None try: with open(status_file) as f: last_processed = f.read().strip() except (OSError, IOError) as e: if e.errno == ENOENT: pass else: raise output.append((session, volname, last_processed)) if output: sys.stdout.write("%s %s %s\n" % ("SESSION".ljust(25), "VOLUME".ljust(25), "SESSION TIME".ljust(25))) sys.stdout.write("-"*75) sys.stdout.write("\n") for session, volname, last_processed in output: sess_time = 'Session Corrupted' if last_processed: try: sess_time = human_time(last_processed) except TypeError: sess_time = 'Session Corrupted' sys.stdout.write("%s %s %s\n" % (session.ljust(25), volname.ljust(25), sess_time.ljust(25))) if not output: if args.session or args.volume: fail("Invalid Session", logger=logger) else: sys.stdout.write("No sessions found.\n")
def embed(self): embed = discord.Embed() embed.title = f'Enqueued {self.entry.title}' embed.url = self.entry.url embed.add_field(name='Duration', value=utils.human_time(self.entry.duration)) if self.progress: embed.title = f'Currently playing {self.entry.title}' embed.add_field(name='Progress', value=utils.human_time(self.progress)) embed.add_field(name='Requester', value=self.requester, inline=False) embed.add_field( name='Skips', value=f'{len(self.skip_votes)}/{self.required_skips}') return embed
def train(use_gpu=True, epochs=40, verbose=500): train_dl, valid_dl = load_data(batch_size=4, split_rate=0.2, gpu=use_gpu) model = Net(use_gpu) opt = optim.Adadelta(model.parameters()) criterion = nn.BCELoss() start = timer() fit(epochs, model, criterion, opt, train_dl, valid_dl, verbose) end = timer() t = human_time(start, end) print('Total training time using {}: {}'.format(model.device, t))
def callback(self, data): print data if print_received: time = human_time(data.header.stamp) rospy.loginfo("Message received from {}".format(time)) position = list(data.position) position[0] = 0 data.position = tuple(position) self.pub_joint_states_desired.publish(data)
async def track_hook(self, event): if isinstance(event, lavalink.Events.TrackStartEvent): embed = discord.Embed() embed.url = event.track.uri embed.title = f'Now playing {event.track.title}' if not event.track.stream: embed.add_field(name='Duration', value=utils.human_time(event.track.duration // 1000)) embed.add_field(name='Requester', value=event.track.requester, inline=False) embed.set_thumbnail(url=event.track.thumbnail) await event.track.channel.send(embed=embed) elif isinstance(event, lavalink.Events.QueueEndEvent): await asyncio.sleep(60) if len(event.player.queue) == 0 and not event.player.is_playing and event.player.is_connected: await event.player.disconnect() channel = self.bot.get_channel(event.player.fetch('channel')) if channel: await channel.send('Disconnected because of inactivity.')
def uptime(self): delta = datetime.datetime.utcnow() - self.start_time return human_time(delta.total_seconds())
async def play(self, ctx, *, query): """Plays a song. If there is a song currently in the queue, then it is queued until the next song is done playing. This command automatically searches as well from YouTube. """ player = ctx.player if not player.is_connected: await ctx.invoke(self.summon) if not player.is_connected: return else: if ctx.author not in player.connected_channel.members: return await ctx.send(f'You must be in {player.connected_channel.name} to request songs.') query = query.strip('<>') if not url_rx.match(query): query = f'ytsearch:{query}' results = await ctx.bot.lavalink.get_tracks(query) if not results or not results['tracks']: return await ctx.send('Nothing found!') embed = discord.Embed() time_until = 0 time_remaining = 0 for track in player.queue: time_until += track.duration if player.is_playing: time_remaining = player.current.duration - player.position time_until += time_remaining time_until_playing = f'Up next!' if time_until == 0 else utils.human_time(time_until // 1000) if time_until == time_remaining and time_until != 0: time_until_playing += ' (Next!)' if results['loadType'] == 'PLAYLIST_LOADED': tracks = results['tracks'] duration = 0 for track in tracks: duration += track['info']['length'] await player.add(Track(track, ctx.author, ctx.channel)) embed.title = f'Enqueued {results["playlistInfo"]["name"]}' embed.add_field(name='Tracks', value=len(tracks)) embed.add_field(name='Duration', value=utils.human_time(duration // 1000)) embed.add_field(name='Time until playing', value=time_until_playing) await ctx.send(embed=embed) else: track = results['tracks'][0] embed.title = f'Enqueued {track["info"]["title"]}' embed.url = track['info']['uri'] if 'youtube' in embed.url: embed.set_thumbnail(url=f'https://img.youtube.com/vi/{track["info"]["identifier"]}/default.jpg') if not track['info']['isStream']: embed.add_field(name='Duration', value=utils.human_time(track['info']['length'] // 1000)) embed.add_field(name='Time until playing', value=time_until_playing) await ctx.send(embed=embed) await player.add(Track(track, ctx.author, ctx.channel)) if not player.is_playing: await player.play()