diff --git a/.gitignore b/.gitignore index 5e247de..f11aced 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,4 @@ -# File is synced from zeronet-js repo - # Configs, etc. -*.pem config.json # NodeJS @@ -14,26 +11,9 @@ package-lock.json dist docs -# pkg -zeronet-linux* -zeronet-macos* -zeronet-win* -.pkg - # Other garbage *.bak *.log tmp /data -.zeronet - -# Python -*.pyc - -# snap -parts -prime -stage -*.tar.bz2 -*.snap -snap/.snapcraft +*.apk diff --git a/README.md b/README.md new file mode 100644 index 0000000..5cf5d93 --- /dev/null +++ b/README.md @@ -0,0 +1,39 @@ +# apkmirror-client + +Download APKs from APKMirror.com + +# Example + +> Download Whatsapp + +```js +'use strict' + +const apk = require('apkmirror-client') +const fs = require('fs') + +apk.searchForApps('whatsapp', (err, res) => { // search for whatsapp + if (err) throw err + let whatsapp = res.filter(r => r.app.name === 'WhatsApp Messenger')[0] // this makes sure we don't get any "whatsapp gold" stuff + apk.getAppPage(whatsapp, (err, page) => { // now download details + if (err) throw err + console.log(page) + + page.versions.filter(v => !v.beta)[0].loadRelease((err, release) => { // now get latest non-beta release + if (err) throw err + console.log(release) + + release.estimateBestCandidate('arm64').loadVariant((err, download) => { // now get the arm64 release + if (err) throw err + console.log(res) + download.downloadAPK((err, apk) => { // and finally download the apk + if (err) throw err + apk.pipe(fs.createWriteStream('./whatsapp.apk')).on('close', () => { // ...into this file + console.log('Saved as whatsapp.apk!') + }) + }) + }) + }) + }) +}) +``` diff --git a/example.js b/example.js new file mode 100644 index 0000000..72559dc --- /dev/null +++ b/example.js @@ -0,0 +1,32 @@ +'use strict' + +/* eslint-disable max-nested-callbacks */ +/* eslint-disable no-console */ + +const apk = require('apkmirror-client') +const fs = require('fs') + +apk.searchForApps('whatsapp', (err, res) => { // search for whatsapp + if (err) throw err + let whatsapp = res.filter(r => r.app.name === 'WhatsApp Messenger')[0] // this makes sure we don't get any "whatsapp gold" stuff + apk.getAppPage(whatsapp, (err, page) => { // now download details + if (err) throw err + console.log(page) + + page.versions.filter(v => !v.beta)[0].loadRelease((err, release) => { // now get latest non-beta release + if (err) throw err + console.log(release) + + release.estimateBestCandidate('arm64').loadVariant((err, download) => { // now get the arm64 release + if (err) throw err + console.log(res) + download.downloadAPK((err, apk) => { // and finally download the apk + if (err) throw err + apk.pipe(fs.createWriteStream('./whatsapp.apk')).on('close', () => { // ...into this file + console.log('Saved as whatsapp.apk!') + }) + }) + }) + }) + }) +}) diff --git a/package.json b/package.json index 32148e9..4ac6206 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "apkmirror-client", "version": "0.1.1", - "description": "Client to download APKs from Apkmirror", + "description": "Download APKs from APKMirror.com", "main": "src/index.js", "scripts": { "test": "aegir test -t node", @@ -25,11 +25,11 @@ "dependencies": { "data-queue": "0.0.3", "debug": "^3.1.0", - "jquery": "^3.2.1", - "jsdom": "^11.5.1" + "jquery": "^3.3.1", + "jsdom": "^11.10.0" }, "devDependencies": { - "aegir": "^12.2.0", + "aegir": "^13.1.0", "chai": "^4.1.2", "dirty-chai": "^2.0.1" }, diff --git a/src/index.js b/src/index.js index 094d6a8..ab4f480 100644 --- a/src/index.js +++ b/src/index.js @@ -55,11 +55,8 @@ module.exports = { return res ? orig.filter(i => i.id === res.id)[0] : false }, downloadAPK: (url, cb) => { - get(url, {parser: 'appDownloadPage'}, (err, url) => { - if (err) return cb(err) - log('download apk from %s', url) - cb(null, request.get(url)) - }) + log('download apk from %s', url) + cb(null, request.get(url)) } } diff --git a/src/parser/appDownloadPage.js b/src/parser/appDownloadPage.js deleted file mode 100644 index ed5f350..0000000 --- a/src/parser/appDownloadPage.js +++ /dev/null @@ -1,5 +0,0 @@ -'use strict' - -module.exports = ($, window, cb) => { - cb(null, $('a[rel=nofollow]')[0].href) -} diff --git a/src/parser/appPage.js b/src/parser/appPage.js index 64b70e8..3f92e7b 100644 --- a/src/parser/appPage.js +++ b/src/parser/appPage.js @@ -1,5 +1,8 @@ 'use strict' +const debug = require('debug') +const log = debug('apkmirror-client:app:page') + const appRow = require('./appRow') const appPageBasic = require('./appPageBasic') const get = require('..') @@ -46,5 +49,7 @@ module.exports = ($, window, cb) => { return obj }, {}) }) + + log('got app page for %s', JSON.stringify(res.app.name)) cb(null, res) } diff --git a/src/parser/appReleasePage.js b/src/parser/appReleasePage.js index b05c72a..1dc3a90 100644 --- a/src/parser/appReleasePage.js +++ b/src/parser/appReleasePage.js @@ -1,5 +1,8 @@ 'use strict' +const debug = require('debug') +const log = debug('apkmirror-client:app:release-page') + const appPageBasic = require('./appPageBasic') const cleanText = s => s.replace(/\n/g, '').trim() const get = require('..') @@ -33,5 +36,7 @@ module.exports = ($, window, cb) => { }) res.estimateBestCandidate = get.estimateBestCandidate.bind(null, res.variants) + log('got release page for %s', JSON.stringify(res.app.name)) + cb(null, res) } diff --git a/src/parser/appSearch.js b/src/parser/appSearch.js index a478d04..944586a 100644 --- a/src/parser/appSearch.js +++ b/src/parser/appSearch.js @@ -1,5 +1,8 @@ 'use strict' +const debug = require('debug') +const log = debug('apkmirror-client:app:search') + const appRow = require('./appRow') module.exports = ($, window, cb) => { @@ -8,5 +11,8 @@ module.exports = ($, window, cb) => { i++ return appRow(e, $($('#content').find('.infoSlide')[i]), $, true) }) + + log('search found %s results', res.length) + cb(null, res) } diff --git a/src/parser/appVariantPage.js b/src/parser/appVariantPage.js index 6e16fad..9c43390 100644 --- a/src/parser/appVariantPage.js +++ b/src/parser/appVariantPage.js @@ -1,5 +1,8 @@ 'use strict' +const debug = require('debug') +const log = debug('apkmirror-client:app:variant-page') + const appPageBasic = require('./appPageBasic') const cleanText = s => s.replace(/\n/g, '').trim() const get = require('..') @@ -35,5 +38,7 @@ module.exports = ($, window, cb) => { }, {}) res.downloadAPK = get.downloadAPK.bind(null, res.download) + log('got variant page for %s', JSON.stringify(res.app.name)) + cb(null, res) } diff --git a/src/parser/index.js b/src/parser/index.js index a33d052..6ae9db0 100644 --- a/src/parser/index.js +++ b/src/parser/index.js @@ -4,6 +4,5 @@ module.exports = { appSearch: require('./appSearch'), appPage: require('./appPage'), appReleasePage: require('./appReleasePage'), - appVariantPage: require('./appVariantPage'), - appDownloadPage: require('./appDownloadPage') + appVariantPage: require('./appVariantPage') }