types#VideoAnnotation TypeScript Examples
The following examples show how to use
types#VideoAnnotation.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: videoAnnotationFileUtils.tsx From obsidian-annotator with GNU Affero General Public License v3.0 | 6 votes |
export async function writeVideoAnnotation(
annotation: VideoAnnotation,
plugin: AnnotatorPlugin,
annotationFilePath: string
) {
const vault = plugin.app.vault;
const tfile = vault.getAbstractFileByPath(annotationFilePath);
let res: ReturnType<typeof writeVideoAnnotationToVideoAnnotationFileString>;
if (tfile instanceof TFile) {
const text = await vault.read(tfile);
res = writeVideoAnnotationToVideoAnnotationFileString(annotation, text);
vault.modify(tfile, res.newVideoAnnotationFileString);
} else {
res = writeVideoAnnotationToVideoAnnotationFileString(annotation, null);
vault.create(annotationFilePath, res.newVideoAnnotationFileString);
}
return res.newVideoAnnotation;
}
Example #2
Source File: videoAnnotationFileUtils.tsx From obsidian-annotator with GNU Affero General Public License v3.0 | 6 votes |
export async function loadVideoAnnotations(
url: URL | null,
vault: Vault,
annotationFilePath: string
): Promise<VideoAnnotation[]> {
const tfile = vault.getAbstractFileByPath(annotationFilePath);
if (tfile instanceof TFile) {
const text = await vault.read(tfile);
return loadVideoAnnotationsAtUriFromFileText(url, text);
} else {
return loadVideoAnnotationsAtUriFromFileText(url, null);
}
}
Example #3
Source File: videoAnnotationUtils.tsx From obsidian-annotator with GNU Affero General Public License v3.0 | 6 votes |
export function getVideoAnnotationFromFileContent(annotationId: string, fileContent: string): VideoAnnotation {
const annotationRegex = makeVideoAnnotationBlockRegex(annotationId);
let m: RegExpExecArray;
if ((m = annotationRegex.exec(fileContent)) !== null) {
if (m.index === annotationRegex.lastIndex) {
annotationRegex.lastIndex++;
}
const {
groups: { annotationId, time, title, content }
} = m;
return {
readwiseId: '',
content: content
.trim()
.split('\n')
.map(x => x.substr(1))
.join('\n'),
title,
tags: [],
_id: annotationId,
video: '620d5a42b9ab630009bf3e31',
start: Number(time.trim()),
user: 'obsidianuser',
updatedAt: JSON.parse(JSON.stringify(new Date())),
createdAt: JSON.parse(JSON.stringify(new Date())),
__v: 0
};
} else {
return null;
}
}
Example #4
Source File: videoAnnotationUtils.tsx From obsidian-annotator with GNU Affero General Public License v3.0 | 6 votes |
export function writeVideoAnnotationToVideoAnnotationFileString(
annotation: VideoAnnotation,
annotationFileString: string | null
): { newVideoAnnotationFileString: string; newVideoAnnotation: VideoAnnotation } {
const annotationId = annotation._id ? annotation._id : Math.random().toString(36).substr(2);
const res: VideoAnnotation = JSON.parse(JSON.stringify(annotation));
res._id = annotationId;
const annotationString = makeVideoAnnotationString(res);
if (annotationFileString !== null) {
let didReplace = false;
const regex = makeVideoAnnotationBlockRegex(annotationId);
annotationFileString = annotationFileString.replace(regex, () => {
didReplace = true;
return annotationString;
});
if (!didReplace) {
annotationFileString = `${annotationFileString}\n${annotationString}`;
}
return { newVideoAnnotationFileString: annotationFileString, newVideoAnnotation: res };
} else {
return { newVideoAnnotationFileString: annotationString, newVideoAnnotation: res };
}
}
Example #5
Source File: videoAnnotationUtils.tsx From obsidian-annotator with GNU Affero General Public License v3.0 | 6 votes |
makeVideoAnnotationString = (annotation: VideoAnnotation) => {
const annotationString = ` **${annotation.title}** %%TIMESTAMP: ${annotation.start}%%\n${annotation.content}`;
return (
'\n' +
annotationString
.split('\n')
.map(x => `>${x}`)
.join('\n') +
'\n^' +
annotation._id +
'\n'
);
}
Example #6
Source File: videoAnnotationFileUtils.tsx From obsidian-annotator with GNU Affero General Public License v3.0 | 5 votes |
export async function getVideoAnnotation(annotationId: string, file: TFile, vault: Vault): Promise<VideoAnnotation> {
const text = await vault.read(file);
return getVideoAnnotationFromFileContent(annotationId, text);
}
Example #7
Source File: videoAnnotationUtils.tsx From obsidian-annotator with GNU Affero General Public License v3.0 | 5 votes |
export function loadVideoAnnotationsAtUriFromFileText(url: URL | null, fileText: string | null): VideoAnnotation[] {
const params = url ? Object.fromEntries(url.searchParams.entries()) : null;
if (params?.uri == 'app://obsidian.md/index.html') {
return [];
}
const rows = [];
const annotationRegex = makeVideoAnnotationBlockRegex();
if (fileText !== null) {
let m: RegExpExecArray;
while ((m = annotationRegex.exec(fileText)) !== null) {
if (m.index === annotationRegex.lastIndex) {
annotationRegex.lastIndex++;
}
const {
groups: { annotationId, time, title, content }
} = m;
const completeVideoAnnotation = {
readwiseId: '',
content: content
.trim()
.split('\n')
.map(x => x.substr(1))
.join('\n'),
title,
tags: [],
_id: annotationId,
video: '620d5a42b9ab630009bf3e31',
start: Number(time.trim()),
user: 'obsidianuser',
updatedAt: JSON.parse(JSON.stringify(new Date())),
createdAt: JSON.parse(JSON.stringify(new Date())),
__v: 0
};
rows.push(completeVideoAnnotation);
}
}
return rows;
}
Example #8
Source File: videoAnnotationUtils.tsx From obsidian-annotator with GNU Affero General Public License v3.0 | 5 votes |
export function checkPseudoVideoAnnotationEquality(
annotation: VideoAnnotation,
pseudoVideoAnnotation: VideoAnnotation
): boolean {
return annotation.start == pseudoVideoAnnotation.start;
}