2 回答
TA贡献1887条经验 获得超5个赞
从文档(https://github.com/ytdl-org/youtube-dl/blob/master/README.md#readme)开始,duration
所以Length 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()当您打印它时它没有小数点),但它包含所有相关信息。
TA贡献1851条经验 获得超5个赞
对于那些路过但仍然需要帮助的人,这是我已经完成的一种更简单的转换方法。
time_to_convert = 249 #YOUR VARIABLE
s= time_to_convert % 60 #seconds
m= time_to_convert / 60 #minutes
print(f'{int(m)}min{s:02d}s') #":02d" will let your seconds look like this 05s
# ^int() maybe you don't need this at all
对于 HOUR,您只需将秒数除以 1 小时的总秒数即可。含义 => 3600
h = time_to_convert / 3600 #total ammount of s in a hour
print(f'{int(h)}') #now you'll need the int() unless you want to show broken/floating hours
- 2 回答
- 0 关注
- 122 浏览
添加回答
举报