Skip to content
This repository has been archived by the owner on Jul 18, 2023. It is now read-only.

Commit

Permalink
Add a Architecture selector for YTM
Browse files Browse the repository at this point in the history
  • Loading branch information
reisxd committed Aug 7, 2022
1 parent 1f2d1bc commit 0c61066
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 19 deletions.
2 changes: 0 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ app.use(
server.listen(8080, () => {
console.log('The webserver is now running!');
try {
// Shrihan, I sometimes question what are you doing with the console
// :moyai:
console.log('Opening the app in the default browser...');
open('http://localhost:8080');
console.log('Done. Check if a browser window has opened');
Expand Down
47 changes: 41 additions & 6 deletions public/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ let currentFile;
let alreadyAddedLog = false;
let isDownloading = false;
let hasFinished = false;
let arch;
let versionChoosen;

function sendCommand (args) {
ws.send(JSON.stringify(args));
Expand Down Expand Up @@ -71,18 +73,22 @@ function setPatches () {
location.href = '/versions';
}

function setAppVersion () {
function setAppVersion (arch, version) {
if (!isDownloading) {
if (!document.querySelector('input[name="version"]:checked')) {
return alert("You didn't select an app version!");
if (!arch) {
if (!document.querySelector('input[name="version"]:checked')) {
return alert("You didn't select an app version!");
}
}

sendCommand({
event: 'selectAppVersion',
versionChoosen: document.querySelector('input[name="version"]:checked')
.value
versionChoosen: version || document.querySelector('input[name="version"]:checked').value,
arch
});

document.getElementsByTagNane('header')[0].innerHTML = '<h1>Downloading APK...</h1>'
document.getElementsByTagName('header')[0].innerHTML =
'<h1>Downloading APK...</h1>';
document.getElementById('content').innerHTML = '<span class="log"></span>';
document.getElementsByTagName('main')[0].innerHTML +=
'<progress value="0"></progress>';
Expand Down Expand Up @@ -211,6 +217,35 @@ ws.onmessage = (msg) => {
<label for="app-${i}">${version.version}</label></li>`;
i++;
}

if (message.selectedApp === 'music') {
document.getElementById('continue').onclick = () => {
let version = document.querySelector(
'input[name="version"]:checked'
).value;
document.getElementsByTagName('header')[0].innerHTML = `
<h1>Please select the architecture</h1>
<span>YouTube Music APKs only have specific architecture APKs.
<br>If you don't know which one to choose, either look at your devices architecture using CPU-Z or select Arm64.</span>`;
document.getElementById('versions').innerHTML = '';
document.getElementById('versions').innerHTML += `
<li>
<input type="radio" name="arch" id="arch-1" value="arm64-v8a"/>
<label for="arch-1">Arm64 (armv8)</label></li>
<li>
<input type="radio" name="arch" id="arch-2" value="armeabi-v7a"/>
<label for="arch-2">Arm32 (armv7)</label></li>`;
document.getElementById('continue').onclick = () => {
if (isDownloading && hasFinished) {
location.href = '/patch';
}
setAppVersion(
document.querySelector('input[name="arch"]:checked').value,
version
);
};
};
}
break;
}

Expand Down
25 changes: 18 additions & 7 deletions utils/downloadApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const fetchURL = require('node-fetch');
const { load } = require('cheerio');
const { dloadFromURL } = require('../utils/FileDownlader.js');

module.exports = async function (version, ws) {
module.exports = async function (version, ws, arch) {
const apkVersion = version.replace(/\./g, '-');

let versionDownload;
Expand Down Expand Up @@ -56,12 +56,23 @@ module.exports = async function (version, ws) {
const versionDownloadList = await versionDownload.text();

const vDLL = load(versionDownloadList);
const dlLink = vDLL('span[class="apkm-badge"]')
.first()
.parent()
.children('a[class="accent_color"]')
.first()
.attr('href');
let dlLink;
if (arch) {
dlLink = vDLL(`div:contains("${arch}")`)
.parent()
.children('div[class^="table-cell rowheight"]')
.first()
.children('a[class="accent_color"]')
.first()
.attr('href');
} else {
dlLink = vDLL('span[class="apkm-badge"]')
.first()
.parent()
.children('a[class="accent_color"]')
.first()
.attr('href');
}

const downloadLink = await fetchURL(`https://www.apkmirror.com${dlLink}`);
const downloadLinkPage = await downloadLink.text();
Expand Down
3 changes: 2 additions & 1 deletion wsEvents/GetAppVersion.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ module.exports = async function (message, ws) {
return ws.send(
JSON.stringify({
event: 'appVersions',
versionList
versionList,
selectedApp: global.jarNames.selectedApp
})
);
};
4 changes: 2 additions & 2 deletions wsEvents/PatchApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ module.exports = async function (message, ws) {
ws.send(
JSON.stringify({
event: 'patchLog',
log: data.toString(),
log: data.toString()
})
);

Expand All @@ -177,7 +177,7 @@ module.exports = async function (message, ws) {
ws.send(
JSON.stringify({
event: 'patchLog',
log: data.toString(),
log: data.toString()
})
);

Expand Down
2 changes: 1 addition & 1 deletion wsEvents/SelectAppVersion.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const downloadApp = require('../utils/downloadApp.js');

module.exports = async function (message, ws) {
await downloadApp(message.versionChoosen, ws);
await downloadApp(message.versionChoosen, ws, message.arch);
};

0 comments on commit 0c61066

Please sign in to comment.