commit
This commit is contained in:
parent
be4fd23bcf
commit
0bd53741af
728 changed files with 86573 additions and 0 deletions
34
node_modules/googlethis/lib/core/nodes/Converters.js
generated
vendored
Normal file
34
node_modules/googlethis/lib/core/nodes/Converters.js
generated
vendored
Normal file
|
@ -0,0 +1,34 @@
|
|||
'use strict';
|
||||
|
||||
const Constants = require('../../utils/constants');
|
||||
|
||||
class Converters {
|
||||
constructor($) {
|
||||
const unit_converter_input = $(Constants.SELECTORS.UNIT_CONVERTER_INPUT).attr('value');
|
||||
const unit_converter_output = $(Constants.SELECTORS.UNIT_CONVERTER_OUTPUT).attr('value');
|
||||
const unit_converter_formula = $(Constants.SELECTORS.UNIT_CONVERTER_FORMULA).text();
|
||||
|
||||
const input_currency_name = $(Constants.SELECTORS.INPUT_CURRENCY_NAME).attr('data-name');
|
||||
const output_currency_name = $(Constants.SELECTORS.OUTPUT_CURRENCY_NAME).attr('data-name');
|
||||
const currency_converter_input = $(Constants.SELECTORS.CURRENCY_CONVERTER_INPUT).text();
|
||||
const currency_converter_output = $(Constants.SELECTORS.CURRENCY_CONVERTER_OUTPUT).text();
|
||||
|
||||
if (unit_converter_input && unit_converter_output) {
|
||||
this.input = unit_converter_input;
|
||||
this.output = unit_converter_output;
|
||||
this.formula = unit_converter_formula;
|
||||
} else if (currency_converter_input && currency_converter_output) {
|
||||
this.input = {
|
||||
name: input_currency_name,
|
||||
value: currency_converter_input
|
||||
}
|
||||
|
||||
this.output = {
|
||||
name: output_currency_name,
|
||||
value: currency_converter_output
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Converters;
|
34
node_modules/googlethis/lib/core/nodes/Dictionary.js
generated
vendored
Normal file
34
node_modules/googlethis/lib/core/nodes/Dictionary.js
generated
vendored
Normal file
|
@ -0,0 +1,34 @@
|
|||
'use strict';
|
||||
|
||||
const Constants = require('../../utils/constants');
|
||||
|
||||
class Dictionary {
|
||||
/** @type {string | null} */
|
||||
word;
|
||||
|
||||
/** @type {string | null} */
|
||||
phonetic;
|
||||
|
||||
/** @type {string | null} */
|
||||
audio;
|
||||
|
||||
/** @type {string[]} */
|
||||
definitions;
|
||||
|
||||
/** @type {string[]} */
|
||||
examples;
|
||||
|
||||
constructor($) {
|
||||
const word = $(Constants.SELECTORS.GD_WORD).text();
|
||||
const phonetic = $(Constants.SELECTORS.GD_PHONETIC).text();
|
||||
const audio = $(Constants.SELECTORS.GD_AUDIO).attr('src');
|
||||
|
||||
this.word = word || null;
|
||||
this.phonetic = word ? phonetic || 'N/A' : null;
|
||||
this.audio = word && audio ? `https:${audio}` : null;
|
||||
this.definitions = word ? $(Constants.SELECTORS.GD_DEFINITIONS).map((i, el) => $(el).text()).get() : [];
|
||||
this.examples = word ? $(Constants.SELECTORS.GD_EXAMPLES).map((i, el) => $(el).text()).get() : [];
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Dictionary;
|
41
node_modules/googlethis/lib/core/nodes/FeaturedSnippet.js
generated
vendored
Normal file
41
node_modules/googlethis/lib/core/nodes/FeaturedSnippet.js
generated
vendored
Normal file
|
@ -0,0 +1,41 @@
|
|||
'use strict';
|
||||
|
||||
const Constants = require('../../utils/constants');
|
||||
|
||||
class FeaturedSnippet {
|
||||
/** @type {string | null} */
|
||||
title;
|
||||
|
||||
/** @type {string | null} */
|
||||
description;
|
||||
|
||||
/** @type {string | null} */
|
||||
url;
|
||||
|
||||
constructor($) {
|
||||
const featured_snippet_title =
|
||||
$(Constants.SELECTORS.FEATURED_SNIPPET_TITLE[0]).text() ||
|
||||
$(Constants.SELECTORS.FEATURED_SNIPPET_TITLE[1]).text() ||
|
||||
$(Constants.SELECTORS.FEATURED_SNIPPET_TITLE[2]).text();
|
||||
|
||||
const featured_snippet_url = $(Constants.SELECTORS.FEATURED_SNIPPET_URL).map((i, el) => $(el).attr('href')).get()[0];
|
||||
|
||||
const featured_snippet = Constants.SELECTORS.FEATURED_SNIPPET_DESC.map((selector) => {
|
||||
if ($(selector)[0] && selector != Constants.SELECTORS.FEATURED_SNIPPET_DESC[2]) {
|
||||
return $(selector).html()
|
||||
.replace(/<\/li>|<\/b>|<b>/g, '')
|
||||
.replace(/&/g, '&')
|
||||
.split('<li class="TrT0Xe">')
|
||||
.join('\n').trim();
|
||||
} else if (selector == Constants.SELECTORS.FEATURED_SNIPPET_DESC[2]) {
|
||||
return $(selector).text();
|
||||
}
|
||||
}).filter(text => text && text.length)[0];
|
||||
|
||||
this.title = featured_snippet_title || null;
|
||||
this.description = featured_snippet || null;
|
||||
this.url = featured_snippet_url || null;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = FeaturedSnippet;
|
171
node_modules/googlethis/lib/core/nodes/KnowledgeGraph.js
generated
vendored
Normal file
171
node_modules/googlethis/lib/core/nodes/KnowledgeGraph.js
generated
vendored
Normal file
|
@ -0,0 +1,171 @@
|
|||
'use strict';
|
||||
|
||||
const Utils = require('../../utils/utils');
|
||||
const Constants = require('../../utils/constants');
|
||||
|
||||
class MetadataItem {
|
||||
/** @type {string} */
|
||||
title;
|
||||
|
||||
/** @type {string} */
|
||||
value;
|
||||
|
||||
constructor (data) {
|
||||
this.title = data.title;
|
||||
this.value = data.value;
|
||||
}
|
||||
}
|
||||
|
||||
class Social {
|
||||
/** @type {string} */
|
||||
name;
|
||||
|
||||
/** @type {string} */
|
||||
url;
|
||||
|
||||
/** @type {string} */
|
||||
icon;
|
||||
|
||||
constructor (data) {
|
||||
this.name = data.name;
|
||||
this.url = data.url;
|
||||
this.icon = data.icon;
|
||||
}
|
||||
}
|
||||
|
||||
class KnowledgeGraph {
|
||||
/** @type {string | null} */
|
||||
type;
|
||||
|
||||
/** @type {string | null} */
|
||||
title;
|
||||
|
||||
/** @type {string | null} */
|
||||
description;
|
||||
|
||||
/** @type {string | null} */
|
||||
url;
|
||||
|
||||
/** @type {{ title: string; value: string }[]} */
|
||||
metadata = [];
|
||||
|
||||
/** @type {{ title: string; year: string; }[]} */
|
||||
books = [];
|
||||
|
||||
/** @type {{ title: string; year: string; }[]} */
|
||||
tv_shows_and_movies = [];
|
||||
|
||||
ratings = [];
|
||||
|
||||
/** @type {string[]} */
|
||||
available_on = [];
|
||||
|
||||
/** @type {{ url: string; source: string }[]} */
|
||||
images = [];
|
||||
|
||||
/** @type {{ title: string; album: string }[]} */
|
||||
songs = [];
|
||||
|
||||
/** @type {Social[]} */
|
||||
socials;
|
||||
|
||||
/** @type {string | null} */
|
||||
demonstration;
|
||||
|
||||
/** @type {string | null} */
|
||||
lyrics;
|
||||
|
||||
constructor (data, $) {
|
||||
this.title = $(Constants.SELECTORS.KNO_PANEL_TITLE[0]).first().text() || $(Constants.SELECTORS.KNO_PANEL_TITLE[1]).text() || null;
|
||||
this.description = $(Constants.SELECTORS.KNO_PANEL_DESCRIPTION).first().text() || null;
|
||||
this.url = $(Constants.SELECTORS.KNO_PANEL_URL).attr('href') || null;
|
||||
|
||||
// Extract metadata from the knowledge graph
|
||||
$(Constants.SELECTORS.KNO_PANEL_METADATA).each((_i, el) => {
|
||||
const key = $(el).first().text().trim().slice(0, -1);
|
||||
const value = $(el).next().text().trim();
|
||||
if (value.length) {
|
||||
this.metadata.push(new MetadataItem({ title: key, value: value.trim() }));
|
||||
}
|
||||
});
|
||||
|
||||
const knowledge_panel_type = $(Constants.SELECTORS.KNO_PANEL_TYPE).last().text();
|
||||
|
||||
if (knowledge_panel_type && knowledge_panel_type !== this.title) {
|
||||
this.type = knowledge_panel_type;
|
||||
} else {
|
||||
this.type = null;
|
||||
}
|
||||
|
||||
this.books = $(Constants.SELECTORS.KNO_PANEL_BOOKS).map((_i, el) => {
|
||||
const title = $(el).first().text().trim();
|
||||
const year = $(el).next().text().trim();
|
||||
|
||||
if (year.length)
|
||||
return { title, year }
|
||||
}).get();
|
||||
|
||||
this.tv_shows_and_movies = $(Constants.SELECTORS.KNO_PANEL_TV_SHOWS_AND_MOVIES).map((_i, el) => {
|
||||
const title = $(el).first().text().trim();
|
||||
const year = $(el).next().text().trim();
|
||||
|
||||
if (year.length)
|
||||
return { title, year };
|
||||
}).get();
|
||||
|
||||
const lyrics = $(Constants.SELECTORS.KNO_PANEL_SONG_LYRICS)
|
||||
.map((i, el) =>
|
||||
$($(el).html()
|
||||
.replace(/<br aria-hidden="true">/g, '\n')
|
||||
.replace(/<\/span><\/div><div jsname=".*" class=".*"><span jsname=".*">/g, '\n\n')
|
||||
.replace(/<br>/g, '\n')).text()).get();
|
||||
|
||||
this.lyrics = lyrics.length ? lyrics.join('\n\n') : null;
|
||||
|
||||
const google_users_rating = $(Constants.SELECTORS.KNO_PANEL_FILM_GOOGLEUSERS_RATING)[0];
|
||||
|
||||
if (google_users_rating) {
|
||||
const rating = $(google_users_rating.children[0].children[0]).text() || null;
|
||||
this.ratings.push({
|
||||
name: 'Google Users',
|
||||
rating: rating
|
||||
});
|
||||
}
|
||||
|
||||
$(Constants.SELECTORS.KNO_PANEL_FILM_RATINGS[0]).each((i, el) => {
|
||||
const name = $($(Constants.SELECTORS.KNO_PANEL_FILM_RATINGS[1])[i]).attr('title');
|
||||
const rating = $(el).text();
|
||||
|
||||
this.ratings.push({ name, rating });
|
||||
});
|
||||
|
||||
this.available_on = $(Constants.SELECTORS.KNO_PANEL_AVAILABLE_ON).map((_i, el) => $(el).text()).get();
|
||||
|
||||
this.images = $(Constants.SELECTORS.KNO_PANEL_IMAGES).map((_i, elem) => {
|
||||
const url = $(elem).attr('data-src');
|
||||
const source = $(elem).parent().parent().parent().parent().parent().attr('data-lpage');
|
||||
|
||||
return { url, source };
|
||||
}).get().filter((img) => img.url);
|
||||
|
||||
this.songs = $(Constants.SELECTORS.KNO_PANEL_SONGS).map((_i, el) => {
|
||||
const title = $(el).text().trim();
|
||||
const album = $(el).next().find('span').first().text().trim();
|
||||
|
||||
return { title, album };
|
||||
}).get();
|
||||
|
||||
this.socials = $(Constants.SELECTORS.KNO_PANEL_SOCIALS).map((_i, el) => {
|
||||
const name = $(el).text();
|
||||
const url = $(el).attr('href');
|
||||
const icon = $(el).find('img').attr('src');
|
||||
|
||||
return new Social({ name, url, icon });
|
||||
}).get();
|
||||
|
||||
const demo = Utils.getStringBetweenStrings(data, 'source src\\x3d\\x22', '.mp4');
|
||||
this.demonstration = demo ? `${demo}.mp4` : null;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = KnowledgeGraph;
|
28
node_modules/googlethis/lib/core/nodes/Location.js
generated
vendored
Normal file
28
node_modules/googlethis/lib/core/nodes/Location.js
generated
vendored
Normal file
|
@ -0,0 +1,28 @@
|
|||
'use strict';
|
||||
|
||||
const Constants = require('../../utils/constants');
|
||||
|
||||
class Location {
|
||||
/** @type {string | null} */
|
||||
title;
|
||||
|
||||
/** @type {string | null} */
|
||||
distance;
|
||||
|
||||
/** @type {string | null} */
|
||||
map;
|
||||
|
||||
constructor($) {
|
||||
const location_title = $(Constants.SELECTORS.LOCATION_TITLE).text();
|
||||
const location_distance = $(Constants.SELECTORS.LOCATION_DISTANCE).text();
|
||||
const location_image = $(Constants.SELECTORS.LOCATION_IMAGE).attr('src');
|
||||
|
||||
const is_available = location_title && location_distance;
|
||||
|
||||
this.title = is_available ? location_title : null;
|
||||
this.distance = is_available ? location_distance : null;
|
||||
this.map = is_available ? `https://google.com/${location_image}` : null;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Location;
|
146
node_modules/googlethis/lib/core/nodes/OrganicResults.js
generated
vendored
Normal file
146
node_modules/googlethis/lib/core/nodes/OrganicResults.js
generated
vendored
Normal file
|
@ -0,0 +1,146 @@
|
|||
'use strict';
|
||||
|
||||
const Constants = require('../../utils/constants');
|
||||
|
||||
class OrganicResult {
|
||||
/** @type {string} */
|
||||
title;
|
||||
|
||||
/** @type {string} */
|
||||
description;
|
||||
|
||||
/** @type {string} */
|
||||
url;
|
||||
|
||||
/** @type {boolean} */
|
||||
is_sponsored;
|
||||
|
||||
/** @type {{ high_res: string; low_res: string; }} */
|
||||
favicons;
|
||||
|
||||
constructor(data) {
|
||||
this.title = data.title;
|
||||
this.description = data.description;
|
||||
this.url = data.url;
|
||||
this.is_sponsored = data.is_sponsored;
|
||||
this.favicons = data.favicons;
|
||||
}
|
||||
}
|
||||
|
||||
class OrganicResults {
|
||||
/**
|
||||
* @returns {{
|
||||
* title: string;
|
||||
* description: string;
|
||||
* url: string;
|
||||
* is_sponsored: boolean;
|
||||
* favicons: {
|
||||
* high_res: string;
|
||||
* low_res: string;
|
||||
* }
|
||||
* }[]}
|
||||
*/
|
||||
static parse($, parse_ads = false, is_mobile = true) {
|
||||
// Stores advert indexes so we can identify them later
|
||||
const ad_indexes = [];
|
||||
|
||||
const titles = $(Constants.SELECTORS.TITLE)
|
||||
.map((_i, el) => {
|
||||
const is_ad =
|
||||
el.parent.attribs.style == '-webkit-line-clamp:2' ||
|
||||
(!is_mobile && el.parent.attribs.class.startsWith('vdQmEd'));
|
||||
|
||||
// Ignore ad titles if parse_ads is false
|
||||
if (!parse_ads && is_ad)
|
||||
return null;
|
||||
|
||||
return is_mobile ?
|
||||
$(el).text().trim() : $(el).find('h3').text().trim() || $(el).find('a > div > span').first().text().trim();
|
||||
}).get();
|
||||
|
||||
const descriptions = $(Constants.SELECTORS.DESCRIPTION)
|
||||
.map((_i, el) => {
|
||||
const is_ad = el.parent.attribs.class == 'w1C3Le' ||
|
||||
(!is_mobile && !Object.keys(el.parent.attribs).length);
|
||||
|
||||
// Ignore ad descriptions if parse_ads is false
|
||||
if (!parse_ads && is_ad) {
|
||||
return null;
|
||||
} else if (is_ad) {
|
||||
ad_indexes.push(_i);
|
||||
}
|
||||
|
||||
return $(el).text().trim();
|
||||
}).get();
|
||||
|
||||
const urls = $(is_mobile ? Constants.SELECTORS.URL : `${Constants.SELECTORS.TITLE} > a`)
|
||||
.map((_i, el) => {
|
||||
const is_ad = el.parent?.parent?.attribs?.class?.startsWith('vdQmEd');
|
||||
|
||||
/**
|
||||
* Since the selector for URLs is the same as the one for titles on desktop,
|
||||
* we need to check if the element is an ad. If we're parsing the mobile page,
|
||||
* then ads are simply stripped out of the results.
|
||||
*/
|
||||
if (!is_mobile && !parse_ads && is_ad) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $(el).attr('href');
|
||||
}).get();
|
||||
|
||||
// Refine results
|
||||
if (titles.length < urls.length && titles.length < descriptions.length) {
|
||||
urls.shift();
|
||||
}
|
||||
|
||||
if (urls.length > titles.length) {
|
||||
urls.shift();
|
||||
}
|
||||
|
||||
const is_innacurate_data = descriptions.length < urls.slice(1).length;
|
||||
|
||||
urls.forEach((item, index) => {
|
||||
// Why YouTube? Because video results usually don't have a description.
|
||||
if (item.includes('m.youtube.com') && is_innacurate_data) {
|
||||
urls.splice(index, 1);
|
||||
titles.splice(index, 1);
|
||||
index--;
|
||||
}
|
||||
});
|
||||
|
||||
const results = [];
|
||||
|
||||
for (let i = 0; i < titles.length; i++) {
|
||||
const title = titles[i];
|
||||
const description = descriptions[i];
|
||||
|
||||
let url = urls[i];
|
||||
|
||||
// Some results have a different URL format (AMP and ad results).
|
||||
if (url?.startsWith('/aclk') || url?.startsWith('/amp/s')) {
|
||||
url = `${Constants.URLS.W_GOOGLE}${url.substring(1)}`;
|
||||
}
|
||||
|
||||
const high_res_favicon = `${Constants.URLS.FAVICONKIT}/${new URL(url || Constants.URLS.W_GOOGLE).hostname}/192`;
|
||||
const low_res_favicon = `${Constants.URLS.W_GOOGLE}s2/favicons?sz=64&domain_url=${new URL(url || Constants.URLS.W_GOOGLE).hostname}`;
|
||||
|
||||
if (titles[i] && descriptions[i] && urls[i]) {
|
||||
results.push(new OrganicResult({
|
||||
title,
|
||||
description,
|
||||
url,
|
||||
is_sponsored: ad_indexes.includes(i),
|
||||
favicons: {
|
||||
high_res: high_res_favicon,
|
||||
low_res: low_res_favicon
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = OrganicResults;
|
28
node_modules/googlethis/lib/core/nodes/PAA.js
generated
vendored
Normal file
28
node_modules/googlethis/lib/core/nodes/PAA.js
generated
vendored
Normal file
|
@ -0,0 +1,28 @@
|
|||
'use strict';
|
||||
|
||||
const unraw = require('unraw').default;
|
||||
const Utils = require('../../utils/utils');
|
||||
const Constants = require('../../utils/constants');
|
||||
|
||||
class PAA {
|
||||
static parse($, data) {
|
||||
/** @type {string[]} */
|
||||
const items = [];
|
||||
|
||||
Constants.SELECTORS.PAA.forEach((item) =>
|
||||
$(item).each((i, el) => items.push($(el).text())));
|
||||
|
||||
items.shift();
|
||||
|
||||
const extra_data = JSON.parse(unraw(Utils.getStringBetweenStrings(data, 'var c=\'', '\';google') || '{}'));
|
||||
const rfs = extra_data?.sb_wiz?.rfs;
|
||||
|
||||
if (rfs) {
|
||||
rfs.forEach((el) => items.push(el.replace(/<b>|<\/b>/g, '')));
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = PAA;
|
33
node_modules/googlethis/lib/core/nodes/PAS.js
generated
vendored
Normal file
33
node_modules/googlethis/lib/core/nodes/PAS.js
generated
vendored
Normal file
|
@ -0,0 +1,33 @@
|
|||
'use strict';
|
||||
|
||||
const Constants = require('../../utils/constants');
|
||||
|
||||
class Query {
|
||||
/** @type {string} */
|
||||
title;
|
||||
|
||||
/** @type {string} */
|
||||
thumbnail;
|
||||
|
||||
constructor (data) {
|
||||
this.title = data.title;
|
||||
this.thumbnail = data.thumbnail;
|
||||
}
|
||||
}
|
||||
|
||||
class PAS {
|
||||
static parse($) {
|
||||
/** @type {{ title: string; thumbnail: string }[]} */
|
||||
const items = [];
|
||||
|
||||
$(Constants.SELECTORS.PASF).each((i, el) => {
|
||||
if ($(el).attr('data-src')) {
|
||||
items.push(new Query({ title: $(el).attr('alt'), thumbnail: `https:${$(el).attr('data-src')}` }));
|
||||
}
|
||||
});
|
||||
|
||||
return items;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = PAS;
|
21
node_modules/googlethis/lib/core/nodes/Time.js
generated
vendored
Normal file
21
node_modules/googlethis/lib/core/nodes/Time.js
generated
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
'use strict';
|
||||
|
||||
const Constants = require('../../utils/constants');
|
||||
|
||||
class Time {
|
||||
/** @type {string | null} */
|
||||
hours;
|
||||
|
||||
/** @type {string | null} */
|
||||
date;
|
||||
|
||||
constructor($) {
|
||||
const hours = $(Constants.SELECTORS.CURRENT_TIME_HOUR).first().text();
|
||||
const date = $(Constants.SELECTORS.CURRENT_TIME_DATE).map((i, el) => $(el).text()).get()[1];
|
||||
|
||||
this.hours = date ? hours.trim() : null;
|
||||
this.date = date ? date.trim() : null;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Time;
|
46
node_modules/googlethis/lib/core/nodes/TopStories.js
generated
vendored
Normal file
46
node_modules/googlethis/lib/core/nodes/TopStories.js
generated
vendored
Normal file
|
@ -0,0 +1,46 @@
|
|||
'use strict';
|
||||
|
||||
const Constants = require('../../utils/constants');
|
||||
|
||||
class Item {
|
||||
/** @type {string} */
|
||||
description;
|
||||
|
||||
/** @type {url} */
|
||||
url;
|
||||
|
||||
constructor(data) {
|
||||
this.description = data.description;
|
||||
this.url = data.url;
|
||||
}
|
||||
}
|
||||
|
||||
class TopStories {
|
||||
static parse($) {
|
||||
// Removes unwanted text from the description
|
||||
$(`${Constants.SELECTORS.TOP_STORIES_DESCRIPTION[0]} > div.CEMjEf`).each((el) => $(el).remove());
|
||||
$(`${Constants.SELECTORS.TOP_STORIES_DESCRIPTION[0]} > div > p`).each((el) => $(el).remove());
|
||||
|
||||
const top_stories_descriptions = Constants.SELECTORS.TOP_STORIES_DESCRIPTION.map((selector) =>
|
||||
$(selector).map((el) => $(el).text()).get()).filter((descs) => descs.length > 0)[0];
|
||||
const top_stories_urls = $(Constants.SELECTORS.TOP_STORIES_URL).map((el) => $(el).attr('href')).get();
|
||||
|
||||
/** @type {{
|
||||
description: string;
|
||||
url: string;
|
||||
}[]} */
|
||||
const items = [];
|
||||
|
||||
if (top_stories_descriptions) {
|
||||
for (let i = 0; i < top_stories_urls.length; i++) {
|
||||
items.push(new Item({
|
||||
description: top_stories_descriptions[i], url: top_stories_urls[i]
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = TopStories;
|
32
node_modules/googlethis/lib/core/nodes/Translation.js
generated
vendored
Normal file
32
node_modules/googlethis/lib/core/nodes/Translation.js
generated
vendored
Normal file
|
@ -0,0 +1,32 @@
|
|||
'use strict';
|
||||
|
||||
const Constants = require('../../utils/constants');
|
||||
|
||||
class Translation {
|
||||
/** @type {string | null} */
|
||||
source_language;
|
||||
|
||||
/** @type {string | null} */
|
||||
target_language;
|
||||
|
||||
/** @type {string | null} */
|
||||
source_text;
|
||||
|
||||
/** @type {string | null} */
|
||||
target_text;
|
||||
|
||||
constructor($) {
|
||||
const source_language = $(Constants.SELECTORS.TR_SOURCE_LANGUAGE).text();
|
||||
const target_language = $(Constants.SELECTORS.TR_TARGET_LANGUAGE).text();
|
||||
|
||||
const source_text = $(Constants.SELECTORS.TR_SOURCE_TEXT).text();
|
||||
const target_text = $(Constants.SELECTORS.TR_TARGET_TEXT).text();
|
||||
|
||||
this.source_language = source_text.length ? source_language : null;
|
||||
this.target_language = source_text.length ? target_language : null;
|
||||
this.source_text = source_text.length ? source_text : null;
|
||||
this.target_text = target_text.length ? target_text : null;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Translation;
|
61
node_modules/googlethis/lib/core/nodes/Videos.js
generated
vendored
Normal file
61
node_modules/googlethis/lib/core/nodes/Videos.js
generated
vendored
Normal file
|
@ -0,0 +1,61 @@
|
|||
'use strict';
|
||||
|
||||
const Constants = require('../../utils/constants');
|
||||
|
||||
class Video {
|
||||
/** @type {string} */
|
||||
id;
|
||||
|
||||
/** @type {string} */
|
||||
url;
|
||||
|
||||
/** @type {string} */
|
||||
title;
|
||||
|
||||
/** @type {string} */
|
||||
author;
|
||||
|
||||
/** @type {string} */
|
||||
duration;
|
||||
|
||||
constructor(data) {
|
||||
this.id = data.id;
|
||||
this.url = data.url;
|
||||
this.title = data.title;
|
||||
this.author = data.author;
|
||||
this.duration = data.duration;
|
||||
}
|
||||
}
|
||||
|
||||
class Videos {
|
||||
static parse($) {
|
||||
const data = $(Constants.SELECTORS.VIDEOS);
|
||||
|
||||
/**
|
||||
* @type {{
|
||||
* id: string;
|
||||
* url: string;
|
||||
* title: string;
|
||||
* author: string;
|
||||
* duration: string;
|
||||
* }[]}
|
||||
*/
|
||||
const videos = [];
|
||||
|
||||
for (const elem of data) {
|
||||
const id = $(elem).find('a').attr('href')?.split('v=')?.[1];
|
||||
const url = $(elem).find('a').attr('href');
|
||||
const title = $(elem).children().find('a > div > div').prev().text().trim();
|
||||
const author = $(elem).children().find('a > div > div > span').next().next().prev().text().replace(/·/g, '').trim();
|
||||
const duration = $(elem).children().find('div[role="presentation"]').first().text();
|
||||
|
||||
if (id && url && title && author && duration) {
|
||||
videos.push(new Video({ id, url, title, author, duration }));
|
||||
}
|
||||
}
|
||||
|
||||
return videos;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Videos;
|
43
node_modules/googlethis/lib/core/nodes/Weather.js
generated
vendored
Normal file
43
node_modules/googlethis/lib/core/nodes/Weather.js
generated
vendored
Normal file
|
@ -0,0 +1,43 @@
|
|||
'use strict';
|
||||
|
||||
const Constants = require('../../utils/constants');
|
||||
|
||||
class Weather {
|
||||
/** @type {string | null} */
|
||||
location;
|
||||
|
||||
/** @type {string | null} */
|
||||
forecast;
|
||||
|
||||
/** @type {string | null} */
|
||||
precipitation;
|
||||
|
||||
/** @type {string | null} */
|
||||
humidity;
|
||||
|
||||
/** @type {string | null} */
|
||||
temperature;
|
||||
|
||||
/** @type {string | null} */
|
||||
wind;
|
||||
|
||||
constructor($) {
|
||||
const weather_location = $(Constants.SELECTORS.WEATHER_LOCATION).text();
|
||||
const weather_forecast = $(Constants.SELECTORS.WEATHER_FORECAST).text();
|
||||
const precipitation = $(Constants.SELECTORS.PRECIPITATION).text();
|
||||
const air_humidity = $(Constants.SELECTORS.AIR_HUMIDITY).text();
|
||||
const temperature = $(Constants.SELECTORS.TEMPERATURE).text();
|
||||
const wind_speed = $(Constants.SELECTORS.WIND_SPEED).text();
|
||||
|
||||
const is_available = weather_location && weather_forecast;
|
||||
|
||||
this.location = is_available ? weather_location : null;
|
||||
this.forecast = is_available ? weather_forecast : null;
|
||||
this.precipitation = is_available ? precipitation : null;
|
||||
this.humidity = is_available ? air_humidity : null;
|
||||
this.temperature = is_available ? temperature : null;
|
||||
this.wind = is_available ? wind_speed : null;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Weather;
|
Loading…
Add table
Add a link
Reference in a new issue