package stream.flarebot.flarebot.commands.music;

import com.arsenarsen.lavaplayerbridge.PlayerManager;
import com.arsenarsen.lavaplayerbridge.player.Track;
import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.entities.Message;
import net.dv8tion.jda.core.entities.TextChannel;
import net.dv8tion.jda.core.entities.User;
import stream.flarebot.flarebot.FlareBot;
import stream.flarebot.flarebot.commands.Command;
import stream.flarebot.flarebot.commands.CommandType;
import stream.flarebot.flarebot.music.extractors.YouTubeExtractor;
import stream.flarebot.flarebot.util.MessageUtils;

public class SongCommand implements Command {

    private PlayerManager manager;

    public SongCommand(FlareBot bot) {
        this.manager = bot.getMusicManager();
    }

    @Override
    public void onCommand(User sender, TextChannel channel, Message message, String[] args, Member member) {
        if (manager.getPlayer(channel.getGuild().getId()).getPlayingTrack() != null) {
            Track track = manager.getPlayer(channel.getGuild().getId()).getPlayingTrack();
            channel.sendMessage(MessageUtils.getEmbed(sender)
                    .addField("Current song: ", getLink(track), false)
                    .addField("Amount Played: ",
                            (int) (100f / track.getTrack().getDuration() * track.getTrack()
                                    .getPosition()) + "% of "
                                    + formatDuration(track), true)
                    .addField("Requested by:", String
                            .format("<@!%s>", track.getMeta().get("requester")), false).build())
                    .queue();
        } else {
            channel.sendMessage(MessageUtils.getEmbed(sender)
                    .addField("Current song: ", "**No song playing right now!**", false)
                    .build()).queue();
        }
    }

    public static String getLink(Track track) {
        String name = String.valueOf(track.getTrack().getInfo().title);
        String link = YouTubeExtractor.WATCH_URL + track.getTrack().getIdentifier();
        return String.format("[`%s`](%s)", name, link);
    }

    @Override
    public String getCommand() {
        return "song";
    }

    @Override
    public String getDescription() {
        return "Get the current song playing.";
    }

    @Override
    public String getUsage() {
        return "{%}song";
    }

    @Override
    public CommandType getType() {
        return CommandType.MUSIC;
    }

    public static String formatDuration(Track track) {
        long totalSeconds = track.getTrack().getDuration() / 1000;
    public static String formatDuration(long duration) {
        long totalSeconds = duration / 1000;
        long seconds = totalSeconds % 60;
        long minutes = (totalSeconds / 60) % 60;
        long hours = (totalSeconds / 3600);
        return (hours > 0 ? (hours < 10 ? "0" + hours : hours) + ":" : "")
                + (minutes < 10 ? "0" + minutes : minutes) + ":" + (seconds < 10 ? "0" + seconds : seconds);
    }

    public static String getProgressBar(Track track) {
        float percentage = (100f / track.getTrack().getDuration() * track.getTrack().getPosition());
        StringBuilder progress = new StringBuilder("[");
        progress.append(StringUtils.repeat("▬", (int) Math.round((double) percentage / 10)));
        progress.append("]()");
        progress.append(StringUtils.repeat("▬", 10 - (int) Math.round((double) percentage / 10)));
        progress.append(" " + new DecimalFormat("#.##").format(percentage) + "%");
        return progress.toString();
    }

}

@@ -330,24 +330,69 @@
 ities.User;%0A
+import org.apache.commons.lang3.StringUtils;%0A
 import strea
@@ -421,16 +421,16 @@
 areBot;%0A
-
 import s
@@ -644,16 +644,49 @@
 Utils;%0A%0A
+import java.text.DecimalFormat;%0A%0A
 public c
@@ -1258,18 +1258,16 @@
 ent song
-: 
 %22, getLi
@@ -1332,74 +1332,108 @@
 ayed
-: %22,%0A                            (int) (100f / track.getTrack().ge
+%22, getProgressBar(track), true)%0A                    .addField(%22Time%22, String.format(%22%25s / %25s%22, forma
 tDur
@@ -1430,36 +1430,32 @@
  formatDuration(
-) * 
 track.getTrack()
@@ -1458,279 +1458,101 @@
 ck()
-%0A                                    .getPosition()) + %22%25 of %22%0A                                    + formatDuration(track), true)%0A                    .addField(%22Requested by:%22, String%0A                            .format(%22%3C@!%25s%3E%22, track.getMeta().get(%22requester%22)), false)
+.getPosition()), formatDuration(track.getTrack().getDuration())), false)%0A                    
 .bui
@@ -1709,18 +1709,16 @@
 ent song
-: 
 %22, %22**No
@@ -2432,130 +2432,8 @@
  %7D%0A%0A
-    public static String formatDuration(Track track) %7B%0A        long totalSeconds = track.getTrack().getDuration() / 1000;%0A
     

Make song info look better