Skip to content

Commit

Permalink
Merge branch '2.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
gegehprast committed Feb 9, 2020
2 parents db71fe8 + 2f85d47 commit 04bb03c
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 6 deletions.
20 changes: 17 additions & 3 deletions Browser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ class Browser {
return [this.browser, this.browser2]
}

/**
* Create new page.
*/
async newPage() {
const page = await this.browser.newPage()
page.setDefaultTimeout(30000)

return page
}

/**
* Create new optimized asset page.
*/
Expand All @@ -45,19 +55,23 @@ class Browser {

/**
* Get new tab page instance.
* @param page current page.
*
* @param {Object} page Current page.
* @param {Boolean} optimized Optimized or not.
*/
async getNewTabPage(page) {
async getNewTabPage(page, optimized = true) {
const pageTarget = page.target()
const newTarget = await this.browser.waitForTarget(target => target.opener() === pageTarget)
const newPage = await newTarget.page()
newPage.setDefaultTimeout(30000)

return await this.optimizePage(newPage)
return optimized ? await this.optimizePage(newPage) : newPage
}

/**
* Optimize a page.
*
* @param {Object} page Current page.
*/
async optimizePage(page) {
await page.setRequestInterception(true)
Expand Down
33 changes: 32 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "shallty",
"version": "2.2.0",
"version": "2.2.2",
"description": "Shallty adalah aplikasi untuk meng-crawl situs fastsub/fanshare Indonesia. Tujuan utamanya adalah untuk melewati berbagai halaman redirect dan mengambil tautan unduh aslinya. Saat ini Shallty telah mendukung crawling untuk Meownime, Samehadaku, Neonime, dan Oploverz. https://shallty.kyuun.id",
"main": "index.js",
"scripts": {
Expand All @@ -18,6 +18,7 @@
"url": "https://github.com/gegehprast/shallty.git"
},
"dependencies": {
"axios": "^0.19.2",
"express": "^4.17.1",
"lodash": "^4.17.15",
"puppeteer": "^2.0.0",
Expand Down
7 changes: 7 additions & 0 deletions shortlinks/Anjay.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const Browser = require('../Browser')
const Handler = require('../exceptions/Handler')
const Util = require('../utils/utils')
const Coeg = require('./Coeg')

class Anjay {
constructor() {
Expand Down Expand Up @@ -42,6 +43,12 @@ class Anjay {
await Util.sleep(3000)
const url = page.url()

if (url.includes('bucin')) {
await page.close()

return Coeg.parse(url)
}

if (!url.includes('ahexa') && !url.includes('anjay')) {
await page.close()

Expand Down
3 changes: 2 additions & 1 deletion shortlinks/Coeg.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ class Coeg {
'siotong',
'telondasmu',
'greget',
'siherp'
'siherp',
'bucin'
]
}

Expand Down
40 changes: 40 additions & 0 deletions shortlinks/Neonime.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const Browser = require('../Browser')
const Util = require('../utils/utils')
const Handler = require('../exceptions/Handler')

class Neonime {
constructor() {
this.marker = 'neonime.org'
}

async parse(link) {
const page = await Browser.newOptimizedPage()

try {
link = decodeURIComponent(link)
await page.goto(link)

await Util.sleep(9500)
await page.click('#generater')
await Util.sleep(9500)
await page.click('#showlink')

const finalPage = await Browser.getNewTabPage(page)
await Util.sleep(2000)
const url = finalPage.url()

await page.close()
await finalPage.close()

return {
url: url
}
} catch (error) {
await page.close()

return Handler.error(error)
}
}
}

module.exports = new Neonime
2 changes: 2 additions & 0 deletions shortlinks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const Hightech = require('./Hightech')
const Jelajahinternet = require('./Jelajahinternet')
const Kepoow = require('./Kepoow')
const Kontenajaib = require('./Kontenajaib')
const Neonime = require('./Neonime')
const Semawur = require('./Semawur')
const Sukakesehattan = require('./Sukakesehattan')
const Teknoku = require('./Teknoku')
Expand All @@ -26,6 +27,7 @@ class Shortlink {
Jelajahinternet,
Kepoow,
Kontenajaib,
Neonime,
Semawur,
Sukakesehattan,
Teknoku,
Expand Down
14 changes: 14 additions & 0 deletions test/unit/shortlink.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,18 @@ describe('shortlink', function () {
expect(data.url).to.include('solidfiles.com')
})
})

describe('neonime', function () {
it('should return an object which has a string url property', async function () {
this.timeout(60000)
await Browser.init()
const data = await Shortlink.parse('https%3A%2F%2Fneonime.org%2F%3Ffd3c883ce6%3DQzl4djNGUFpDZHVjZUJCWVdKenhwcWpOUndkV0crTThpaUh5d2k2dFVrL1czSWVRbExvUlFrRy8yWlBjTDhCQm9aNmhhdlp2UXNZVkQ4M0dwdEh3UHd6ZXFHMjdiSjB6cDlFQ1J5eDdSbVVVTUZTL0NEV3dXemV5TWxjN2IrSlE%3D')
console.log(data)

expect(data).to.be.an('object')
expect(data).to.has.property('url')
expect(data.url).to.be.a('string')
expect(data.url).to.include('zippyshare')
})
})
})

0 comments on commit 04bb03c

Please sign in to comment.