Skip to content

Commit 2d065fa

Browse files
committed
Refactor Play command to refresh local video list before matching input (#152)
1 parent 1ace5b9 commit 2d065fa

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/commands/play.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import { BaseCommand } from "./base.js";
22
import { CommandContext } from "../types/index.js";
33
import { MediaService } from "../services/media.js";
44
import { ErrorUtils, GeneralUtils } from '../utils/shared.js';
5+
import fs from 'fs';
6+
import path from 'path';
7+
import config from "../config.js";
58

69
export default class PlayCommand extends BaseCommand {
710
name = "play";
@@ -27,8 +30,17 @@ export default class PlayCommand extends BaseCommand {
2730
if (GeneralUtils.isValidUrl(input)) {
2831
await this.handleUrl(context, input);
2932
} else {
30-
// Try to find local video first
31-
const video = context.videos.find(m => m.name === input);
33+
// Refresh video list from disk before matching
34+
const videoFiles = fs.readdirSync(config.videosDir);
35+
const refreshedVideos = videoFiles.map(file => ({
36+
name: path.parse(file).name,
37+
path: path.join(config.videosDir, file)
38+
}));
39+
context.videos.length = 0;
40+
context.videos.push(...refreshedVideos);
41+
42+
// Case-insensitive match
43+
const video = context.videos.find(m => m.name.toLowerCase() === input.toLowerCase());
3244

3345
if (video) {
3446
await this.handleLocalVideo(context, video);

0 commit comments

Comments
 (0)