New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ionic-youtube-search

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ionic-youtube-search - npm Package Compare versions

Comparing version 1.0.3 to 1.0.4

lib/lib/parser.service.d.ts

22

lib/index.d.ts
export declare const Name: (name: string) => string;
export declare function search(searchQuery: string): Promise<{
export declare function search(searchQuery: string): Promise<({
id: {
videoId: any;
};
url: string;
title: any;
description: any;
duration_raw: any;
snippet: {
url: string;
duration: any;
publishedAt: any;
thumbnails: {
id: any;
url: any;
default: any;
high: any;
height: any;
width: any;
};
duration: any;
title: any;
views: any;
};
}[]>;
thumbnail: {
id: any;
url: any;
height: any;
width: any;
};
uploadedAt: any;
views: any;
} | undefined)[]>;

@@ -1,16 +0,32 @@

export declare function searchVideo(searchString: string): Promise<{
export declare function searchVideo(searchString: string): Promise<({
id: {
videoId: any;
};
url: string;
title: any;
description: any;
duration_raw: any;
snippet: {
url: string;
duration: any;
publishedAt: any;
thumbnails: {
id: any;
url: any;
default: any;
high: any;
height: any;
width: any;
};
duration: any;
title: any;
views: any;
};
}[]>;
thumbnail: {
id: any;
url: any;
height: any;
width: any;
};
uploadedAt: any;
views: any;
} | undefined)[]>;

102

lib/lib/search.js

@@ -40,57 +40,73 @@ "use strict";

var ngx_1 = require("@ionic-native/http/ngx");
var parser_service_1 = require("./parser.service");
function searchVideo(searchString) {
return __awaiter(this, void 0, void 0, function () {
var httpClient, YOUTUBE_URL, searchRes, searchValue, pattern, matches, content, contentJson, contentObject, videos, _i, _a, result, videoId, url, duration, thumbnailURLs, publishedAt, title, views;
return __generator(this, function (_b) {
switch (_b.label) {
var httpClient, YOUTUBE_URL, results, details, fetched, options, searchRes, html, data, i, data, res, parserService, parsed;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
httpClient = new ngx_1.HTTP();
YOUTUBE_URL = 'https://www.youtube.com';
return [4 /*yield*/, httpClient.get(encodeURI(YOUTUBE_URL + "/results?search_query=" + searchString + "&sp=EgIQAQ%253D%253D"), {}, {})];
results = [];
details = [];
fetched = false;
options = { type: "video", limit: 0 };
return [4 /*yield*/, httpClient.get(YOUTUBE_URL + "/results?q=" + encodeURI(searchString.trim()) + "&hl=en", {}, {})];
case 1:
searchRes = _b.sent();
searchRes = _a.sent();
return [4 /*yield*/, searchRes.data];
case 2:
searchValue = _b.sent();
pattern = new RegExp('initial-data"><!-- {.*--></div><script >');
matches = searchValue.match(pattern);
content = matches[0];
content = content.replace('initial-data"><!-- ', '');
content = content.replace('--></div><script >', '');
contentJson = JSON.parse(content);
contentObject = contentJson.contents.sectionListRenderer.contents.filter(function (listing) { return listing.itemSectionRenderer !== undefined; });
videos = [];
for (_i = 0, _a = contentObject[0].itemSectionRenderer.contents; _i < _a.length; _i++) {
result = _a[_i];
html = _a.sent();
// try to parse html
try {
data = html.split("ytInitialData")[1].split("');</script>")[0];
html = data.replace(/\\x([0-9A-F]{2})/ig, function () {
var items = [];
for (var _i = 0; _i < arguments.length; _i++) {
items[_i] = arguments[_i];
}
return String.fromCharCode(parseInt(items[1], 16));
});
}
catch (e) { /* do nothing */ }
try {
details = JSON.parse(html.split('{"itemSectionRenderer":{"contents":')[html.split('{"itemSectionRenderer":{"contents":').length - 1].split(',"continuations":[{')[0]);
fetched = true;
}
catch (e) { /* do nothing */ }
if (!fetched) {
try {
if (result.compactVideoRenderer !== undefined) {
result = result.compactVideoRenderer;
videoId = result.videoId;
url = YOUTUBE_URL + '/watch?v=' + videoId;
duration = result.lengthText;
thumbnailURLs = result.thumbnail.thumbnails;
publishedAt = result.publishedTimeText.runs[0].text;
title = result.title.runs[0].text;
views = result.viewCountText;
videos.push({
id: {
videoId: videoId
},
snippet: {
url: url,
publishedAt: publishedAt,
thumbnails: { default: thumbnailURLs[0], high: thumbnailURLs[thumbnailURLs.length - 1] },
duration: duration,
title: title,
views: views,
}
});
}
details = JSON.parse(html.split('{"itemSectionRenderer":')[html.split('{"itemSectionRenderer":').length - 1].split('},{"continuationItemRenderer":{')[0]).contents;
fetched = true;
}
catch (error) {
// tslint:disable-next-line:no-console
console.log(error);
catch (e) { /* do nothing */ }
}
if (!fetched)
return [2 /*return*/, []];
// tslint:disable-next-line:prefer-for-of
for (i = 0; i < details.length; i++) {
if (typeof options.limit === "number" && options.limit > 0 && results.length >= options.limit)
break;
data = details[i];
res = void 0;
if (options.type === "all") {
if (!!data.videoRenderer)
options.type = "video";
else if (!!data.channelRenderer)
options.type = "channel";
else if (!!data.playlistRenderer)
options.type = "playlist";
else
continue;
}
if (options.type === "video") {
parserService = new parser_service_1.ParserService();
parsed = parserService.parseVideo(data);
if (!parsed)
continue;
res = parsed;
}
results.push(res);
}
return [2 /*return*/, videos];
return [2 /*return*/, results];
}

@@ -97,0 +113,0 @@ });

{
"name": "ionic-youtube-search",
"version": "1.0.3",
"version": "1.0.4",
"description": "Search videos on YouTube without API key in ionic apps",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc