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

[pull] master from diygod:master #59

Merged
merged 6 commits into from
Sep 16, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions lib/v2/alternativeto/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
'/software/:name/:routeParams?': ['JimenezLi'],
'/platform/:name/:routeParams?': ['JimenezLi'],
};
32 changes: 32 additions & 0 deletions lib/v2/alternativeto/platform.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const { baseURL, puppeteerGet } = require('./utils');
const cheerio = require('cheerio');

module.exports = async (ctx) => {
const name = ctx.params.name;
const query = new URLSearchParams(ctx.params.routeParams);
const link = `https://alternativeto.net/platform/${name}/?${query.toString()}`;

// use Puppeteer due to the obstacle by cloudflare challenge
const html = await puppeteerGet(link, ctx.cache);
const $ = cheerio.load(html);

ctx.state.data = {
title: $('.Heading_h1___Cf5Y').text().trim(),
description: $('.intro-text').text().trim(),
link,
item: $('.AppListItem_appInfo__h9cWP')
.toArray()
.map((element) => {
const item = $(element);
const title = item.find('.Heading_h2___LwQD').text().trim();
const link = `${baseURL}${item.find('.Heading_h2___LwQD a').attr('href')}`;
const description = item.find('.AppListItem_description__wtODK').text().trim();

return {
title,
link,
description,
};
}),
};
};
19 changes: 19 additions & 0 deletions lib/v2/alternativeto/radar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = {
'alternativeto.net': {
_name: 'AlternativeTo',
www: [
{
title: 'Software Alternatives',
docs: 'https://docs.rsshub.app/routes/programming#alternativeto-software-alternatives',
source: '/software/:name',
target: '/software/:name',
},
{
title: 'Platform Software',
docs: 'https://docs.rsshub.app/routes/programming#alternativeto-platform-software',
source: '/platform/:name',
target: '/platform/:name',
},
],
},
};
4 changes: 4 additions & 0 deletions lib/v2/alternativeto/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = (router) => {
router.get('/software/:name/:routeParams?', require('./software'));
router.get('/platform/:name/:routeParams?', require('./platform'));
};
32 changes: 32 additions & 0 deletions lib/v2/alternativeto/software.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const { baseURL, puppeteerGet } = require('./utils');
const cheerio = require('cheerio');

module.exports = async (ctx) => {
const name = ctx.params.name;
const query = new URLSearchParams(ctx.params.routeParams);
const link = `https://alternativeto.net/software/${name}/?${query.toString()}`;

// use Puppeteer due to the obstacle by cloudflare challenge
const html = await puppeteerGet(link, ctx.cache);
const $ = cheerio.load(html);

ctx.state.data = {
title: $('.Heading_h1___Cf5Y').text().trim(),
description: $('.intro-text').text().trim(),
link,
item: $('.AppListItem_appInfo__h9cWP')
.toArray()
.map((element) => {
const item = $(element);
const title = item.find('.Heading_h2___LwQD').text().trim();
const link = `${baseURL}${item.find('.Heading_h2___LwQD a').attr('href')}`;
const description = item.find('.AppListItem_description__wtODK').text().trim();

return {
title,
link,
description,
};
}),
};
};
22 changes: 22 additions & 0 deletions lib/v2/alternativeto/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const baseURL = 'https://alternativeto.net';

const puppeteerGet = (url, cache) =>
cache.tryGet(url, async () => {
const browser = await require('@/utils/puppeteer')();
const page = await browser.newPage();
await page.setRequestInterception(true);
page.on('request', (request) => {
request.resourceType() === 'document' ? request.continue() : request.abort();
});
await page.goto(url, {
waitUntil: 'domcontentloaded',
});
const html = await page.evaluate(() => document.documentElement.innerHTML);
browser.close();
return html;
});

module.exports = {
baseURL,
puppeteerGet,
};
27 changes: 5 additions & 22 deletions lib/v2/mixcloud/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const { queries } = require('./queries');
module.exports = async (ctx) => {
const host = 'https://www.mixcloud.com';
const imageBaseURL = 'https://thumbnailer.mixcloud.com/unsafe/480x480/';
const graphqlURL = 'https://app.mixcloud.com/graphql';
const headers = {
Referer: host,
'Content-Type': 'application/json',
Expand Down Expand Up @@ -40,7 +41,6 @@ module.exports = async (ctx) => {
username: ctx.params.username,
},
orderBy: 'LATEST',
audioTypes: ['SHOW'],
},
},
favorites: {
Expand All @@ -59,37 +59,20 @@ module.exports = async (ctx) => {
},
},
},
profile: {
query: queries.profile.query,
variables: {
lookup: {
username: ctx.params.username,
},
},
},
};

const profile = (
await got({
method: 'post',
url: `${host}/graphql`,
json: payloads.profile,
headers,
})
).data.data;

const biog = profile.user.biog;
const image = `${imageBaseURL}${profile.user.picture.urlRoot}`;

const data = (
await got({
method: 'post',
url: `${host}/graphql`,
url: graphqlURL,
json: payloads[type],
headers,
})
).data.data;

const biog = data.user.biog;
const image = `${imageBaseURL}${data.user.picture.urlRoot}`;

// https://github.com/ytdl-org/youtube-dl/blob/f1487d4fca40fd37d735753e24a7bae53a1b1513/youtube_dl/extractor/mixcloud.py#L72-L79
const decryptionKey = 'IFYOUWANTTHEARTISTSTOGETPAIDDONOTDOWNLOADFROMMIXCLOUD';
const decryptXorCipher = (key, cipherText) => {
Expand Down
Loading