Things I have tried
This code copies and pastes information from a Youtube video.<%*
let url = await tp.system.clipboard();
let page = await tp.obsidian.request({url});
let p = new DOMParser();
let doc = p. parseFromString(page, “text/html”);
let $ = s => doc.querySelector(s);
let qcFileName = $(“meta[property=‘og:title’]”).content;
titleName = “ " + qcFileName;
await tp.file.move(”/004_Videos/" + titleName);
let duration2 = $(“meta[itemprop=‘duration’]”).content.slice(2);
let duration1 = duration2.replace(/M/gi, " Min ") ;
let duration = duration1.replace(/S/gi, " Sec ") ;
%>
-
Title:
*<%$(“meta[property=‘og:title’]”).content %> -
Type:
[[+]] -
URL:
<%$(“link[rel=‘shortLinkUrl’]”).href %> -
Channel/Host:
<%$(“link[itemprop=‘name’]”).getAttribute(“content”) %> -
Publish Date:
<%$(“meta[itemprop=‘uploadDate’]”).content.slice(0, 4) %> -
Duration
: <% duration %>
<% qcFileName %>
When I apply it through Templater it works very well… but when the title of a video has a special character the following console error appears: File name cannot contain any of the following characters: * " \ / < > : | ?
What additional line of code can help to exclude these characters?
What I’m trying to do
The only thing I could do is omit the variable that contains the original title; This is the only way I can skip the error; I would like to know what lines of code can be inserted so that everything Works automatically.
<%*
let url = await tp.system.clipboard();
let page = await tp.obsidian.request({url});
let p = new DOMParser();
let doc = p. parseFromString(page, “text/html”);
let $ = s => doc.querySelector(s);
let qcFileName = $(“meta[property=‘og:title’]”).content;
titleName = “ Change Title Manually”;
<— The Error Gone----<<
await tp.file.move(“/004_Videos/” + titleName);
let duration2 = $(“meta[itemprop=‘duration’]”).content.slice(2);
let duration1 = duration2.replace(/M/gi, " Min ") ;
let duration = duration1.replace(/S/gi, " Sec ") ;
%>
<% qcFileName %>
> Blockquote