Skip to content

Commit c048840

Browse files
committed
feat: show vid duration & ref: remove "original title"
1 parent d409b39 commit c048840

File tree

4 files changed

+47
-11
lines changed

4 files changed

+47
-11
lines changed

src/assets/translations/de.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@
149149
"foundNoVidInfo": "Keine Infos zum Video gefunden - versuche es später erneut."
150150
},
151151
"embedFields": {
152-
"originalTitle": "Originaltitel:",
153152
"votes": "Likes & Dislikes (zirka):",
154153
"timestamps": "Zeitmarken:"
155154
}

src/assets/translations/en-US.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,15 @@
2020
"enabled": "Enabled",
2121
"disabled": "Disabled",
2222
"listSeparator": ", ",
23-
"listSeparatorLast": " and "
23+
"listSeparatorLast": " and ",
24+
"time": {
25+
"short": {
26+
"days": "d",
27+
"hours": "h",
28+
"minutes": "m",
29+
"seconds": "s"
30+
}
31+
}
2432
},
2533
"commands": {
2634
"config": {
@@ -183,8 +191,8 @@
183191
"foundNoVidInfo": "Found no data for this video - please try again later"
184192
},
185193
"embedFields": {
186-
"originalTitle": "Original title:",
187194
"votes": "Votes (estimated):",
195+
"duration": "Video duration:",
188196
"timestamps": "Timestamps:",
189197
"sponsorBlockCategories": {
190198
"sponsor": "Sponsored",

src/commands/VideoInfo.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Col, useEmbedify } from "@lib/embedify.ts";
55
import { CmdBase, SlashCommand } from "@lib/Command.ts";
66
import { axios } from "@lib/axios.ts";
77
import type { DeArrowObj, ReturnYouTubeDislikeObj, SponsorBlockActionType, SponsorBlockCategory, SponsorBlockSegmentObj, YTVidDataObj } from "@src/types.ts";
8-
import { generateEmojiProgressBar, joinArrayReadable, secsToYtTime } from "@lib/text.ts";
8+
import { generateEmojiProgressBar, joinArrayReadable, secsToTimeStr, secsToYtTime } from "@lib/text.ts";
99
import { getBestThumbnailUrl } from "@lib/thumbnail.ts";
1010
import { GuildConfig } from "@models/GuildConfig.model.ts";
1111
import { formatNumber, valsWithin } from "@lib/math.ts";
@@ -211,13 +211,7 @@ export class VideoInfoCmd extends SlashCommand {
211211
if(type === "dearrow_only" && !hasDeArrowData)
212212
return null;
213213

214-
embed.setTitle((hasDeArrowData ? bestDeArrowTitle?.title : ytData?.title) ?? url);
215-
216-
hasDeArrowData && ytData.title && embed.addFields({
217-
name: t("commands.video_info.embedFields.originalTitle"),
218-
value: ytData.title,
219-
inline: false,
220-
});
214+
hasDeArrowData && bestDeArrowTitle && embed.setTitle(bestDeArrowTitle.title);
221215

222216
//#SECTION votes
223217

@@ -239,6 +233,18 @@ export class VideoInfoCmd extends SlashCommand {
239233
});
240234
}
241235

236+
//#SECTION video duration
237+
238+
const duration = deArrowData?.videoDuration ?? undefined;
239+
240+
if(typeof duration === "number") {
241+
embed.addFields({
242+
name: t("commands.video_info.embedFields.duration"),
243+
value: secsToTimeStr(duration, locale, true),
244+
inline: true,
245+
});
246+
}
247+
242248
//#SECTION sponsorblock
243249

244250
if(["timestamps_only", "everything"].includes(type) && sponsorBlockData) {

src/lib/text.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Collection } from "discord.js";
22
import emojis from "@assets/emojis.json" with { type: "json" };
3+
import { tr } from "@lib/translate.ts";
34

45
/** Capitalizes the first letter of a string */
56
export function capitalize(text: string) {
@@ -126,3 +127,25 @@ export function secsToYtTime(seconds: number) {
126127

127128
return `${hours ? hours + ":" : ""}${String(minutes).padStart(2, "0")}:${String(secs).padStart(2, "0")}`;
128129
}
130+
131+
/** Returns the passed amount of seconds in a human-readable format */
132+
export function secsToTimeStr(seconds: number, locale = "en-US", padded = false) {
133+
const t = tr.use(locale);
134+
135+
const d = Math.floor(seconds / (60 * 60 * 24)),
136+
h = Math.floor(seconds / (60 * 60)) % 24,
137+
m = Math.floor(seconds / 60) % 60,
138+
s = Math.floor(seconds) % 60;
139+
140+
const pad = (n: number) => padded ? String(n).padStart(2, "0") : n;
141+
142+
return ([
143+
[(60 * 60 * 24), `${d}${t("general.time.short.days")}`],
144+
[(60 * 60), `${pad(h)}${t("general.time.short.hours")}`],
145+
[60, `${pad(m)}${t("general.time.short.minutes")}`],
146+
[0, `${pad(s)}${t("general.time.short.seconds")}`],
147+
] as const)
148+
.filter(([d]) => seconds >= d)
149+
.map(([, s]) => s)
150+
.join(" ");
151+
}

0 commit comments

Comments
 (0)