mirror of
https://github.com/LuanRT/YouTube.js.git
synced 2026-06-24 07:11:48 +00:00
* feat(utils): Add logger * chore: Clean up some classes and add more logging * chore: Fix conflicts
34 lines
1.1 KiB
TypeScript
34 lines
1.1 KiB
TypeScript
import { Parser } from '../index.js';
|
|
import ItemSection from '../classes/ItemSection.js';
|
|
import SectionList from '../classes/SectionList.js';
|
|
import SingleColumnBrowseResults from '../classes/SingleColumnBrowseResults.js';
|
|
|
|
import { InnertubeError } from '../../utils/Utils.js';
|
|
import type { ApiResponse } from '../../core/index.js';
|
|
import type { ObservedArray } from '../helpers.js';
|
|
import type { IBrowseResponse } from '../types/index.js';
|
|
|
|
class TimeWatched {
|
|
#page: IBrowseResponse;
|
|
contents?: ObservedArray<ItemSection>;
|
|
|
|
constructor(response: ApiResponse) {
|
|
this.#page = Parser.parseResponse<IBrowseResponse>(response.data);
|
|
|
|
if (!this.#page.contents)
|
|
throw new InnertubeError('Page contents not found');
|
|
|
|
const tab = this.#page.contents.item().as(SingleColumnBrowseResults).tabs.get({ selected: true });
|
|
|
|
if (!tab)
|
|
throw new InnertubeError('Could not find target tab.');
|
|
|
|
this.contents = tab.content?.as(SectionList).contents.as(ItemSection);
|
|
}
|
|
|
|
get page(): IBrowseResponse {
|
|
return this.#page;
|
|
}
|
|
}
|
|
|
|
export default TimeWatched; |