Comparing version 0.0.4 to 0.0.6
{ | ||
"name": "iyoutube", | ||
"version": "0.0.4", | ||
"version": "0.0.6", | ||
"description": "The ultimate unofficial YouTube API Client for Javascript", | ||
"main": "src/main.ts", | ||
"main": "output/main.js", | ||
"types": "output/main.d.ts", | ||
"scripts": { | ||
"test": "npx nodemon test/main.ts --ignore *.json" | ||
"test": "npm run compile && node test/test.js", | ||
"compile": "tsc", | ||
"publish": "npm version patch -m 'Fix' && npm publish --access=public ./ && git push" | ||
}, | ||
@@ -14,3 +17,4 @@ "keywords": [], | ||
"node-fetch": "^2.6.7", | ||
"ts-node": "^10.7.0" | ||
"ts-node": "^10.7.0", | ||
"typescript": "^4.6.3" | ||
}, | ||
@@ -24,2 +28,2 @@ "devDependencies": { | ||
} | ||
} | ||
} |
import { HTTPRequestMethod } from "../interfaces/HTTPClient"; | ||
import { WrappedHTTPClient } from "../WrappedHTTPClient"; | ||
import fs from 'fs'; | ||
import helpers from "./helpers"; | ||
import { Video } from "../interfaces/Video"; | ||
import IYoutubeClient from "../main"; | ||
import IYoutube from "../IYoutube"; | ||
import { ENDPOINT_BROWSE } from "../constants"; | ||
@@ -11,5 +10,5 @@ | ||
httpclient: WrappedHTTPClient; | ||
client: IYoutubeClient; | ||
client: IYoutube; | ||
constructor(httpclient : WrappedHTTPClient, client: IYoutubeClient) { | ||
constructor(httpclient : WrappedHTTPClient, client: IYoutube) { | ||
this.httpclient = httpclient; | ||
@@ -20,2 +19,3 @@ this.client = client; | ||
async getPopularVideos():Promise<Array<Video>> { | ||
this.client.throwErrorIfNotReady(); | ||
const res = await this.httpclient.request({ | ||
@@ -31,6 +31,4 @@ method: HTTPRequestMethod.POST, | ||
}); | ||
const resJSON = await JSON.parse(res.data); | ||
fs.writeFileSync("tempres.json", JSON.stringify(resJSON, null, 2)); | ||
const popularShelf = helpers.recursiveSearchForKey("expandedShelfContentsRenderer", resJSON)[0]; | ||
@@ -43,2 +41,3 @@ let items = popularShelf.items; | ||
async getTrendsNow():Promise<Array<Video>> { | ||
this.client.throwErrorIfNotReady(); | ||
const res = await this.httpclient.request({ | ||
@@ -45,0 +44,0 @@ method: HTTPRequestMethod.POST, |
@@ -5,3 +5,3 @@ import { Channel } from "diagnostics_channel"; | ||
import { Playlist } from "../interfaces/Playlist"; | ||
import IYoutubeClient from "../main"; | ||
import IYoutube from "../IYoutube"; | ||
import { WrappedHTTPClient } from "../WrappedHTTPClient"; | ||
@@ -14,5 +14,5 @@ import helpers from "./helpers"; | ||
httpclient: WrappedHTTPClient; | ||
client : IYoutubeClient; | ||
client : IYoutube; | ||
constructor(httpclient : WrappedHTTPClient, client: IYoutubeClient) { | ||
constructor(httpclient : WrappedHTTPClient, client: IYoutube) { | ||
this.httpclient = httpclient; | ||
@@ -23,2 +23,3 @@ this.client = client; | ||
async getPlaylists():Promise<Array<Playlist>> { | ||
this.client.throwErrorIfNotReady(); | ||
const res = await this.httpclient.request({ | ||
@@ -54,2 +55,3 @@ method: HTTPRequestMethod.POST, | ||
async getSubscriptions():Promise<Array<Channel>> { | ||
this.client.throwErrorIfNotReady(); | ||
const res = await this.httpclient.request({ | ||
@@ -70,4 +72,5 @@ method: HTTPRequestMethod.POST, | ||
getSubscriptionFeed():ContinuatedList { | ||
this.client.throwErrorIfNotReady(); | ||
return new SubscriptionFeedContinuatedList(this.httpclient); | ||
} | ||
} |
@@ -1,70 +0,36 @@ | ||
import { Authenticator } from "./Authenticator"; | ||
import { HTTPClient } from "./interfaces/HTTPClient"; | ||
import { StorageAdapter } from "./interfaces/StorageAdapter"; | ||
import { WrappedHTTPClient } from "./WrappedHTTPClient"; | ||
import { SearchConitinuatedList, SearchType } from "./fetchers/SearchContinuatedList"; | ||
import { NodeFetchClientAdapter } from "./adapters/NodeFetchClientAdapter"; | ||
import { NodeFSStorageAdapater } from "./adapters/NodeFSStorageAdapter"; | ||
import { Explorer } from "./fetchers/Explorer"; | ||
import { ContinuatedList } from "./fetchers/ContinuatedList"; | ||
import { User } from "./fetchers/User"; | ||
import { Authenticator } from "./Authenticator"; | ||
import { Channel } from "./interfaces/Channel"; | ||
import { Video } from "./interfaces/Video"; | ||
import { Playlist } from "./interfaces/Playlist"; | ||
import { DEBUG } from "./constants"; | ||
import { Thumbnail } from "./interfaces/Thumbnail"; | ||
import { ChannelBadge } from "./interfaces/ChannelBadge"; | ||
import { HTTPClient } from "./interfaces/HTTPClient"; | ||
import { StorageAdapter } from "./interfaces/StorageAdapter"; | ||
import { default as IYoutube } from "./Iyoutube"; | ||
export default class IYoutube { | ||
rawHttpClient: HTTPClient; | ||
wrappedHttpClient: WrappedHTTPClient; | ||
export { IYoutube as IYoutube } | ||
export { NodeFSStorageAdapater as NodeFSStorageAdapater } | ||
export { NodeFetchClientAdapter as NodeFetchClientAdapter } | ||
export { HTTPClient as HTTPClient } | ||
export { StorageAdapter as StorageAdapter }; | ||
storageAdapter : StorageAdapter; | ||
authenticator: Authenticator; | ||
export { Explorer as Explorer } | ||
export { User as User } | ||
export { ContinuatedList as ContinuatedList } | ||
#explorer : Explorer; | ||
#user : User; | ||
export { Authenticator as Authenticator } | ||
export { Channel as Channel } | ||
export { Video as Video } | ||
export { Playlist as Playlist } | ||
export { Thumbnail as Thumbnail } | ||
export { ChannelBadge as ChannelBadge } | ||
constructor(httpClient : HTTPClient, storageAdapater : StorageAdapter) { | ||
this.rawHttpClient = httpClient; | ||
this.wrappedHttpClient = new WrappedHTTPClient(this.rawHttpClient); | ||
this.storageAdapter = storageAdapater; | ||
this.authenticator = new Authenticator(this.rawHttpClient, this.storageAdapter); | ||
this.wrappedHttpClient.authorizationHeaderCallback = () => { return this.authenticator.getAuthorizationHeader() }; | ||
this.#explorer = new Explorer(this.wrappedHttpClient, this); | ||
this.#user = new User(this.wrappedHttpClient, this); | ||
} | ||
async init() { | ||
if(DEBUG) console.log(""); | ||
await this.authenticator.init(); | ||
} | ||
async search(term: string, type : SearchType):Promise<ContinuatedList> { | ||
this.#throwErrorIfNotReady(); | ||
var list = new SearchConitinuatedList(term, type, this.wrappedHttpClient); | ||
return list; | ||
} | ||
async getPlaylist(playlistId: string):Promise<Playlist> { | ||
this.#throwErrorIfNotReady(); | ||
var pl = new Playlist(this.wrappedHttpClient); | ||
pl.playlistId = playlistId; | ||
await pl.loadAll(); | ||
return pl; | ||
} | ||
getExplorer():Explorer { | ||
this.#throwErrorIfNotReady(); | ||
return this.#explorer; | ||
} | ||
getUser():User { | ||
this.#throwErrorIfNotReady(); | ||
return this.#user; | ||
} | ||
#throwErrorIfNotReady(){ | ||
if(!this.storageAdapter) throw new Error("The provided Storage Adapter was invalid"); | ||
if(!this.rawHttpClient) throw new Error("The provided HTTP Client was invalid"); | ||
if(this.authenticator.requiresLogin()) throw new Error("This Instance of IYoutube is not authenticated"); | ||
} | ||
} | ||
//Default Export for most NodeJS | ||
import * as path from 'path'; | ||
export const nodeInst = new IYoutube(new NodeFetchClientAdapter() , new NodeFSStorageAdapater(path.resolve(__dirname, "../datastorage"))); |
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
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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
144744
68
2898
3
1
1
+ Addedtypescript@^4.6.3
+ Added@types/node@22.9.1(transitive)
+ Addedtypescript@4.9.5(transitive)
- Removed@types/node@22.9.3(transitive)
- Removedtypescript@5.7.2(transitive)