Skip to content

Commit

Permalink
add "start syncplay" command
Browse files Browse the repository at this point in the history
  • Loading branch information
zuluwi committed Feb 4, 2024
1 parent 23089c5 commit 1c6d672
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 54 deletions.
20 changes: 12 additions & 8 deletions src/language/locale/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ export default {
"No video information available": "No video information available",
//
"Select a file to open with VLC Player": "Select a file to open with VLC Player",
"Add subtitles (if you want subtitle path in the timestamp link, you need to add them with this command)":
"Add subtitles (if you want subtitle path in the timestamp link, you need to add them with this command)",
"Add subtitles": "Add subtitles",
"A video must be open to add subtitles": "A video must be open to add subtitles",
"Seek forward": "Seek forward",
"Seek backward": "Seek backward",
Expand Down Expand Up @@ -39,21 +38,26 @@ export default {
"Long Seek Amount (in seconds)": "Long Seek Amount (in seconds)",
"Set the seek amount for 'Long seek forward/backward' commands": "Set the seek amount for 'Long seek forward/backward' commands",
//
"Snapshot Settings": "Snapshot Settings",
Snapshot: "Snapshot",
"Snapshot folder": "Snapshot folder",
"Enter the folder name where snapshots will be saved in the vault": "Enter the folder name where snapshots will be saved in the vault",
"Select a valid file name": `Select a valid file name ( name must not contain the characters \\ / < > " * : | ? )`,
"Snapshot Format": "Snapshot Format",
"Select the image format in which the snapshots will be saved": "Select the image format in which the snapshots will be saved",
//
"Syncplay Path": "Syncplay Path",
"Select 'Syncplay.exe' from the folder where Syncplay is installed": "Select 'Syncplay.exe' from the folder where Syncplay is installed",
"Select Syncplay.exe": "Select Syncplay.exe",
"Start Syncplay with plugin arguments": "Start Syncplay with plugin arguments",
"Start Syncplay": "Start Syncplay",
"Before you can use this command, you need to select 'Syncplay.exe' in the plugin settings":
"Before you can use this command, you need to select 'Syncplay.exe' in the plugin settings",
//
Extra: "Extra",
"Copy VLC Web Interface link": "Copy VLC Web Interface link",
"Copy command line code": "Copy command line code",
"Copy arguments for starting VLC (for Syncplay)": "Copy arguments for starting VLC (for Syncplay)",
"Note: If the `--snapshot-path` option contains spaces, the snapshot command will not work (this only happens for Syncplay arguments)":
"Note: If the `--snapshot-path` option contains spaces, the snapshot command will not work (this only happens for Syncplay arguments)",
"syncplay argument instructions":
"You will get an error when you open VLC with Syncplay because the Snapshot folder path contains spaces. To fix this, paste the arguments and click the **`Store configuration and run Syncplay`** button to start the program once and close it. The arguments will be saved in the **`syncplay.ini`** file where Syncplay is installed, open this file and merge the **`#1#`** in the *`perplayerarguments`* object into **`#2#`** and save the file. Then open Syncplay and run it.",
// "Copy arguments for starting VLC (for Syncplay)": "Copy arguments for starting VLC (for Syncplay)",
// "syncplay argument instructions": "You will get an error when you open VLC with Syncplay because the Snapshot folder path contains spaces. To fix this, paste the arguments and click the **`Store configuration and run Syncplay`** button to start the program once and close it. The arguments will be saved in the **`syncplay.ini`** file where Syncplay is installed, open this file and merge the **`#1#`** in the *`perplayerarguments`* object into **`#2#`** and save the file. Then open Syncplay and run it.",
"Copy to clipboard": "Copy to clipboard",
"Copied to clipboard": "Copied to clipboard",

Expand Down
20 changes: 12 additions & 8 deletions src/language/locale/tr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ export default {
"No video information available": "Mevcut video bilgisine ulaşılamadı",
//
"Select a file to open with VLC Player": "VLC Player ile açmak için bir dosya seçin",
"Add subtitles (if you want subtitle path in the timestamp link, you need to add them with this command)":
"Altyazı ekle (zaman damgalı linkte altyazı adresinin bulunmasını istiyorsanız bu komutla eklemeniz gerekmekte)",
"Add subtitles": "Altyazı ekle",
"A video must be open to add subtitles": "Altyazı ekleyebilmek için bir video açık olmalı",
"Seek forward": "İleri sar",
"Seek backward": "Geri sar",
Expand Down Expand Up @@ -39,7 +38,15 @@ export default {
"Long Seek Amount (in seconds)": "Uzun İleri/Geri Sarma Miktarı (saniye cinsinden)",
"Set the seek amount for 'Long seek forward/backward' commands": "Uzun İleri/Geri Sar komutları için atmala miktarını seçiniz",
//
"Snapshot Settings": "Snapshot Ayarları",
"Syncplay Path": "Syncplay Yolu",
"Select 'Syncplay.exe' from the folder where Syncplay is installed": "Syncplay'in kurulu olduğu klasörden Syncplay.exe'yi seçiniz",
"Select Syncplay.exe": "Syncplay.exe'yi seç",
"Start Syncplay with plugin arguments": "Plugin argümanlarıyla Syncplay'i çalıştır",
"Start Syncplay": "Syncplay'i çalıştır",
"Before you can use this command, you need to select 'Syncplay.exe' in the plugin settings":
"Bu komutu kullanabilmek için öncelikle plugin ayarlarından 'Syncplay.exe'yi seçmeniz gerekmekte",
//
Snapshot: "Snapshot",
"Snapshot folder": "Snapshot Klasörü",
"Enter the folder name where snapshots will be saved in the vault": "Snapshotların kasada kaydedileceği klasör adını giriniz",
"Select a valid file name": `Geçerli bir dosya adı seçiniz ( isim \\ / < > " * : | ? karakterlerini barındırmamalı )`,
Expand All @@ -49,11 +56,8 @@ export default {
Extra: "Ekstra",
"Copy VLC Web Interface link": "VLC Web Interface linkini kopyala",
"Copy command line code": "Komut satırı kodunu kopyala",
"Copy arguments for starting VLC (for Syncplay)": "VLC'yi başlatma argümanlarını kopyala (Syncplay için)",
"Note: If the `--snapshot-path` option contains spaces, the snapshot command will not work (this only happens for Syncplay arguments)":
"Not: Eğer `--snapshot-path` seçeneği boşluk içeriyorsa snapshot komutu çalışmayacaktır (bu sadece Syncplay argümanları için geçerlidir)",
"syncplay argument instructions":
"Snapshot klasör yolu boşluk barındırdığı için Syncplay ile VLC'yi açtığınızda hata alacaksınız. Bunu düzeltmek için argümanları yapıştırıp **`Yapılandırmayı depolayın ve Syncplay'i çalıştırın`** butonuna tıklayarak bir kere başlatıp programı kapatın. Argümanlar Syncplay'in kurulu olduğu **`syncplay.ini`** dosyasına kaydedilmiş olacak, bu dosyayı açıp *`perplayerarguments`* objesinde bulunan **`#1#`** kısmını birleştirerek **`#2#`** haline getirin ve dosyayı kaydedin. Ardından Syncplay'i açıp çalıştırın.",
// "Copy arguments for starting VLC (for Syncplay)": "VLC'yi başlatma argümanlarını kopyala (Syncplay için)",
// "syncplay argument instructions": "Snapshot klasör yolu boşluk barındırdığı için Syncplay ile VLC'yi açtığınızda hata alacaksınız. Bunu düzeltmek için argümanları yapıştırıp **`Yapılandırmayı depolayın ve Syncplay'i çalıştırın`** butonuna tıklayarak bir kere başlatıp programı kapatın. Argümanlar Syncplay'in kurulu olduğu **`syncplay.ini`** dosyasına kaydedilmiş olacak, bu dosyayı açıp *`perplayerarguments`* objesinde bulunan **`#1#`** kısmını birleştirerek **`#2#`** haline getirin ve dosyayı kaydedin. Ardından Syncplay'i açıp çalıştırın.",
"Copy to clipboard": "Panoya kopyala",
"Copied to clipboard": "Panoya kopyalandı",

Expand Down
14 changes: 12 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,19 @@ export default class VLCBridgePlugin extends Plugin {
checkPort: (timeout?: number) => Promise<object | null>;
getCurrentVideo: () => Promise<string | null>;
vlcExecOptions: () => string[];
launchSyncplay: () => void;

async onload() {
await this.loadSettings();
var { getStatus, getCurrentVideo, checkPort, sendVlcRequest, openVideo, launchVLC, vlcExecOptions, addSubtitle } = passPlugin(this);
var { getStatus, getCurrentVideo, checkPort, sendVlcRequest, openVideo, launchVLC, launchSyncplay, vlcExecOptions, addSubtitle } = passPlugin(this);
this.openVideo = openVideo;
this.addSubtitle = addSubtitle;
this.sendVlcRequest = sendVlcRequest;
this.getStatus = getStatus;
this.checkPort = checkPort;
this.getCurrentVideo = getCurrentVideo;
this.vlcExecOptions = vlcExecOptions;
this.launchSyncplay = launchSyncplay;

// This creates an icon in the left ribbon.
this.addRibbonIcon("lucide-traffic-cone", t("Select a file to open with VLC Player"), (evt: MouseEvent) => {
Expand Down Expand Up @@ -83,10 +85,18 @@ export default class VLCBridgePlugin extends Plugin {
},
});

this.addCommand({
id: "open-syncplay",
name: t("Start Syncplay with plugin arguments"),
callback: async () => {
this.launchSyncplay();
},
});

this.addCommand({
id: "add-subtitle",
icon: "lucide-subtitles",
name: t("Add subtitles (if you want subtitle path in the timestamp link, you need to add them with this command)"),
name: t("Add subtitles"),
callback: async () => {
this.subtitleOpen();
},
Expand Down
93 changes: 68 additions & 25 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface VBPluginSettings {
snapshotExt: "png" | "jpg" | "tiff";
currentFile: string | null;
vlcPath: string;
syncplayPath: string;
lang: string;
normalSeek: number;
largeSeek: number;
Expand All @@ -33,6 +34,7 @@ export const DEFAULT_SETTINGS: VBPluginSettings = {
snapshotExt: "png",
currentFile: null,
vlcPath: "",
syncplayPath: "",
lang: "en",
normalSeek: 5,
largeSeek: 60,
Expand Down Expand Up @@ -94,6 +96,7 @@ export class VBPluginSettingsTab extends PluginSettingTab {

let copyUrlEl: Setting;
let copyCommandEl: Setting;
let syncplayArgEl: Setting;
let copyArgEl: Setting;

const splittedPath = () => {
Expand All @@ -108,19 +111,20 @@ export class VBPluginSettingsTab extends PluginSettingTab {
};

const setCopyBtnDesc = () => {
syncplayArgEl.setDesc(`"${this.plugin.settings.syncplayPath}" -- ${this.plugin.vlcExecOptions().join(" ")}`);
copyUrlEl.setDesc(`http://:${this.plugin.settings.password}@localhost:${this.plugin.settings.port}/`);
copyCommandEl.setDesc(`"${this.plugin.settings.vlcPath}" ${this.plugin.vlcExecOptions().join(" ")}`);
copyArgEl.setDesc(`${this.plugin.vlcExecOptions().join(" ").replace(/["]/g, "")}`);

if (/\s/.test(this.plugin.app.vault.adapter.getFullRealPath(this.plugin.settings.snapshotFolder))) {
MarkdownRenderer.render(
this.app,
`> [!warning]\n> ${t("syncplay argument instructions").replace("#1#", splittedPath()[1]).replace("#2#", splittedPath()[2])}`,
copyArgEl.descEl,
"",
this.plugin
);
}

// copyArgEl.setDesc(`${this.plugin.vlcExecOptions().join(" ").replace(/["]/g, "")}`);
// if (/\s/.test(this.plugin.app.vault.adapter.getFullRealPath(this.plugin.settings.snapshotFolder))) {
// MarkdownRenderer.render(
// this.app,
// `> [!warning]\n> ${t("syncplay argument instructions").replace("#1#", splittedPath()[1]).replace("#2#", splittedPath()[2])}`,
// copyArgEl.descEl,
// "",
// this.plugin
// );
// }

// .createDiv()
// .createEl("code", { text: `${splittedPath()}` });
Expand All @@ -137,8 +141,8 @@ export class VBPluginSettingsTab extends PluginSettingTab {
const input = document.createElement("input");
input.setAttribute("type", "file");
input.accept = ".exe";
input.onchange = async (e: any) => {
var files = e.target.files;
input.onchange = async (e: Event) => {
var files = (e.target as HTMLInputElement)?.files as FileList;
for (let i = 0; i < files.length; i++) {
var file = files[i];

Expand Down Expand Up @@ -234,7 +238,7 @@ export class VBPluginSettingsTab extends PluginSettingTab {
});
});

containerEl.createEl("h1", { text: t("Snapshot Settings") });
containerEl.createEl("h1", { text: t("Snapshot") });

var folderNamePattern = /^[A-Za-z0-9][^\\\/\<\>\"\*\:\|\?]*$/gi;
new Setting(containerEl)
Expand Down Expand Up @@ -276,6 +280,45 @@ export class VBPluginSettingsTab extends PluginSettingTab {
});
});

containerEl.createEl("h1", { text: "Syncplay" });

var selectSPDescEl: HTMLElement;
var selectSP = new Setting(containerEl)
.setName(t("Syncplay Path"))
.setDesc(t("Select 'Syncplay.exe' from the folder where Syncplay is installed"))
.addButton((btn) => {
btn
.setButtonText(t("Select Syncplay.exe"))

.onClick(() => {
const input = document.createElement("input");
input.setAttribute("type", "file");
input.accept = ".exe";
input.onchange = async (e: Event) => {
var files = (e.target as HTMLInputElement)?.files as FileList;
for (let i = 0; i < files.length; i++) {
var file = files[i];

this.plugin.settings.syncplayPath = file.path;
selectSPDescEl.innerText = file.path;
await this.plugin.saveSettings();
setCopyBtnDesc();

input.remove();
}
};

input.click();
});
});
selectSPDescEl = selectSP.descEl.createEl("div").createEl("b", { text: this.plugin.settings.syncplayPath || "" });

syncplayArgEl = new Setting(containerEl).setName(t("Start Syncplay with plugin arguments")).addButton((btn) =>
btn.setButtonText(t("Start Syncplay")).onClick(async () => {
this.plugin.launchSyncplay();
})
);

containerEl.createEl("h1", { text: t("Extra") });

copyUrlEl = new Setting(containerEl).setName(t("Copy VLC Web Interface link")).addButton((btn) =>
Expand All @@ -298,17 +341,17 @@ export class VBPluginSettingsTab extends PluginSettingTab {
}
})
);
copyArgEl = new Setting(containerEl).setName(t("Copy arguments for starting VLC (for Syncplay)")).addButton((btn) =>
btn.setButtonText(t("Copy to clipboard")).onClick(async () => {
if (await isPortAvailable(this.plugin.settings.port)) {
// await navigator.clipboard.writeText(`${this.plugin.vlcExecOptions().join(" ").trim().replace(/["]/g, "")}`);
await navigator.clipboard.writeText(`${this.plugin.vlcExecOptions().join(" ").trim()}`);
new Notice(t("Copied to clipboard"));
} else {
new Notice(t("The port you selected is not usable, please enter another port value"));
}
})
);
// copyArgEl = new Setting(containerEl).setName(t("Copy arguments for starting VLC (for Syncplay)")).addButton((btn) =>
// btn.setButtonText(t("Copy to clipboard")).onClick(async () => {
// if (await isPortAvailable(this.plugin.settings.port)) {
// // await navigator.clipboard.writeText(`${this.plugin.vlcExecOptions().join(" ").trim().replace(/["]/g, "")}`);
// await navigator.clipboard.writeText(`${this.plugin.vlcExecOptions().join(" ").trim()}`);
// new Notice(t("Copied to clipboard"));
// } else {
// new Notice(t("The port you selected is not usable, please enter another port value"));
// }
// })
// );
setCopyBtnDesc();

//
Expand Down
46 changes: 35 additions & 11 deletions src/vlcHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,35 +223,35 @@ export function passPlugin(plugin: VLCBridgePlugin) {
// console.log(filePath, currentConfig.currentFile, filePath == currentConfig.currentFile);
if (fileCheck) {
if (fileCheck.current) {
if (time) {
requestUrl(`http://:${password_}@localhost:${port_}/requests/status.json?command=seek&val=${time}`);
}
if (subPath && subPath !== currentMedia.subtitlePath) {
addSubtitle(subPath, subDelay);
}
if (time) {
requestUrl(`http://:${password_}@localhost:${port_}/requests/status.json?command=seek&val=${time}`);
}
} else {
await requestUrl(`http://:${password_}@localhost:${port_}/requests/status.json?command=pl_play&id=${fileCheck.id}`).then(async (response) => {
if (response.status == 200 && (await waitStreams())) {
// currentConfig.currentFile = filePath;
if (time) {
requestUrl(`http://:${password_}@localhost:${port_}/requests/status.json?command=seek&val=${time}`);
}
if (subPath) {
addSubtitle(subPath, subDelay);
}
if (time) {
requestUrl(`http://:${password_}@localhost:${port_}/requests/status.json?command=seek&val=${time}`);
}
}
});
}
} else {
await requestUrl(`http://:${password_}@localhost:${port_}/requests/status.json?command=in_play&input=${encodeURIComponent(filePath)}`).then(async (response) => {
if (response.status == 200 && (await waitStreams())) {
// currentConfig.currentFile = filePath;
if (time) {
requestUrl(`http://:${password_}@localhost:${port_}/requests/status.json?command=seek&val=${time}`);
}
if (subPath) {
addSubtitle(subPath, subDelay);
}
if (time) {
requestUrl(`http://:${password_}@localhost:${port_}/requests/status.json?command=seek&val=${time}`);
}
}
});
// if (time) {
Expand Down Expand Up @@ -305,7 +305,7 @@ export function passPlugin(plugin: VLCBridgePlugin) {
currentMedia.subtitlePath = filePath;
let subIndex = (await waitStreams()).filter((e) => e !== "meta").length - 1;
requestUrl(`http://:${password_}@localhost:${port_}/requests/status.json?command=subtitle_track&val=${subIndex}`);
if (subDelay) {
if (typeof subDelay == "number") {
requestUrl(`http://:${password_}@localhost:${port_}/requests/status.json?command=subdelay&val=${subDelay}`);
}
}
Expand Down Expand Up @@ -353,5 +353,29 @@ export function passPlugin(plugin: VLCBridgePlugin) {
currentConfig.snapshotExt = plugin.settings.snapshotExt;
};

return { getCurrentVideo, getStatus, checkPort, sendVlcRequest, openVideo, vlcExecOptions, launchVLC, addSubtitle };
const launchSyncplay = async () => {
// console.log("launchVlc");
// console.log(`"${plugin.settings.vlcPath}" ${vlcExecOptions().join(" ")}`);

if (!plugin.settings.syncplayPath) {
return new Notice(t("Before you can use this command, you need to select 'Syncplay.exe' in the plugin settings"));
}
if (await isPortReachable(plugin.settings.port, { host: "localhost" })) {
return new Notice(t("The port you selected is not usable, please enter another port value"));
}
exec(`"${plugin.settings.syncplayPath}" -- ${vlcExecOptions().join(" ")}`)
.finally(() => {})
.catch((err: Error) => {
console.log("Syncplay Launch Error", err);
new Notice(t("The vlc.exe specified in the settings could not be run, please check again!"));
});
currentConfig.vlcPath = plugin.settings.vlcPath;
currentConfig.port = plugin.settings.port;
currentConfig.password = plugin.settings.password;
currentConfig.lang = plugin.settings.lang;
currentConfig.snapshotFolder = plugin.settings.snapshotFolder;
currentConfig.snapshotExt = plugin.settings.snapshotExt;
};

return { getCurrentVideo, getStatus, checkPort, sendVlcRequest, openVideo, vlcExecOptions, launchVLC, launchSyncplay, addSubtitle };
}

0 comments on commit 1c6d672

Please sign in to comment.