Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

youtube quality android #196

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/resources.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion filter_lists/list_catalog.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
"support_url": "https://github.com/brave/adblock-lists"
},
{
"url": "https://raw.githubusercontent.com/brave/adblock-lists/master/brave-lists/brave-specific.txt",
"url": "https://raw.githubusercontent.com/brave/adblock-lists/d2ab11d0241c5e135315652de96c52fa975dd0a0/brave-lists/brave-specific.txt",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was for testing. I'll revert this to master

"title": "Brave Specific",
"format": "Standard",
"support_url": "https://github.com/brave/adblock-lists"
Expand Down
8 changes: 8 additions & 0 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@
},
"resourcePath": "brave-youtube-navigation-fix.js"
},
{
"name": "brave-youtube-quality.js",
"aliases": [],
"kind": {
"mime": "application/javascript"
},
"resourcePath": "brave-youtube-quality.js"
},
{
"name": "brave-youtube-theater-fix.js",
"aliases": [],
Expand Down
30 changes: 30 additions & 0 deletions resources/brave-youtube-quality.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/// brave-youtube-quality.js
(function() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tapanmodh do you know if the same script works for desktop ? I think It should. We can create an issue for the desktop if we want to use the same feature on the desktop.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, same script works for desktop

const IS_MOBILE_YOUTUBE = window.location.hostname == 'm.youtube.com';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hostname could be www.youtube.com

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to include both as we need m.youtube.com for mobile sites and www.youtube.com for desktop sites option

const IS_ANDROID = window.navigator.userAgent.indexOf('Android') > -1;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why don't you decide whether to inject the script or not in native (java or cpp)?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stoletheminerals it's not possible if we're using this via adblock scriptlet injections; those can be selectively injected per-domain, but not according to any other criteria. If you want to move checks to native code it'll have to be a completely separate injection mechanism.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@antonok-edm thanks, yeah that makes sense. I'm just not sure why we decided to move this code to adblock scriptlets. To me it's weird to inject first and then check if we injected it on Android, when we could decide before the injection, but I understand that we can't do it in the current implementation. Anyway, it's not a security concern.


if (IS_ANDROID && IS_MOBILE_YOUTUBE && typeof isYoutubeHdQualityPlaybackEnabled !== 'undefined' && isYoutubeHdQualityPlaybackEnabled) {
navigation.addEventListener('navigate', (event) => {
const url = new URL(event.destination.url);
if (url.pathname && url.pathname === '/watch' && url.search && url.searchParams.get('v')) {
const mutationObserver = new MutationObserver(() => {
let player = document.getElementById('movie_player');
if (player && typeof player.getAvailableQualityLevels !== 'undefined') {
setPlaybackVideoQuality(player, 'hd720');
mutationObserver.disconnect();
}
});
mutationObserver.observe(document.body, { childList: true, subtree: true });
}
});

function setPlaybackVideoQuality(player, quality) {

if (player.setPlaybackQualityRange) {
player.setPlaybackQualityRange(quality);
} else if (player.setPlaybackQuality) {
player.setPlaybackQuality(quality);
}
}
}
})()