Skip to content

Commit

Permalink
Merge pull request #55 from lstrzepek/fix-mobile
Browse files Browse the repository at this point in the history
Fixed mobile version with unsupported url format error
  • Loading branch information
lstrzepek authored Sep 11, 2024
2 parents 01478a8 + 5689e3c commit c0d138e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "ytranscript",
"name": "YTranscript",
"version": "0.9.2",
"version": "1.0.0",
"minAppVersion": "0.15.0",
"description": "This is simple plugin to fetch transcription for Youtube.",
"author": "Łukasz Strzępek",
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-ytranscript",
"version": "0.9.2",
"version": "1.0.0",
"description": "This is a sample plugin for Obsidian (https://obsidian.md)",
"main": "main.js",
"scripts": {
Expand Down
17 changes: 14 additions & 3 deletions src/fetch-transcript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export class YoutubeTranscript {
) {
try {
const langCode = config?.lang ?? "en";

const videoPageBody = await request(url);
const parsedBody = parse(videoPageBody);

Expand Down Expand Up @@ -71,16 +72,26 @@ export class YoutubeTranscript {
) ?? availableCaptions?.[0];

const captionsUrl = captionTrack?.baseUrl;
const fixedCaptionsUrl = captionsUrl.startsWith("https://")
? captionsUrl
: "https://www.youtube.com" + captionsUrl;

const resXML = await request(captionsUrl).then((xml) => parse(xml));
const resXML = await request(fixedCaptionsUrl).then((xml) =>
parse(xml),
);

const chunks = resXML.getElementsByTagName("text");
console.log(chunks);

return {
title: title,
lines: chunks.map((cue: any) => ({
text: cue.textContent.replaceAll("'", "'"),
text: cue.textContent
.replaceAll("'", "'")
.replaceAll("&", "&")
.replaceAll(""", '"')
.replaceAll("'", "'")
.replaceAll("&lt;", "<")
.replaceAll("&gt;", ">"),
duration: parseFloat(cue.attributes.dur) * 1000,
offset: parseFloat(cue.attributes.start) * 1000,
})),
Expand Down

0 comments on commit c0d138e

Please sign in to comment.