diff --git a/YoutubeConfig.json b/YoutubeConfig.json index 1dac57bc5d4ad8b20d8ce90b80904a9e54841785..10f5fe1d2e06f9680c9d57b82946a043db86b74d 100644 --- a/YoutubeConfig.json +++ b/YoutubeConfig.json @@ -7,7 +7,7 @@ "sourceUrl": "https://plugins.grayjay.app/Youtube/YoutubeConfig.json", "repositoryUrl": "https://futo.org", "scriptUrl": "./YoutubeScript.js", - "version": 177, + "version": 178, "iconUrl": "./youtube.png", "id": "35ae969a-a7db-11ed-afa1-0242ac120002", diff --git a/YoutubeScript.js b/YoutubeScript.js index ef5c8f8693882d11f20c98637111902b8c37b960..654afc0fd21dc29dcc73dce7c7b1c31e1c866e5e 100644 --- a/YoutubeScript.js +++ b/YoutubeScript.js @@ -62,6 +62,9 @@ const REGEX_VIDEO_PLAYLIST_URL = new RegExp("https://(.*\\.)?youtube\\.com/playl const REGEX_INITIAL_DATA = new RegExp("<script.*?var ytInitialData = (.*?);<\/script>"); const REGEX_INITIAL_PLAYER_DATA = new RegExp("<script.*?var ytInitialPlayerResponse = (.*?});"); +//TODO: Make this one more flexible/reliable. For now used as fallback if initial fails. +const REGEX_INITIAL_PLAYER_DATA_FALLBACK = new RegExp("<script.*?var ytInitialPlayerResponse = (.*});var meta = document\.createElement"); + const REGEX_HUMAN_NUMBER = new RegExp("([0-9\\.,]*)([a-zA-Z]*)"); const REGEX_HUMAN_AGO = new RegExp("([0-9]*) ([a-zA-Z]*) ago"); @@ -2202,10 +2205,20 @@ function getInitialData(html, useAuth = false) { return null; } function getInitialPlayerData(html) { - const match = html.match(REGEX_INITIAL_PLAYER_DATA); + let match = html.match(REGEX_INITIAL_PLAYER_DATA); if(match) { - const initialDataRaw = match[1]; - return JSON.parse(initialDataRaw); + let initialDataRaw = match[1]; + try { + return JSON.parse(initialDataRaw); + } + catch(ex) { + //Fallback approach + match = html.match(REGEX_INITIAL_PLAYER_DATA_FALLBACK); + if(match) { + initialDataRaw = match[1]; + return JSON.parse(initialDataRaw); + } + } } return null; }