在 youtubedl 中将秒转换为分钟和小时

Converting seconds to minutes and hours in youtubedl

        embed = discord.Embed(
            title=self.title, description=f"**Channel:** {self.uploader}\n **Duration:** {self.duration}", url=self.video_url)
        embed.set_footer(
            text=f"Requested by: {self.requested_by.name}",
            icon_url=self.requested_by.avatar_url)
        if self.thumbnail:
            embed.set_thumbnail(url=self.thumbnail)
        return embed

所以都是关于第二行的。现在输出以秒为单位显示持续时间。我想更改格式以便显示实际时间。例如视频时长 3 分钟:

根据文档 (https://github.com/ytdl-org/youtube-dl/blob/master/README.md#readme),durationLength of the video in seconds,因此您可以手动从秒 hours:minutes:seconds.

开始
total_seconds = self.duration
hours = (total_seconds - ( total_seconds % 3600))/3600
seconds_minus_hours = (total_seconds - hours*3600)
minutes = (seconds_minus_hours - (seconds_minus_hours % 60) )/60
seconds = seconds_minus_hours - minutes*60

time = '{}:{}:{}'.format(int(hours), int(minutes), int(seconds))

那个时间字符串可能有点乱(int() 是这样,当你打印它时它没有小数点)但它包含所有相关信息。