Skip to content

Commit

Permalink
feat: README, cleanup, updates and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mkg20001 committed May 10, 2018
1 parent 8f10e8c commit fe4043e
Show file tree
Hide file tree
Showing 11 changed files with 100 additions and 37 deletions.
22 changes: 1 addition & 21 deletions .gitignore
@@ -1,7 +1,4 @@
# File is synced from zeronet-js repo

# Configs, etc.
*.pem
config.json

# NodeJS
Expand All @@ -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
39 changes: 39 additions & 0 deletions 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!')
})
})
})
})
})
})
```
32 changes: 32 additions & 0 deletions 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!')
})
})
})
})
})
})
8 changes: 4 additions & 4 deletions 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",
Expand All @@ -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"
},
Expand Down
7 changes: 2 additions & 5 deletions src/index.js
Expand Up @@ -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))
}
}

Expand Down
5 changes: 0 additions & 5 deletions src/parser/appDownloadPage.js

This file was deleted.

5 changes: 5 additions & 0 deletions 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('..')
Expand Down Expand Up @@ -46,5 +49,7 @@ module.exports = ($, window, cb) => {
return obj
}, {})
})

log('got app page for %s', JSON.stringify(res.app.name))
cb(null, res)
}
5 changes: 5 additions & 0 deletions 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('..')
Expand Down Expand Up @@ -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)
}
6 changes: 6 additions & 0 deletions 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) => {
Expand All @@ -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)
}
5 changes: 5 additions & 0 deletions 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('..')
Expand Down Expand Up @@ -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)
}
3 changes: 1 addition & 2 deletions src/parser/index.js
Expand Up @@ -4,6 +4,5 @@ module.exports = {
appSearch: require('./appSearch'),
appPage: require('./appPage'),
appReleasePage: require('./appReleasePage'),
appVariantPage: require('./appVariantPage'),
appDownloadPage: require('./appDownloadPage')
appVariantPage: require('./appVariantPage')
}

0 comments on commit fe4043e

Please sign in to comment.