|
@@ -9,6 +9,7 @@ import LogLevels from "../../enums/log-levels";
|
|
|
import config from "../../config";
|
|
import config from "../../config";
|
|
|
|
|
|
|
|
interface IStreamConfig {
|
|
interface IStreamConfig {
|
|
|
|
|
+ id: number;
|
|
|
location: string;
|
|
location: string;
|
|
|
url: string;
|
|
url: string;
|
|
|
hashtags: string[];
|
|
hashtags: string[];
|
|
@@ -21,6 +22,7 @@ export default class VideoStreams {
|
|
|
private readonly _name: string = "Video Streams";
|
|
private readonly _name: string = "Video Streams";
|
|
|
private readonly _mastodonClient: mastodon.rest.Client;
|
|
private readonly _mastodonClient: mastodon.rest.Client;
|
|
|
private readonly _scraper: Scraper;
|
|
private readonly _scraper: Scraper;
|
|
|
|
|
+ private readonly _defaultLocation: string = "Transmisión en vivo";
|
|
|
|
|
|
|
|
constructor(accessToken = config.MASTODON_TEST_ACCESS_TOKEN) {
|
|
constructor(accessToken = config.MASTODON_TEST_ACCESS_TOKEN) {
|
|
|
accessToken = config.DEVELOP ? config.MASTODON_TEST_ACCESS_TOKEN : accessToken;
|
|
accessToken = config.DEVELOP ? config.MASTODON_TEST_ACCESS_TOKEN : accessToken;
|
|
@@ -40,16 +42,31 @@ export default class VideoStreams {
|
|
|
throw new Error("VIDEO_STREAMS must be a JSON array");
|
|
throw new Error("VIDEO_STREAMS must be a JSON array");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- return parsed.map((item: any) => ({
|
|
|
|
|
- location: String(item.location ?? "").trim(),
|
|
|
|
|
- url: String(item.url ?? "").trim(),
|
|
|
|
|
- hashtags: Array.isArray(item.hashtags)
|
|
|
|
|
- ? item.hashtags.map((h: unknown) => String(h).trim()).filter((h: string) => h !== "")
|
|
|
|
|
- : [],
|
|
|
|
|
- screenshotSelector: item.screenshotSelector !== undefined ? String(item.screenshotSelector).trim() : undefined,
|
|
|
|
|
- clickSelector: item.clickSelector !== undefined ? String(item.clickSelector).trim() : undefined,
|
|
|
|
|
- screenshotDelay: item.screenshotDelay !== undefined ? Number(item.screenshotDelay) : undefined
|
|
|
|
|
- })).filter((stream) => stream.location !== "" && stream.url !== "");
|
|
|
|
|
|
|
+ let id = 1;
|
|
|
|
|
+ const streams: IStreamConfig[] = [];
|
|
|
|
|
+
|
|
|
|
|
+ parsed.forEach((item: any) => {
|
|
|
|
|
+ const location = String(item.location ?? "").trim();
|
|
|
|
|
+ const url = String(item.url ?? "").trim();
|
|
|
|
|
+
|
|
|
|
|
+ if (url === "") {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ streams.push({
|
|
|
|
|
+ id: id++,
|
|
|
|
|
+ location,
|
|
|
|
|
+ url,
|
|
|
|
|
+ hashtags: Array.isArray(item.hashtags)
|
|
|
|
|
+ ? item.hashtags.map((h: unknown) => String(h).trim()).filter((h: string) => h !== "")
|
|
|
|
|
+ : [],
|
|
|
|
|
+ screenshotSelector: item.screenshotSelector !== undefined ? String(item.screenshotSelector).trim() : undefined,
|
|
|
|
|
+ clickSelector: item.clickSelector !== undefined ? String(item.clickSelector).trim() : undefined,
|
|
|
|
|
+ screenshotDelay: item.screenshotDelay !== undefined ? Number(item.screenshotDelay) : undefined
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ return streams;
|
|
|
} catch (err: any) {
|
|
} catch (err: any) {
|
|
|
console.error(`${this._name} | Error parsing VIDEO_STREAMS: ${err.message}`);
|
|
console.error(`${this._name} | Error parsing VIDEO_STREAMS: ${err.message}`);
|
|
|
throw err;
|
|
throw err;
|
|
@@ -61,12 +78,20 @@ export default class VideoStreams {
|
|
|
return new File([buffer], fileName, { type: "image/png" });
|
|
return new File([buffer], fileName, { type: "image/png" });
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private generateUniqueTag(id: number): string {
|
|
|
|
|
+ return `EnVivoCL_${String(id).padStart(3, "0")}`;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private buildMessage(stream: IStreamConfig): string {
|
|
private buildMessage(stream: IStreamConfig): string {
|
|
|
- let message = `${Emojis.VIDEO_CAMERA} Transmisión en vivo desde ${stream.location}`;
|
|
|
|
|
|
|
+ const location = stream.location !== "" ? stream.location : this._defaultLocation;
|
|
|
|
|
+ const uniqueTag = this.generateUniqueTag(stream.id);
|
|
|
|
|
+ const tags = [uniqueTag, ...stream.hashtags];
|
|
|
|
|
+
|
|
|
|
|
+ let message = `${Emojis.VIDEO_CAMERA} Transmisión en vivo desde ${location}`;
|
|
|
message += `\n\n${Emojis.LINK} ${stream.url}`;
|
|
message += `\n\n${Emojis.LINK} ${stream.url}`;
|
|
|
|
|
|
|
|
- if (stream.hashtags.length > 0) {
|
|
|
|
|
- message += `\n\n${stream.hashtags.map((hashtag) => `#${hashtag}`).join(" ")}`;
|
|
|
|
|
|
|
+ if (tags.length > 0) {
|
|
|
|
|
+ message += `\n\n${tags.map((hashtag) => `#${hashtag}`).join(" ")}`;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return message;
|
|
return message;
|