mirror of
https://github.com/BluemediaDev/muse.git
synced 2025-04-19 21:03:56 +02:00
Fix caching bug
This commit is contained in:
parent
7703506aae
commit
7fcd9a6a7d
4 changed files with 14 additions and 31 deletions
|
@ -7,7 +7,6 @@ import Command from './commands';
|
||||||
import debug from './utils/debug';
|
import debug from './utils/debug';
|
||||||
import NaturalLanguage from './services/natural-language-commands';
|
import NaturalLanguage from './services/natural-language-commands';
|
||||||
import handleGuildCreate from './events/guild-create';
|
import handleGuildCreate from './events/guild-create';
|
||||||
import handleTypingStart from './events/handle-typing-start';
|
|
||||||
import handleVoiceStateUpdate from './events/voice-state-update';
|
import handleVoiceStateUpdate from './events/voice-state-update';
|
||||||
import errorMsg from './utils/error-msg';
|
import errorMsg from './utils/error-msg';
|
||||||
import {isUserInVoice} from './utils/channels';
|
import {isUserInVoice} from './utils/channels';
|
||||||
|
@ -105,7 +104,6 @@ export default class {
|
||||||
|
|
||||||
// Register event handlers
|
// Register event handlers
|
||||||
this.client.on('guildCreate', handleGuildCreate);
|
this.client.on('guildCreate', handleGuildCreate);
|
||||||
this.client.on('typingStart', handleTypingStart);
|
|
||||||
this.client.on('voiceStateUpdate', handleVoiceStateUpdate);
|
this.client.on('voiceStateUpdate', handleVoiceStateUpdate);
|
||||||
|
|
||||||
return this.client.login(this.token);
|
return this.client.login(this.token);
|
||||||
|
|
|
@ -1,21 +0,0 @@
|
||||||
import {Channel, TextChannel, PartialDMChannel, User, PartialUser} from 'discord.js';
|
|
||||||
|
|
||||||
const WAIT_TIME_SECONDS = 12;
|
|
||||||
|
|
||||||
export default (channel: Channel | PartialDMChannel, user: User | PartialUser): void => {
|
|
||||||
if (channel.type !== 'text') {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const textChannel = channel as TextChannel;
|
|
||||||
|
|
||||||
setTimeout(async () => {
|
|
||||||
if (user.typingIn(channel)) {
|
|
||||||
const msg = await textChannel.send(`take your time why don'tcha <@${user.id}>`);
|
|
||||||
|
|
||||||
setTimeout(async () => {
|
|
||||||
await msg.delete();
|
|
||||||
}, 2000);
|
|
||||||
}
|
|
||||||
}, WAIT_TIME_SECONDS * 1000); // Discord sends typing updates every 10s
|
|
||||||
};
|
|
|
@ -33,7 +33,7 @@ export default class {
|
||||||
if (msg.content.toLowerCase().includes('bears')) {
|
if (msg.content.toLowerCase().includes('bears')) {
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
msg.channel.send('F*** THE BEARS'),
|
msg.channel.send('F*** THE BEARS'),
|
||||||
this.playClip(msg.guild!, {title: 'GO PACKERS!', artist: 'Charlie Berens', url: 'https://www.youtube.com/watch?v=UaqlE9Pyy_Q', length: 385, playlist: null, isLive: false}, 358, 5)
|
this.playClip(msg.guild!, {title: 'GO PACKERS!', artist: 'Charlie Berens', url: 'https://www.youtube.com/watch?v=UaqlE9Pyy_Q', length: 385, playlist: null, isLive: false}, 358, 5.5)
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -294,8 +294,14 @@ export default class {
|
||||||
const ffmpegInputOptions: string[] = [];
|
const ffmpegInputOptions: string[] = [];
|
||||||
let shouldCacheVideo = false;
|
let shouldCacheVideo = false;
|
||||||
|
|
||||||
|
let format: ytdl.videoFormat | undefined;
|
||||||
|
|
||||||
if (await this.isCached(url)) {
|
if (await this.isCached(url)) {
|
||||||
ffmpegInput = cachedPath;
|
ffmpegInput = cachedPath;
|
||||||
|
|
||||||
|
if (options.seek) {
|
||||||
|
ffmpegInputOptions.push('-ss', options.seek.toString());
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Not yet cached, must download
|
// Not yet cached, must download
|
||||||
const info = await ytdl.getInfo(url);
|
const info = await ytdl.getInfo(url);
|
||||||
|
@ -304,7 +310,7 @@ export default class {
|
||||||
|
|
||||||
const filter = (format: ytdl.videoFormat): boolean => format.codecs === 'opus' && format.container === 'webm' && format.audioSampleRate !== undefined && parseInt(format.audioSampleRate, 10) === 48000;
|
const filter = (format: ytdl.videoFormat): boolean => format.codecs === 'opus' && format.container === 'webm' && format.audioSampleRate !== undefined && parseInt(format.audioSampleRate, 10) === 48000;
|
||||||
|
|
||||||
let format = formats.find(filter);
|
format = formats.find(filter);
|
||||||
|
|
||||||
const nextBestFormat = (formats: ytdl.videoFormat[]): ytdl.videoFormat | undefined => {
|
const nextBestFormat = (formats: ytdl.videoFormat[]): ytdl.videoFormat | undefined => {
|
||||||
if (formats[0].live) {
|
if (formats[0].live) {
|
||||||
|
@ -332,7 +338,7 @@ export default class {
|
||||||
|
|
||||||
// Don't cache livestreams or long videos
|
// Don't cache livestreams or long videos
|
||||||
const MAX_CACHE_LENGTH_SECONDS = 30 * 60; // 30 minutes
|
const MAX_CACHE_LENGTH_SECONDS = 30 * 60; // 30 minutes
|
||||||
shouldCacheVideo = !info.player_response.videoDetails.isLiveContent && parseInt(info.length_seconds, 10) < MAX_CACHE_LENGTH_SECONDS;
|
shouldCacheVideo = !info.player_response.videoDetails.isLiveContent && parseInt(info.length_seconds, 10) < MAX_CACHE_LENGTH_SECONDS && !options.seek;
|
||||||
|
|
||||||
ffmpegInputOptions.push(...[
|
ffmpegInputOptions.push(...[
|
||||||
'-reconnect',
|
'-reconnect',
|
||||||
|
@ -342,11 +348,11 @@ export default class {
|
||||||
'-reconnect_delay_max',
|
'-reconnect_delay_max',
|
||||||
'5'
|
'5'
|
||||||
]);
|
]);
|
||||||
}
|
|
||||||
|
|
||||||
// Add seek parameter if necessary
|
if (options.seek) {
|
||||||
if (options.seek) {
|
// Fudge seek position since FFMPEG doesn't do a great job
|
||||||
ffmpegInputOptions.push('-ss', options.seek.toString());
|
ffmpegInputOptions.push('-ss', (options.seek + 7).toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create stream and pipe to capacitor
|
// Create stream and pipe to capacitor
|
||||||
|
@ -372,7 +378,7 @@ export default class {
|
||||||
const cacheStream = createWriteStream(cacheTempPath);
|
const cacheStream = createWriteStream(cacheTempPath);
|
||||||
|
|
||||||
cacheStream.on('finish', async () => {
|
cacheStream.on('finish', async () => {
|
||||||
// Only move if size is non-zero (may have errored out)
|
// Only move if size is non-zero (may have errored out)
|
||||||
const stats = await fs.stat(cacheTempPath);
|
const stats = await fs.stat(cacheTempPath);
|
||||||
|
|
||||||
if (stats.size !== 0) {
|
if (stats.size !== 0) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue