Fix #44, additional minor enhncements
This commit is contained in:
@ -37,6 +37,7 @@ import sharp from 'sharp';
|
||||
import { URL, URLSearchParams } from 'url';
|
||||
import { WebSocket } from 'ws';
|
||||
import type { PlaylistAdder } from './playlist/playlistAdder';
|
||||
import { TidalPlaylistAdder } from './playlist/tidalPlaylistAdder';
|
||||
|
||||
const URL_REGEX = new RegExp(/href="(?<postUrl>[^>]+?)" target="_blank"/gm);
|
||||
const INVIDIOUS_REGEX = new RegExp(/invidious.*?watch.*?v=(?<videoId>[a-zA-Z_0-9-]+)/gm);
|
||||
@ -176,22 +177,24 @@ export class TimelineReader {
|
||||
}
|
||||
const isMusic = await this.isMusicVideo(youtubeId);
|
||||
if (!isMusic) {
|
||||
this.logger.debug('Probably not a music video', youtubeId, url);
|
||||
this.logger.debug('Probably not a music video', youtubeId);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
const spotify: Platform = 'spotify';
|
||||
const tidal: Platform = 'tidal';
|
||||
const tidalId = odesliInfo.linksByPlatform[tidal]?.entityUniqueId;
|
||||
const tidalUri = tidalId ? odesliInfo.entitiesByUniqueId[tidalId].id : undefined;
|
||||
|
||||
const songInfo = {
|
||||
...info,
|
||||
pageUrl: odesliInfo.pageUrl,
|
||||
youtubeUrl: odesliInfo.linksByPlatform[platform]?.url,
|
||||
spotifyUrl: odesliInfo.linksByPlatform[spotify]?.url,
|
||||
spotifyUri: odesliInfo.linksByPlatform[spotify]?.nativeAppUriDesktop,
|
||||
tidalUri: tidalUri,
|
||||
postedUrl: url.toString()
|
||||
} as SongInfo;
|
||||
if (songInfo.youtubeUrl && !songInfo.spotifyUrl) {
|
||||
this.logger.warn('SongInfo with YT, but no spotify URL', odesliInfo);
|
||||
}
|
||||
return songInfo;
|
||||
} catch (e) {
|
||||
if (e instanceof Error && e.cause === 429) {
|
||||
@ -374,11 +377,11 @@ export class TimelineReader {
|
||||
}
|
||||
|
||||
private async checkAndSavePost(post: Post) {
|
||||
const isIgnored = this.ignoredUsers.includes(post.account.username);
|
||||
const isIgnored = this.ignoredUsers.includes(post.account.acct);
|
||||
if (isIgnored) {
|
||||
this.logger.info(
|
||||
'Ignoring post by ignored user',
|
||||
post.account.username,
|
||||
post.account.acct,
|
||||
'is ignored',
|
||||
this.ignoredUsers,
|
||||
isIgnored
|
||||
@ -419,11 +422,42 @@ export class TimelineReader {
|
||||
const socket = new WebSocket(
|
||||
`wss://${MASTODON_INSTANCE}/api/v1/streaming?type=subscribe&stream=public:local&access_token=${MASTODON_ACCESS_TOKEN}`
|
||||
);
|
||||
|
||||
// Sometimes, the app just stops receiving WS updates.
|
||||
// Regularly check if it is necessary to reset it
|
||||
const wsTimeout = 5;
|
||||
let timeoutId = setTimeout(
|
||||
() => {
|
||||
socketLogger.warn(
|
||||
'Websocket has not received a new post in',
|
||||
wsTimeout,
|
||||
'hours. Resetting, it might be stuck'
|
||||
);
|
||||
socket.close();
|
||||
this.startWebsocket();
|
||||
},
|
||||
1000 * 60 * 60 * wsTimeout
|
||||
); // 5 hours
|
||||
socket.onopen = () => {
|
||||
socketLogger.log('Connected to WS');
|
||||
};
|
||||
socket.onmessage = async (event) => {
|
||||
try {
|
||||
// Reset timer
|
||||
clearTimeout(timeoutId);
|
||||
timeoutId = setTimeout(
|
||||
() => {
|
||||
socketLogger.warn(
|
||||
'Websocket has not received a new post in',
|
||||
wsTimeout,
|
||||
'hours. Resetting, it might be stuck'
|
||||
);
|
||||
socket.close();
|
||||
this.startWebsocket();
|
||||
},
|
||||
1000 * 60 * 60 * wsTimeout
|
||||
);
|
||||
|
||||
const data: TimelineEvent = JSON.parse(event.data.toString());
|
||||
socketLogger.debug('ES event', data.event);
|
||||
if (data.event !== 'update') {
|
||||
@ -493,9 +527,13 @@ export class TimelineReader {
|
||||
private constructor() {
|
||||
this.logger = new Logger('Timeline');
|
||||
this.logger.log('Constructing timeline object');
|
||||
this.playlistAdders = [new YoutubePlaylistAdder(), new SpotifyPlaylistAdder()];
|
||||
this.playlistAdders = [
|
||||
new YoutubePlaylistAdder(),
|
||||
new SpotifyPlaylistAdder(),
|
||||
new TidalPlaylistAdder()
|
||||
];
|
||||
this.ignoredUsers =
|
||||
IGNORE_USERS === undefined
|
||||
IGNORE_USERS === undefined || IGNORE_USERS === 'CHANGE_ME' || !!IGNORE_USERS
|
||||
? []
|
||||
: IGNORE_USERS.split(',')
|
||||
.map((u) => (u.startsWith('@') ? u.substring(1) : u))
|
||||
|
Reference in New Issue
Block a user