Skip to content

The swiss army knife of lossless video/audio editing

Add pbf import #421

Mikael Finstad46f500568f89
diff --git a/public/menu.js b/public/menu.js
index b099295c..394f4dbd 100644
--- a/public/menu.js
+++ b/public/menu.js
@@ -56,6 +56,12 @@ module.exports = (app, mainWindow, newVersion) => {
mainWindow.webContents.send('importEdlFile', 'cue');
},
},
+ {
+ label: 'PotPlayer Bookmarks (.pbf)',
+ click() {
+ mainWindow.webContents.send('importEdlFile', 'pbf');
+ },
+ },
],
},
{
diff --git a/src/App.jsx b/src/App.jsx
index 66ce1429..4fb2033d 100644
--- a/src/App.jsx
+++ b/src/App.jsx
@@ -43,7 +43,7 @@ import {
findNearestKeyFrameTime, html5ify as ffmpegHtml5ify, isStreamThumbnail, isAudioSupported, isIphoneHevc, tryReadChaptersToEdl,
fixInvalidDuration, getDuration, getTimecodeFromStreams,
} from './ffmpeg';
-import { saveCsv, loadCsv, loadXmeml, loadCue } from './edlStore';
+import { saveCsv, loadCsv, loadXmeml, loadCue, loadPbf } from './edlStore';
import {
getOutPath, formatDuration, toast, errorToast, showFfmpegFail, setFileNameTitle, getOutDir, withBlur,
checkDirWriteAccess, dirExists, openDirToast, isMasBuild, isStoreBuild, dragPreventer, doesPlayerSupportFile,
@@ -1156,6 +1156,7 @@ const App = memo(() => {
if (type === 'csv') edl = await loadCsv(path);
else if (type === 'xmeml') edl = await loadXmeml(path);
else if (type === 'cue') edl = await loadCue(path);
+ else if (type === 'pbf') edl = await loadPbf(path);
loadCutSegments(edl);
} catch (err) {
@@ -1645,6 +1646,7 @@ const App = memo(() => {
if (type === 'csv') filters = [{ name: i18n.t('CSV files'), extensions: ['csv'] }];
else if (type === 'xmeml') filters = [{ name: i18n.t('XML files'), extensions: ['xml'] }];
else if (type === 'cue') filters = [{ name: i18n.t('CUE files'), extensions: ['cue'] }];
+ else if (type === 'pbf') filters = [{ name: i18n.t('PBF files'), extensions: ['pbf'] }];
const { canceled, filePaths } = await dialog.showOpenDialog({ properties: ['openFile'], filters });
if (canceled || filePaths.length < 1) return;
diff --git a/src/edlFormats.js b/src/edlFormats.js
index 9ef396bc..416709a8 100644
--- a/src/edlFormats.js
+++ b/src/edlFormats.js
@@ -54,6 +54,22 @@ export function parseCuesheet(cuesheet) {
});
}
+
+export function parsePbf(text) {
+ const chapters = text.split('\n').map((line) => {
+ const match = line.match(/^[0-9]+=([0-9]+)\*([^*]+)*/);
+ if (match) return { time: parseInt(match[1], 10) / 1000, name: match[2] };
+ return undefined;
+ }).filter((it) => it);
+
+ const out = [];
+ chapters.forEach((chapter, i) => {
+ const nextChapter = chapters[i + 1];
+ out.push({ start: chapter.time, end: nextChapter && nextChapter.time, name: chapter.name });
+ });
+ return out;
+}
+
// https://developer.apple.com/library/archive/documentation/AppleApplications/Reference/FinalCutPro_XML/VersionsoftheInterchangeFormat/VersionsoftheInterchangeFormat.html
export function parseXmeml(xmlStr) {
const xml = fastXmlParser.parse(xmlStr);
diff --git a/src/edlStore.js b/src/edlStore.js
index e8b21eb9..7a861a65 100644
--- a/src/edlStore.js
+++ b/src/edlStore.js
@@ -1,7 +1,7 @@
import csvStringify from 'csv-stringify';
import pify from 'pify';
-import { parseCuesheet, parseXmeml, parseCsv } from './edlFormats';
+import { parseCuesheet, parseXmeml, parseCsv, parsePbf } from './edlFormats';
const fs = window.require('fs-extra');
const cueParser = window.require('cue-parser');
@@ -16,6 +16,10 @@ export async function loadXmeml(path) {
return parseXmeml(await fs.readFile(path, 'utf-8'));
}
+export async function loadPbf(path) {
+ return parsePbf(await fs.readFile(path, 'utf-8'));
+}
+
export async function loadCue(path) {
return parseCuesheet(cueParser.parse(path));
}