-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmusic.rs
721 lines (674 loc) · 23 KB
/
music.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
use crate::utils::basic_functions::shorten;
use rand::Rng;
use regex::Regex;
use serde_json;
use serenity::{
async_trait,
builder::CreateMessage,
client::Context,
framework::standard::{macros::command, Args, CommandResult, Delimiter},
http::Http,
model::{channel::Message, prelude::ChannelId},
prelude::Mutex,
};
use std::{
sync::atomic::Ordering,
sync::{atomic::AtomicUsize, Arc},
time::Duration,
};
use tracing::error;
use youtube_dl::{YoutubeDl, YoutubeDlOutput};
use songbird::{
input::Metadata,
input::{ytdl, Input},
Call, Event, EventContext, EventHandler as VoiceEventHandler, TrackEvent,
};
const JOIN_MSG: &str = "Please, connect the bot to the voice channel you are currently on first with the `join` command.";
const QUEUE_EMPTY_MSG: &str = "The queue is empty";
const NOTIN_VC_MSG: &str = "Not in a voice channel";
const NOTHING_PLAYING: &str = "Nothing playing";
const MAX_PLAYLIST: usize = 25;
struct TrackEndNotifier {
chan_id: ChannelId,
http: Arc<Http>,
handler_lock: Arc<Mutex<Call>>,
}
#[async_trait]
impl VoiceEventHandler for TrackEndNotifier {
async fn act(&self, ctx: &EventContext<'_>) -> Option<Event> {
if let EventContext::Track(_track_list) = ctx {
let handler = self.handler_lock.lock().await;
if let Some(np) = handler.queue().current() {
let metadata = np.metadata();
if let Err(why) = self
.chan_id
.send_message(&self.http, |m| {
_now_playing_embed(m, metadata.as_ref().clone());
m
})
.await
{
error!("Error sending message: {:?}", why);
}
} else {
if let Err(why) = self.chan_id.say(&self.http, "Queue finished").await {
error!("Error sending message: {:?}", why);
}
}
}
None
}
}
struct ChannelIdleChecker {
handler_lock: Arc<Mutex<Call>>,
elapsed: Arc<AtomicUsize>,
}
#[async_trait]
impl VoiceEventHandler for ChannelIdleChecker {
async fn act(&self, _ctx: &EventContext<'_>) -> Option<Event> {
let mut handler = self.handler_lock.lock().await;
if handler.queue().is_empty() {
if (self.elapsed.fetch_add(1, Ordering::Relaxed) + 1) > 15 {
let _ = handler.leave().await;
}
} else {
self.elapsed.store(0, Ordering::Relaxed);
}
None
}
}
async fn _join(ctx: &Context, msg: &Message) -> Option<Arc<Mutex<Call>>> {
let guild = msg.guild(&ctx.cache).await.unwrap();
if let Some(connect_to) = guild
.voice_states
.get(&msg.author.id)
.and_then(|voice_state| voice_state.channel_id)
{
let manager = songbird::get(ctx)
.await
.expect("Songbird Voice client placed in at initialisation.")
.clone();
let (handler_lock, success) = manager.join(guild.id, connect_to).await;
if let Err(why) = success {
error!("Error while joining voice channel: {:?}", why);
return None;
}
{
let mut handler = handler_lock.lock().await;
handler.add_global_event(
Event::Track(TrackEvent::End),
TrackEndNotifier {
chan_id: msg.channel_id,
http: ctx.http.clone(),
handler_lock: handler_lock.clone(),
},
);
handler.add_global_event(
Event::Periodic(Duration::from_secs(60), None),
ChannelIdleChecker {
handler_lock: handler_lock.clone(),
elapsed: Default::default(),
},
);
}
return Some(handler_lock);
}
None
}
/// Joins me to the voice channel you are currently on.
#[command]
#[aliases("connect")]
async fn join(ctx: &Context, msg: &Message) -> CommandResult {
if _join(ctx, msg).await.is_some() {
msg.react(ctx, '✅').await?;
} else {
msg.channel_id.say(ctx, NOTIN_VC_MSG).await?;
}
Ok(())
}
/// Disconnects me from the voice channel if im in one.
#[command]
async fn leave(ctx: &Context, msg: &Message) -> CommandResult {
let guild_id = msg.guild(&ctx.cache).await.unwrap().id;
let manager = songbird::get(ctx)
.await
.expect("Songbird Voice client placed in at initialisation.")
.clone();
if manager.get(guild_id).is_some() {
if let Err(e) = manager.remove(guild_id).await {
msg.channel_id.say(ctx, format!("Failed: {:?}", e)).await?;
}
msg.react(ctx, '✅').await?;
} else {
msg.channel_id.say(ctx, JOIN_MSG).await?;
}
Ok(())
}
/// Adds a song to the queue.
///
/// Usage: `play starmachine2000`
/// or `play https://www.youtube.com/watch?v=dQw4w9WgXcQ`
#[command]
#[min_args(1)]
#[aliases(p)]
async fn play(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
let mut embeded = false;
let mut query = args.message().to_string();
if query.starts_with('<') && query.ends_with('>') {
embeded = true;
let re = Regex::new("[<>]").unwrap();
query = re.replace_all(&query, "").into_owned();
}
if !embeded {
if let Err(_) = ctx
.http
.edit_message(
msg.channel_id.0,
msg.id.0,
&serde_json::json!({"flags" : 4}),
)
.await
{
if query.starts_with("http") {
msg.channel_id
.say(ctx, "Please, put the url between <> so it doesn't embed.")
.await?;
}
}
}
let guild_id = msg.guild(&ctx.cache).await.unwrap().id;
let manager = songbird::get(ctx)
.await
.expect("Songbird Voice client placed in at initialisation.")
.clone();
let handler_lock = match manager.get(guild_id) {
Some(hl) => hl,
None => match _join(ctx, msg).await {
Some(hl) => hl,
None => {
msg.channel_id.say(ctx, NOTIN_VC_MSG).await?;
return Ok(());
}
},
};
let loading_msg = msg.channel_id.say(ctx, "Loading...").await?;
let mut sources: Vec<Input> = Vec::new();
if let Ok(result) = YoutubeDl::new(query).run().await {
match result {
YoutubeDlOutput::Playlist(p) => {
if let Some(playlist) = p.entries {
for s in playlist.clone().into_iter().take(MAX_PLAYLIST) {
match ytdl(&format!("https://www.youtube.com/watch?v={}", s.id)).await {
Ok(mut source) => {
source.metadata.title = Some(s.title);
sources.push(source)
}
Err(why) => error!("Err starting source: {:?}", why),
}
}
}
}
YoutubeDlOutput::SingleVideo(s) => match ytdl(&s.webpage_url.clone().unwrap()).await {
Ok(mut source) => {
source.metadata.title = Some(s.title);
sources.push(source)
}
Err(why) => error!("Err starting source: {:?}", why),
},
}
}
let _ = loading_msg.delete(ctx).await;
if sources.is_empty() {
msg.channel_id
.say(ctx, "Couldn't find any result for the query")
.await?;
return Ok(());
}
let mut handler = handler_lock.lock().await;
let sources_len = sources.len();
if sources_len > 1 {
msg.channel_id
.say(ctx, format!("__**Queued:**__ `{}` tracks", sources_len))
.await?;
} else {
let metadata = sources.first().unwrap().metadata.clone();
if handler.queue().current().is_none() {
msg.channel_id
.send_message(ctx, |m| {
_now_playing_embed(m, metadata);
m
})
.await?;
} else {
msg.channel_id
.say(
ctx,
format!(
"__**Queued:**__ `{}` | `{}`",
metadata.title.unwrap(),
_duration_format(metadata.duration)
),
)
.await?;
}
}
for source in sources {
handler.enqueue_source(source)
}
Ok(())
}
/// Stops the current player (clears song queue).
#[command]
async fn stop(ctx: &Context, msg: &Message) -> CommandResult {
let guild_id = msg.guild(&ctx.cache).await.unwrap().id;
let manager = songbird::get(ctx)
.await
.expect("Songbird Voice client placed in at initialisation.")
.clone();
if let Some(handler_lock) = manager.get(guild_id) {
let handler = handler_lock.lock().await;
let queue = handler.queue();
if queue.current().is_some() {
queue.stop();
msg.react(ctx, '✅').await?;
} else {
msg.channel_id.say(ctx, NOTHING_PLAYING).await?;
}
} else {
msg.channel_id.say(ctx, JOIN_MSG).await?;
}
Ok(())
}
/// Show the song queue.
#[command]
async fn queue(ctx: &Context, msg: &Message) -> CommandResult {
let guild_id = msg.guild(&ctx.cache).await.unwrap().id;
let manager = songbird::get(ctx)
.await
.expect("Songbird Voice client placed in at initialisation.")
.clone();
if let Some(handler_lock) = manager.get(guild_id) {
let handler = handler_lock.lock().await;
let queue = handler.queue().current_queue();
if !queue.is_empty() {
let mut queue_str = String::new();
let metadata = queue[0].metadata();
queue_str += &format!(
"__**Now playing:**__\n```yaml\n{} | {}\n```",
shorten(&metadata.title.clone().unwrap(), 40),
_duration_format(metadata.duration)
);
if queue.len() > 1 {
queue_str += "\n__**Queue:**__\n```yaml\n";
for (index, track) in queue[1..].iter().take(10).enumerate() {
let metadata = track.metadata();
queue_str += &format!(
"{}: {} | {}\n",
index + 1,
shorten(&metadata.title.clone().unwrap(), 40),
_duration_format(metadata.duration)
);
}
if queue.len() > 10 {
queue_str += &format!("... {}", queue.len());
}
queue_str += "\n```";
}
queue_str = queue_str.replace("@", "@\u{200B}");
msg.channel_id
.send_message(ctx.clone(), |m| {
m.embed(|e| {
e.description(&queue_str);
e
})
})
.await?;
} else {
msg.channel_id.say(ctx, QUEUE_EMPTY_MSG).await?;
}
} else {
msg.channel_id.say(ctx, JOIN_MSG).await?;
}
Ok(())
}
/// Clears the song queue.
#[command]
async fn clear_queue(ctx: &Context, msg: &Message) -> CommandResult {
let guild_id = msg.guild(&ctx.cache).await.unwrap().id;
let manager = songbird::get(ctx)
.await
.expect("Songbird Voice client placed in at initialisation.")
.clone();
if let Some(handler_lock) = manager.get(guild_id) {
let handler = handler_lock.lock().await;
let queue = handler.queue();
if !queue.is_empty() {
queue.modify_queue(|q| q.truncate(1));
msg.react(ctx, '✅').await?;
} else {
msg.channel_id.say(ctx, QUEUE_EMPTY_MSG).await?;
}
} else {
msg.channel_id.say(ctx, JOIN_MSG).await?;
}
Ok(())
}
/// Shuffles the song queue.
#[command]
async fn shuffle(ctx: &Context, msg: &Message) -> CommandResult {
let guild_id = msg.guild(&ctx.cache).await.unwrap().id;
let manager = songbird::get(ctx)
.await
.expect("Songbird Voice client placed in at initialisation.")
.clone();
if let Some(handler_lock) = manager.get(guild_id) {
let handler = handler_lock.lock().await;
let queue = handler.queue();
if !queue.is_empty() {
queue.modify_queue(|q| {
let mut rng = rand::thread_rng();
let mut i = q.len();
while i >= 2 {
i -= 1;
q.swap(i, rng.gen_range(1, i + 1));
}
});
msg.react(ctx, '✅').await?;
} else {
msg.channel_id.say(ctx, QUEUE_EMPTY_MSG).await?;
}
} else {
msg.channel_id.say(ctx, JOIN_MSG).await?;
}
Ok(())
}
/// Skips the current song being played.
#[command]
#[aliases(next)]
async fn skip(ctx: &Context, msg: &Message) -> CommandResult {
let guild_id = msg.guild(&ctx.cache).await.unwrap().id;
let manager = songbird::get(ctx)
.await
.expect("Songbird Voice client placed in at initialisation.")
.clone();
if let Some(handler_lock) = manager.get(guild_id) {
let handler = handler_lock.lock().await;
let queue = handler.queue();
if queue.current().is_some() {
let _ = queue.skip();
msg.react(ctx, '✅').await?;
} else {
msg.channel_id.say(ctx, NOTHING_PLAYING).await?;
}
} else {
msg.channel_id.say(ctx, JOIN_MSG).await?;
}
Ok(())
}
/// Pauses the current song.
#[command]
async fn pause(ctx: &Context, msg: &Message) -> CommandResult {
let guild_id = msg.guild(&ctx.cache).await.unwrap().id;
let manager = songbird::get(ctx)
.await
.expect("Songbird Voice client placed in at initialisation.")
.clone();
if let Some(handler_lock) = manager.get(guild_id) {
let handler = handler_lock.lock().await;
let queue = handler.queue();
if queue.current().is_some() {
let _ = queue.pause();
msg.react(ctx, '✅').await?;
} else {
msg.channel_id.say(ctx, NOTHING_PLAYING).await?;
}
} else {
msg.channel_id.say(ctx, JOIN_MSG).await?;
}
Ok(())
}
/// Resumes the current song.
#[command]
#[aliases(unpause)]
async fn resume(ctx: &Context, msg: &Message) -> CommandResult {
let guild_id = msg.guild(&ctx.cache).await.unwrap().id;
let manager = songbird::get(ctx)
.await
.expect("Songbird Voice client placed in at initialisation.")
.clone();
if let Some(handler_lock) = manager.get(guild_id) {
let handler = handler_lock.lock().await;
let queue = handler.queue();
if queue.current().is_some() {
let _ = queue.resume();
msg.react(ctx, '✅').await?;
} else {
msg.channel_id.say(ctx, NOTHING_PLAYING).await?;
}
} else {
msg.channel_id.say(ctx, JOIN_MSG).await?;
}
Ok(())
}
/// Displays the information about the currently playing song.
#[command]
#[aliases(np, nowplaying, playing)]
async fn now_playing(ctx: &Context, msg: &Message) -> CommandResult {
let guild_id = msg.guild(&ctx.cache).await.unwrap().id;
let manager = songbird::get(ctx)
.await
.expect("Songbird Voice client placed in at initialisation.")
.clone();
if let Some(handler_lock) = manager.get(guild_id) {
let handler = handler_lock.lock().await;
let queue = handler.queue();
if let Some(np) = queue.current() {
let metadata = np.metadata();
msg.channel_id
.send_message(ctx, |m| {
_now_playing_embed(m, metadata.as_ref().clone());
m
})
.await?;
} else {
msg.channel_id.say(ctx, NOTHING_PLAYING).await?;
}
} else {
msg.channel_id.say(ctx, JOIN_MSG).await?;
}
Ok(())
}
// /// Change repeat mode.
// ///
// /// Usage: `repeat <one|all|off>`
// /// or `repeat one`
// #[command]
// #[num_args(1)]
// async fn repeat(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
// let mode = args.message();
// let guild_id = msg.guild(&ctx.cache).await.unwrap().id;
// let data = ctx.data.read().await;
// let player_lock = data
// .get::<PlayerManager>()
// .cloned()
// .expect("Expected PlayerManger in TypeMap");
// let mut pm = player_lock.write().await;
// if let Some(player) = pm.get_mut(&(guild_id.0 as u64)) {
// match mode {
// "one" => {
// player.set_repeat(Repeat::One);
// msg.react(ctx, '🔂').await?;
// }
// "all" => {
// player.set_repeat(Repeat::All);
// msg.react(ctx, '🔁').await?;
// }
// "off" => {
// player.set_repeat(Repeat::Off);
// msg.react(ctx, '✅').await?;
// }
// _ => {
// msg.channel_id.say(ctx, "Invalid repeat mode").await?;
// }
// }
// } else {
// msg.channel_id.say(ctx, JOIN_MSG).await?;
// }
// Ok(())
// }
/// Remove a song from queue.
///
/// Usage: `remove <index>`
/// or `remove 1`
#[command]
#[num_args(1)]
async fn remove(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult {
let index = args.single::<usize>().unwrap();
let guild_id = msg.guild(&ctx.cache).await.unwrap().id;
let manager = songbird::get(ctx)
.await
.expect("Songbird Voice client placed in at initialisation.")
.clone();
if let Some(handler_lock) = manager.get(guild_id) {
let handler = handler_lock.lock().await;
let queue = handler.queue();
if !queue.is_empty() {
if let Some(t) = queue.dequeue(index) {
msg.channel_id
.say(
ctx,
format!("Removed - {}", t.metadata().title.clone().unwrap()),
)
.await?;
} else {
msg.channel_id.say(ctx, "Out of bounds").await?;
}
} else {
msg.channel_id.say(ctx, QUEUE_EMPTY_MSG).await?;
}
} else {
msg.channel_id.say(ctx, JOIN_MSG).await?;
}
Ok(())
}
/// Play a lofi stream.
///
/// Usage: `lofi <id>`
///
/// Available Channels:
/// ```
/// +-----------------+------------------------------+
/// | ID | URL |
/// +-----------------+------------------------------+
/// | chilledcow | https://youtu.be/5qap5aO4i9A |
/// | chilledcow2 | https://youtu.be/DWcJFNfaw9c |
/// | chillhopmusic | https://youtu.be/5yx6BWlEVcY |
/// | chillhopmusic2 | https://youtu.be/7NOSDKb0HlU |
/// | tokyolosttracks | https://youtu.be/WBfbkPTqUtU |
/// | thejazzhopcafe | https://youtu.be/OVPPOwMpSpQ |
/// | homeworkradio | https://youtu.be/ZYMuB9y549s |
/// | steezyasfuck | https://youtu.be/-5KAN9_CzSA |
/// | thebootlegboy | https://youtu.be/l7TxwBhtTUY |
/// | inyourchill | https://youtu.be/B8tQ8RUbTW8 |
/// | collegemusic | https://youtu.be/bM0Iw7PPoU4 |
/// +-----------------+------------------------------+
/// ```
#[command]
#[num_args(1)]
async fn lofi(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
let channel_id = args.message().to_string();
let url = match channel_id.as_str() {
"chilledcow" => "https://youtu.be/5qap5aO4i9A",
"chilledcow2" => "https://youtu.be/DWcJFNfaw9c",
"chillhopmusic" => "https://youtu.be/5yx6BWlEVcY",
"chillhopmusic2" => "https://youtu.be/7NOSDKb0HlU",
"tokyolosttracks" => "https://youtu.be/WBfbkPTqUtU",
"thejazzhopcafe" => "https://youtu.be/OVPPOwMpSpQ",
"homeworkradio" => "https://youtu.be/ZYMuB9y549s",
"steezyasfuck" => "https://youtu.be/-5KAN9_CzSA",
"thebootlegboy" => "https://youtu.be/l7TxwBhtTUY",
"inyourchill" => "https://youtu.be/B8tQ8RUbTW8",
"collegemusic" => "https://youtu.be/bM0Iw7PPoU4",
_ => {
msg.channel_id
.say(
ctx,
"Invalid channel ID, try `help lofi` for all the available channels.",
)
.await?;
return Ok(());
}
};
play(ctx, msg, Args::new(url, &[Delimiter::Single(' ')])).await?;
Ok(())
}
// /// Get lyrics of current song, or search for another.
// ///
// /// Usage: `lyrics <title>`
// #[command]
// #[min_args(1)]
// async fn lyrics(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
// let title = args.message().to_string();
// match get_lyrics(title.clone()).await {
// Ok(lyrics) => {
// let chars: Vec<char> = lyrics.lyrics.chars().collect();
// let chunks = chars
// .chunks(2000)
// .map(|chunk| chunk.iter().collect::<String>())
// .collect::<Vec<_>>();
// let pages = chunks
// .iter()
// .enumerate()
// .map(|(i, chunk)| {
// let mut p = CreateMessage::default();
// p.embed(|e| {
// e.footer(|f| f.text(&format!("Page {}/{}", i + 1, chunks.len())));
// e.url(&lyrics.links.genius);
// e.thumbnail(&lyrics.thumbnail.genius);
// e.title(&format!("{} - {}", lyrics.author, lyrics.title));
// e.description(chunk);
// e
// });
// p
// })
// .collect::<Vec<_>>();
// let mut menu_options = MenuOptions::default();
// menu_options.timeout = 180.0;
// let menu = Menu::new(ctx, msg, &pages, menu_options);
// menu.run().await?;
// }
// Err(_) => {
// msg.channel_id
// .say(
// ctx,
// &format!("Could not find lyrics for the song: `{}`", title),
// )
// .await?;
// return Ok(());
// }
// }
// Ok(())
// }
fn _now_playing_embed(m: &mut CreateMessage, np: Metadata) {
m.embed(|e| {
e.title("Now playing");
e.field("Title", np.title.clone().unwrap(), false);
if let Some(t) = np.source_url {
e.field("URL", t, false);
}
e.field("Duration", _duration_format(np.duration), true);
// e.field("Requester", np.requester.mention(), true);
if let Some(t) = np.thumbnail {
e.thumbnail(t);
}
e
});
}
fn _duration_format(duration: Option<Duration>) -> String {
if let Some(d) = duration {
if d != Duration::default() {
return humantime::format_duration(d).to_string();
}
}
"Live".to_string()
}