Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ImprovedTube committed Sep 9, 2023
1 parent 53a9835 commit b4cf9f7
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 18 deletions.
24 changes: 13 additions & 11 deletions js&css/web-accessible/www.youtube.com/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,17 @@ ImprovedTube.playerPlaybackSpeed = function () {
&& this.storage.player_force_speed_on_music !== true
|| this.storage.player_dont_speed_education === true) {
// Data:
let category = document.querySelector('meta[itemprop=genre]')?.content;
let category = document.querySelector('meta[itemprop=genre]')?.content || false;
if (this.storage.player_dont_speed_education === true && category === 'Education') {return;}
if (this.storage.player_force_speed_on_music === true) {return;}
let titleAndKeywords = document.getElementsByTagName('meta')?.title?.content + " " + document.getElementsByTagName('meta')?.keywords?.content;
let duration = document.querySelector('meta[itemprop=duration]')?.content; // Example: PT1H20M30S
let titleAndKeywords = document.getElementsByTagName('meta')?.title?.content + " " + document.getElementsByTagName('meta')?.keywords?.content || false;
let musicRegexMatch = /official (music )?video|lyrics|cover[\)\]]|[\(\[]cover|cover version|karaok|(sing|play)[- ]?along|OK|OK|الكاريوكي|караоке||/i.test(titleAndKeywords) || false;
let notMusicRegexMatch = /do[ck]u|interv[iyj]|back[- ]?stage||entrevista||||wawancara|مقابلة|интервью|entretien| ||||وثائقي|документальный/i.test(titleAndKeywords) || false; // (Tags/keywords shouldnt lie & very few songs titles might have these words)
let duration = document.querySelector('meta[itemprop=duration]')?.content || false; // Example: PT1H20M30S
if (duration) {
function parseDuration(duration) { const [_, h = 0, m = 0, s = 0] = duration.match(/PT(?:(\d+)?H)?(?:(\d+)?M)?(\d+)?S?/).map(part => parseInt(part) || 0);
return h * 3600 + m * 60 + s; }
let durationInSeconds = parseDuration(duration);
let musicRegexMatch = /official (music )?video|lyrics|cover[\)\]]|[\(\[]cover|cover version|karaok|(sing|play)[- ]?along|OK|OK|الكاريوكي|караоке||/i.test(titleAndKeywords);
let notMusicRegexMatch = /do[ck]u|interv[iyj]|back[- ]?stage||entrevista||||wawancara|مقابلة|интервью|entretien| ||||وثائقي|документальный/i.test(titleAndKeywords);
// (Tags/keywords shouldnt lie & very few songs titles might have these words)
function testSongDuration(s) {
if (135 <= s && s <= 260) {return 'veryCommon';}
if (105 <= s && s <= 420) {return 'common';}
Expand All @@ -95,7 +95,9 @@ ImprovedTube.playerPlaybackSpeed = function () {
if (musicSectionLength && (85 <= s / musicSectionLength && s / musicSectionLength<= 355)) {return 'multiple';}
}
let songDurationType = testSongDuration(durationInSeconds);
// check if the video is PROBABLY MUSIC:
}

// check if the video is PROBABLY MUSIC:
if ( ( category === 'Music' && (!notMusicRegexMatch || songDurationType === 'veryCommon'))
|| ( musicRegexMatch && typeof songDurationType !== 'undefined' && !notMusicRegexMatch )
|| ( category === 'Music' && musicRegexMatch && typeof songDurationType !== 'undefined'
Expand All @@ -107,14 +109,14 @@ ImprovedTube.playerPlaybackSpeed = function () {
else { player.setPlaybackRate(Number(option)); video.playbackRate = Number(option); // #1729 question2
// Now this video might rarely be music
// - however we can make extra-sure after waiting for the video descripion to load... (#1539)
tries = 0; intervalMs = 150; if (location.href.indexOf('/watch?') !== -1) {maxTries = 10;} else {maxTries = 1;}
var tries = 0; var intervalMs = 150; if (location.href.indexOf('/watch?') !== -1) {var maxTries = 10;} else {var maxTries = 1;}
// ...except when it is an embedded player?

var waitForDescription = setInterval(() => {
if (document.querySelector('div#description') || (++tries >= maxTries) ) {clearInterval(waitForDescription);}
if (document.querySelector('div#description') || (++tries >= maxTries) ) {
if (document.querySelector('h3#title[class*="music-section"]') // indicates buyable/registered music
&& typeof testSongDuration(durationInSeconds) !== 'undefined' ) // resonable duration
{player.setPlaybackRate(1); video.playbackRate = 1;}
&& typeof testSongDuration(parseDuration(document.querySelector('meta[itemprop=duration]')?.content)) !== 'undefined' ) // resonable duration
{player.setPlaybackRate(1); video.playbackRate = 1; clearInterval(waitForDescription);}}
intervalMs *= 1.4;
}, intervalMs);
}
Expand Down
12 changes: 9 additions & 3 deletions js&css/web-accessible/www.youtube.com/playlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@ ImprovedTube.playlistUpNextAutoplay = function (event) {
ImprovedTube.getParam(location.href, 'list') &&
ImprovedTube.storage.playlist_up_next_autoplay === false
) {
this.elements.ytd_watch.playlistData.currentIndex = this.elements.ytd_watch.playlistData.totalVideos
if (this.elements.ytd_watch.playlistData)
{this.elements.ytd_watch.playlistData.currentIndex = this.elements.ytd_watch.playlistData.totalVideos}
else {tries = 0; intervalMs = 300; maxTries = 5;
var waitForPlaylist = setInterval(() => {
if (this.elements.ytd_watch.playlistData || (++tries >= maxTries) ) {
this.elements.ytd_watch.playlistData.currentIndex = this.elements.ytd_watch.playlistData.totalVideos; clearInterval(waitForPlaylist );}
intervalMs *= 1.4;}, intervalMs);
}
}
};

};
/*------------------------------------------------------------------------------
4.5.2 REVERSE
------------------------------------------------------------------------------*/
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"short_name" : "ImprovedTube",
"name": "'Improve YouTube!' 🎧 (for YouTube & Videos)",
"description": "__MSG_description_ext__",
"version": "4.321",
"version": "4.335",
"default_locale": "en",
"icons": {
"16": "stuff/icons/16.png",
Expand Down
6 changes: 3 additions & 3 deletions menu/skeleton-parts/appearance.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,13 @@ extension.skeleton.main.layers.section.appearance.on.click.player = {
options: [{
text: "doNotChange",
value: "do_not_change"
}, {
text: "Max. width within the page",
value: "max_width"
}, {
text: "fullWindow",
value: "full_window"
}, {
text: "Max. width within the page",
value: "max_width"
}, {
text: "fitToWindow",
value: "fit_to_window"
}, {
Expand Down

0 comments on commit b4cf9f7

Please sign in to comment.