Skip to content

Commit

Permalink
feat: youtube data fetcher - more conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
Venipa committed Apr 18, 2024
1 parent 875d5f5 commit 687479f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ytmdesktop2",
"version": "0.12.6",
"version": "0.12.7",
"private": false,
"author": "Venipa <admin@venipa.net>",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions src/app/plugins/client/track-info-watcher.plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ export const meta = {
}

export const afterInit = () => {
const videoDataChangeLoadedType = ["dataupdated", "dataloaded"]
const videoDataChangeLoadedType = ["dataupdated", "dataloaded", "newdata"]
window.domUtils.ensureDomLoaded(() => {
const playerApi = window.domUtils.playerApi();
playerApi.addEventListener("onVideoDataChange", ev => {
console.log("onVideoDataChange", ev);
if (ev.playertype !== 1 || !videoDataChangeLoadedType.includes(ev.type)) return;
const videoData = playerApi.getPlayerResponse();
if (!videoData) return; // check if newdata has fetched
const requestData = { video: videoData.videoDetails, context: videoData.microformat && videoData.microformat.microformatDataRenderer || null };
console.log("requestData", requestData);
window.ipcRenderer.emit("track:info-req", requestData);
})
})
Expand Down
5 changes: 3 additions & 2 deletions src/app/plugins/trackProvider.plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export default class TrackProvider extends BaseProvider implements AfterInit {

@IpcOn("track:info-req")
private async __onTrackInfo(ev, ytTrack: TrackData) {
this.log("info-req", ytTrack);
if (!ytTrack.video) return;
const track = {
...ytTrack,
Expand All @@ -103,7 +104,7 @@ export default class TrackProvider extends BaseProvider implements AfterInit {
duration: parseTrackDuration(ytTrack)
}
};
trackCollection.addOrUpdate(ytTrack.video.videoId, ytTrack);
trackCollection.addOrUpdate(ytTrack.video.videoId, track);

if (
track.video.videoId === this._activeTrackId ||
Expand Down Expand Up @@ -147,7 +148,7 @@ export default class TrackProvider extends BaseProvider implements AfterInit {
private async __onActiveTrack(trackId: string) {
if (this._activeTrackId === trackId) return;

this.logger.debug(`active track:`, trackId);
this.log(`active track:`, trackId);
this._activeTrackId = trackId;
if (this.trackData) {
const td = this.trackData;
Expand Down
4 changes: 4 additions & 0 deletions src/app/utils/baseProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { App } from "electron";
import { BrowserView } from "electron/main";
import { Logger } from "winston";
import { BaseProviderNames } from "ytmd";
import { stringifyJson } from "../lib/json";
import { BrowserWindowViews } from "./mappedWindow";

export interface BeforeStart {
Expand Down Expand Up @@ -31,6 +32,9 @@ export class BaseProvider {
get logger() {
return this._loggerInstance;
}
log(...args: any) {
return this._loggerInstance.debug(stringifyJson([...args]));
}
get views() {
return this._views.views;
}
Expand Down

0 comments on commit 687479f

Please sign in to comment.