Skip to content

Commit

Permalink
Fix youtube connector
Browse files Browse the repository at this point in the history
Fix an issue where the connector refused to process chapters, when `allowedCategories` was not empty.

The `getUniqueID` function always returns `null` for chapters, so we need to get video ID directly to fetch the video category.
  • Loading branch information
alexesprit committed Aug 30, 2020
1 parent b50dfb0 commit 6711ecd
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions src/connectors/youtube.js
Expand Up @@ -80,19 +80,7 @@ Connector.getUniqueID = () => {
return null;
}

/*
* ytd-watch-flexy element contains ID of a first played video
* if the miniplayer is visible, so we should check
* if URL of a current video in miniplayer is accessible.
*/
const miniPlayerVideoUrl = $('ytd-miniplayer[active] [selected] a').attr(
'href'
);
if (miniPlayerVideoUrl) {
return Util.getYtVideoIdFromUrl(miniPlayerVideoUrl);
}

return $('ytd-watch-flexy').attr('video-id');
return getVideoId();
};

Connector.isScrobblingAllowed = () => {
Expand All @@ -110,7 +98,7 @@ Connector.isScrobblingAllowed = () => {
return true;
}

const videoCategory = getVideoCategory(Connector.getUniqueID());
const videoCategory = getVideoCategory();
if (!videoCategory) {
return false;
}
Expand All @@ -132,12 +120,26 @@ function areChaptersAvailable() {
return Util.getTextFromSelectors(chapterNameSelector);
}

/**
* Get video category.
* @param {String} videoId Video ID
* @return {String} Video category
*/
function getVideoCategory(videoId) {
function getVideoId() {
/*
* ytd-watch-flexy element contains ID of a first played video
* if the miniplayer is visible, so we should check
* if URL of a current video in miniplayer is accessible.
*/
const miniPlayerVideoUrl = Util.getAttrFromSelectors(
'ytd-miniplayer[active] [selected] a',
'href'
);
if (miniPlayerVideoUrl) {
return Util.getYtVideoIdFromUrl(miniPlayerVideoUrl);
}

return Util.getAttrFromSelectors('ytd-watch-flexy', 'video-id');
}

function getVideoCategory() {
const videoId = getVideoId();

if (!videoId) {
return null;
}
Expand Down

0 comments on commit 6711ecd

Please sign in to comment.