youtubei.js
Advanced tools
Comparing version 1.4.2-d.3 to 1.4.2-d.4
@@ -167,3 +167,3 @@ 'use strict'; | ||
if (!args.is_ytm) { | ||
data.params = Proto.encodeSearchFilter(args.options.period, args.options.duration, args.options.order); | ||
data.params = Proto.encodeSearchFilter(args.options.filters); | ||
} | ||
@@ -170,0 +170,0 @@ } else { |
@@ -438,7 +438,9 @@ 'use strict'; | ||
* @param {string} query - search query. | ||
* @param {object} options - search options. | ||
* @param {string} options.client - client used to perform the search, can be: `YTMUSIC` or `YOUTUBE`. | ||
* @param {string} options.order - filter results by order, can be: relevance | rating | age | views | ||
* @param {string} options.period - filter videos uploaded within a period, can be: any | hour | day | week | month | year | ||
* @param {string} options.duration - filter video results by duration, can be: any | short | long | ||
* @param {object} [options] - search options. | ||
* @param {string} [options.client] - client used to perform the search, can be: `YTMUSIC` or `YOUTUBE`. | ||
* @param {object} [options.filters] - search filters. | ||
* @param {string} [options.filters.upload_date] - filter videos by upload date, can be: any | last_hour | today | this_week | this_month | this_year | ||
* @param {string} [options.filters.type] - filter results by type, can be: any | video | channel | playlist | movie | ||
* @param {string} [options.filters.duration] - filter videos by duration, can be: any | short | medium | long | ||
* @param {string} [options.filters.sort_by] - filter video results by order, can be: relevance | rating | upload_date | view_count | ||
* | ||
@@ -448,11 +450,10 @@ * @returns {Promise.<{ query: string; corrected_query: string; estimated_results: number; videos: [] } | | ||
*/ | ||
async search(query, options) { | ||
async search(query, options = { client: 'YOUTUBE' }) { | ||
Utils.throwIfMissing({ query }); | ||
const final_options = Object.assign({ client: 'YOUTUBE', period: 'any', duration: 'any', order: 'relevance' }, options); | ||
const response = await this.actions.search({ query, options: final_options, is_ytm: final_options.client == 'YTMUSIC' }); | ||
const response = await this.actions.search({ query, options, is_ytm: options.client == 'YTMUSIC' }); | ||
const results = new Parser(this, response.data, { | ||
query, | ||
client: final_options.client, | ||
client: options.client, | ||
data_type: 'SEARCH' | ||
@@ -633,3 +634,3 @@ }).parse(); | ||
async getSubscriptionsFeed() { | ||
const response = this.actions.browse('FEsubscriptions'); | ||
const response = await this.actions.browse('FEsubscriptions'); | ||
@@ -636,0 +637,0 @@ const subsfeed = new Parser(this, response, { |
@@ -22,6 +22,7 @@ 'use strict'; | ||
* | ||
* @param {string} period | ||
* @param {string} duration | ||
* @param {string} order | ||
* | ||
* @param {object} filters | ||
* @param {string} [filters.upload_date] - any | last_hour | today | this_week | this_month | this_year | ||
* @param {string} [filters.type] - any | video | channel | playlist | movie | ||
* @param {string} [filters.duration] - any | short | medium | long | ||
* @param {string} [filters.sort_by] - relevance | rating | upload_date | view_count | ||
* @todo implement remaining filters. | ||
@@ -31,16 +32,61 @@ * | ||
*/ | ||
static encodeSearchFilter(period, duration, order) { | ||
const periods = { 'any': null, 'hour': 1, 'day': 2, 'week': 3, 'month': 4, 'year': 5 }; | ||
const durations = { 'any': null, 'short': 1, 'long': 2 }; | ||
const orders = { 'relevance': null, 'rating': 1, 'age': 2, 'views': 3 }; | ||
static encodeSearchFilter(filters) { | ||
const upload_dates = { | ||
'any': null, | ||
'last_hour': 1, | ||
'today': 2, | ||
'this_week': 3, | ||
'this_month': 4, | ||
'this_year': 5 | ||
}; | ||
const buf = messages.SearchFilter.encode({ | ||
number: orders[order], | ||
filter: { | ||
param_0: periods[period], | ||
param_1: (period == 'hour' && order == 'relevance') ? null : 1, | ||
param_2: durations[duration] | ||
const types = { | ||
'any': null, | ||
'video': 1, | ||
'channel': 2, | ||
'playlist': 3, | ||
'movie': 4 | ||
}; | ||
const durations = { | ||
'any': null, | ||
'short': 1, | ||
'medium': 2, | ||
'long': 3 | ||
}; | ||
const orders = { | ||
'relevance': null, | ||
'rating': 1, | ||
'upload_date': 2, | ||
'view_count': 3 | ||
}; | ||
const data = {}; | ||
filters && | ||
(data.filters = {}) || | ||
(data.no_filter = 0); | ||
if (filters) { | ||
if (filters.upload_date) { | ||
if (!['video', 'movie'].includes(filters.type)) | ||
throw new Error('Cannot use upload date filter with type ' + filters.type); | ||
} | ||
}); | ||
filters.upload_date && | ||
(data.filters.param_0 = upload_dates[filters.upload_date]); | ||
filters.type && | ||
(data.filters.param_1 = types[filters.type]); | ||
filters.duration && | ||
(data.filters.param_2 = durations[filters.duration]); | ||
filters.sort_by && | ||
(filters.sort_by !== 'relevance') && | ||
(data.filter = orders[filters.sort_by]); | ||
} | ||
const buf = messages.SearchFilter.encode(data); | ||
return encodeURIComponent(Buffer.from(buf).toString('base64')); | ||
@@ -47,0 +93,0 @@ } |
{ | ||
"name": "youtubei.js", | ||
"version": "1.4.2-d.3", | ||
"version": "1.4.2-d.4", | ||
"description": "A full-featured library that allows you to get detailed info about any video, subscribe, unsubscribe, like, dislike, comment, search, download videos/music and much more!", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
301110
7572