Skip to content

Commit aa6e047

Browse files
authored
Merge pull request #221 from DominikPieper/hotfix/youtube
hotfix: youtube content types
2 parents d30d7d0 + 2d7c350 commit aa6e047

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

src/helpers/domUtils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export interface JavascriptDeclaration {
44
value: string;
55
}
66

7-
const DECLARATION_REGEX = /(const|let|var)\s+(\w+)\s*=\s*(.+?)\s*(?=(?:^|\s+)(const|let|var)\s+|$)/g;
7+
const DECLARATION_REGEX = /(const|let|var)\s+(\w+)\s*=\s*(.+|\n+?)\s*(?=(?:^|\s+)(const|let|var)\s+|$)/g;
88

99
export function getJavascriptDeclarationByName(
1010
name: string,

src/parsers/PinterestParser.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { request } from 'obsidian';
22
import { desktopBrowserUserAgent } from 'src/helpers/networkUtils';
33
import { normalizeFilename } from 'src/helpers/fileutils';
44
import { replaceImages } from 'src/helpers/replaceImages';
5+
import { handleError } from 'src/helpers/error';
56
import { Note } from './Note';
67
import { Parser } from './Parser';
7-
import { handleError } from 'src/helpers/error';
88

99
interface PinAuthor {
1010
fullName: string;

src/parsers/YoutubeParser.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ class YoutubeParser extends Parser {
152152

153153
const videoHTML = new DOMParser().parseFromString(response, 'text/html');
154154

155-
const declaration = getJavascriptDeclarationByName('ytInitialDataa', videoHTML.querySelectorAll('script'));
155+
const declaration = getJavascriptDeclarationByName('ytInitialData', videoHTML.querySelectorAll('script'));
156156
const jsonData = typeof declaration !== 'undefined' ? JSON.parse(declaration.value) : {};
157157

158158
const videoSchemaElement = videoHTML.querySelector('[itemtype*="http://schema.org/VideoObject"]');
@@ -177,6 +177,11 @@ class YoutubeParser extends Parser {
177177
const videoViewsCount =
178178
jsonData?.contents?.twoColumnWatchNextResults?.results?.results?.contents?.[0]?.videoPrimaryInfoRenderer
179179
?.viewCount?.videoViewCountRenderer?.originalViewCount ?? 0;
180+
const channelId =
181+
jsonData?.contents?.twoColumnWatchNextResults?.results?.results?.contents?.[1]
182+
?.videoSecondaryInfoRenderer?.subscribeButton?.subscribeButtonRenderer?.channelId ??
183+
videoSchemaElement?.querySelector('[itemprop="channelId"]')?.getAttribute('content') ??
184+
'';
180185

181186
return {
182187
date: this.getFormattedDateForContent(createdAt),
@@ -193,7 +198,7 @@ class YoutubeParser extends Parser {
193198
videoViewsCount: videoViewsCount,
194199
videoTags: '',
195200
videoChapters: this.formatVideoChapters(videoId, chapters),
196-
channelId: videoSchemaElement?.querySelector('[itemprop="channelId"')?.getAttribute('content') ?? '',
201+
channelId: channelId,
197202
channelURL: personSchemaElement?.querySelector('[itemprop="url"]')?.getAttribute('href') ?? '',
198203
channelName: personSchemaElement?.querySelector('[itemprop="name"]')?.getAttribute('content') ?? '',
199204
extra: null,

0 commit comments

Comments
 (0)