Fix video library initialization for Quick Play
- Replace VideoLibrary dependency with direct directory scanning - Add scanVideoDirectory method to DesktopFileManager - Implement buildUnifiedVideoLibrary function - Add fallback direct directory scanning using Electron API - Improve error handling for video loading - Fix VideoLibrary DOM dependency issues in Quick Play mode
This commit is contained in:
parent
8fb373afdb
commit
0f0147db2a
136
quick-play.html
136
quick-play.html
|
|
@ -550,8 +550,16 @@
|
|||
|
||||
// Try desktop file manager
|
||||
if (allVideos.length === 0 && window.desktopFileManager) {
|
||||
allVideos = window.desktopFileManager.getAllVideos();
|
||||
console.log(`🎬 Got ${allVideos.length} videos from DesktopFileManager`);
|
||||
try {
|
||||
if (typeof window.desktopFileManager.getAllVideos === 'function') {
|
||||
allVideos = window.desktopFileManager.getAllVideos();
|
||||
console.log(`🎬 Got ${allVideos.length} videos from DesktopFileManager`);
|
||||
} else {
|
||||
console.log('🎬 DesktopFileManager.getAllVideos not available');
|
||||
}
|
||||
} catch (dmError) {
|
||||
console.warn('🎬 Error getting videos from DesktopFileManager:', dmError);
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback to unified storage
|
||||
|
|
@ -655,16 +663,29 @@
|
|||
if (linkedDirs.length > 0) {
|
||||
console.log(`🎬 Found ${linkedDirs.length} linked directories, scanning...`);
|
||||
|
||||
// Initialize VideoLibrary to scan directories
|
||||
if (typeof VideoLibrary !== 'undefined') {
|
||||
const tempVideoLibrary = new VideoLibrary({
|
||||
videoContainer: document.createElement('div')
|
||||
});
|
||||
await tempVideoLibrary.loadVideoLibrary();
|
||||
window.videoLibrary = tempVideoLibrary;
|
||||
console.log('🎬 VideoLibrary initialized successfully');
|
||||
// Instead of creating a full VideoLibrary instance,
|
||||
// let's directly scan the directories using DesktopFileManager
|
||||
if (window.desktopFileManager) {
|
||||
console.log('🎬 Using DesktopFileManager to scan directories...');
|
||||
|
||||
// Try to refresh/rescan directories
|
||||
for (const dir of linkedDirs) {
|
||||
try {
|
||||
console.log(`🎬 Scanning directory: ${dir.path}`);
|
||||
await window.desktopFileManager.scanVideoDirectory(dir.path);
|
||||
} catch (scanError) {
|
||||
console.warn(`⚠️ Error scanning directory ${dir.path}:`, scanError);
|
||||
}
|
||||
}
|
||||
|
||||
// Build unified video library manually
|
||||
await buildUnifiedVideoLibrary();
|
||||
return true;
|
||||
} else {
|
||||
console.log('🎬 DesktopFileManager not available, using direct directory scan...');
|
||||
await scanDirectoriesDirectly(linkedDirs);
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
console.log('🎬 No linked directories found');
|
||||
|
|
@ -676,6 +697,99 @@
|
|||
}
|
||||
}
|
||||
|
||||
async function buildUnifiedVideoLibrary() {
|
||||
try {
|
||||
console.log('🎬 Building unified video library...');
|
||||
|
||||
const allVideos = [];
|
||||
|
||||
// Get videos from desktop file manager
|
||||
if (window.desktopFileManager) {
|
||||
const dmVideos = window.desktopFileManager.getAllVideos();
|
||||
allVideos.push(...dmVideos);
|
||||
console.log(`🎬 Added ${dmVideos.length} videos from DesktopFileManager`);
|
||||
}
|
||||
|
||||
// Get individual videos
|
||||
const individualVideos = JSON.parse(localStorage.getItem('videoFiles') || '{}');
|
||||
Object.values(individualVideos).forEach(videoArray => {
|
||||
if (Array.isArray(videoArray)) {
|
||||
allVideos.push(...videoArray);
|
||||
}
|
||||
});
|
||||
|
||||
console.log(`🎬 Total videos collected: ${allVideos.length}`);
|
||||
|
||||
// Save to unified storage
|
||||
const unifiedLibrary = {
|
||||
allVideos: allVideos,
|
||||
lastUpdated: new Date().toISOString(),
|
||||
totalCount: allVideos.length
|
||||
};
|
||||
|
||||
localStorage.setItem('unifiedVideoLibrary', JSON.stringify(unifiedLibrary));
|
||||
console.log(`🎬 Unified video library saved with ${allVideos.length} videos`);
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ Error building unified video library:', error);
|
||||
}
|
||||
}
|
||||
|
||||
async function scanDirectoriesDirectly(linkedDirs) {
|
||||
try {
|
||||
console.log('🎬 Scanning directories directly...');
|
||||
|
||||
if (!window.electronAPI || !window.electronAPI.readDirectory) {
|
||||
console.warn('⚠️ Electron API not available for directory scanning');
|
||||
return;
|
||||
}
|
||||
|
||||
const allVideos = [];
|
||||
const videoExtensions = ['.mp4', '.avi', '.mov', '.wmv', '.flv', '.webm', '.mkv', '.m4v'];
|
||||
|
||||
for (const dir of linkedDirs) {
|
||||
try {
|
||||
console.log(`🎬 Reading directory: ${dir.path}`);
|
||||
const files = await window.electronAPI.readDirectory(dir.path);
|
||||
|
||||
if (Array.isArray(files)) {
|
||||
const videoFiles = files.filter(file => {
|
||||
const ext = file.name.toLowerCase().substring(file.name.lastIndexOf('.'));
|
||||
return videoExtensions.includes(ext);
|
||||
});
|
||||
|
||||
const processedVideos = videoFiles.map(file => ({
|
||||
name: file.name,
|
||||
path: file.path,
|
||||
size: file.size || 0,
|
||||
dateAdded: new Date().toISOString(),
|
||||
directory: dir.path,
|
||||
source: 'directory'
|
||||
}));
|
||||
|
||||
allVideos.push(...processedVideos);
|
||||
console.log(`🎬 Found ${videoFiles.length} videos in ${dir.path}`);
|
||||
}
|
||||
} catch (dirError) {
|
||||
console.warn(`⚠️ Error reading directory ${dir.path}:`, dirError);
|
||||
}
|
||||
}
|
||||
|
||||
// Save to unified storage
|
||||
const unifiedLibrary = {
|
||||
allVideos: allVideos,
|
||||
lastUpdated: new Date().toISOString(),
|
||||
totalCount: allVideos.length
|
||||
};
|
||||
|
||||
localStorage.setItem('unifiedVideoLibrary', JSON.stringify(unifiedLibrary));
|
||||
console.log(`🎬 Direct scan complete: ${allVideos.length} videos found`);
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ Error in direct directory scan:', error);
|
||||
}
|
||||
}
|
||||
|
||||
function showVideoSetupNotification() {
|
||||
// Show a user-friendly notification about setting up videos
|
||||
const taskTitle = document.getElementById('task-title');
|
||||
|
|
|
|||
|
|
@ -589,6 +589,47 @@ class DesktopFileManager {
|
|||
return this.allLinkedVideos;
|
||||
}
|
||||
|
||||
async scanVideoDirectory(directoryPath) {
|
||||
if (!this.isElectron) {
|
||||
console.warn('Not in Electron environment, cannot scan directory');
|
||||
return [];
|
||||
}
|
||||
|
||||
try {
|
||||
console.log(`🎬 Scanning video directory: ${directoryPath}`);
|
||||
const files = await window.electronAPI.readDirectory(directoryPath);
|
||||
|
||||
if (!Array.isArray(files)) {
|
||||
console.warn('Directory scan returned non-array result:', files);
|
||||
return [];
|
||||
}
|
||||
|
||||
const videoExtensions = ['.mp4', '.avi', '.mov', '.wmv', '.flv', '.webm', '.mkv', '.m4v'];
|
||||
const videoFiles = files.filter(file => {
|
||||
const ext = file.name.toLowerCase().substring(file.name.lastIndexOf('.'));
|
||||
return videoExtensions.includes(ext);
|
||||
});
|
||||
|
||||
console.log(`🎬 Found ${videoFiles.length} video files in ${directoryPath}`);
|
||||
|
||||
// Process video files into the expected format
|
||||
const processedVideos = videoFiles.map(file => ({
|
||||
name: file.name,
|
||||
path: file.path,
|
||||
size: file.size || 0,
|
||||
dateAdded: new Date().toISOString(),
|
||||
directory: directoryPath,
|
||||
source: 'directory'
|
||||
}));
|
||||
|
||||
return processedVideos;
|
||||
|
||||
} catch (error) {
|
||||
console.error(`❌ Error scanning video directory ${directoryPath}:`, error);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
getDirectoriesInfo() {
|
||||
return this.externalVideoDirectories.map(dir => ({
|
||||
id: dir.id,
|
||||
|
|
|
|||
Loading…
Reference in New Issue