boton temporal para actualizar duraciones, fix de duracion en y peso de el archvio
This commit is contained in:
@@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:pluto_grid/pluto_grid.dart';
|
||||
import 'package:supabase_flutter/supabase_flutter.dart';
|
||||
import 'package:video_player/video_player.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:energy_media/helpers/globals.dart';
|
||||
import 'package:energy_media/models/media/media_models.dart';
|
||||
@@ -171,6 +172,10 @@ class VideosProvider extends ChangeNotifier {
|
||||
value: media.seconds != null
|
||||
? _formatDuration(media.seconds!)
|
||||
: '-'),
|
||||
'file_size': PlutoCell(
|
||||
value: media.fileSizeBytes != null
|
||||
? _formatFileSize(media.fileSizeBytes!)
|
||||
: '-'),
|
||||
'createdAt': PlutoCell(
|
||||
value: media.createdAt?.toString().split('.')[0] ?? '-'),
|
||||
'tags': PlutoCell(value: media.tags.join(', ')),
|
||||
@@ -750,6 +755,90 @@ class VideosProvider extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
/// Update missing video durations (batch process)
|
||||
Future<Map<String, dynamic>> updateMissingDurations(
|
||||
Function(int current, int total) onProgress,
|
||||
) async {
|
||||
try {
|
||||
// Obtener videos sin duración
|
||||
final videosWithoutDuration = mediaFiles
|
||||
.where((video) => video.seconds == null && video.fileUrl != null)
|
||||
.toList();
|
||||
|
||||
if (videosWithoutDuration.isEmpty) {
|
||||
return {'success': true, 'updated': 0, 'failed': 0};
|
||||
}
|
||||
|
||||
int updated = 0;
|
||||
int failed = 0;
|
||||
|
||||
for (int i = 0; i < videosWithoutDuration.length; i++) {
|
||||
final video = videosWithoutDuration[i];
|
||||
onProgress(i + 1, videosWithoutDuration.length);
|
||||
|
||||
VideoPlayerController? controller;
|
||||
try {
|
||||
// Inicializar VideoPlayerController para obtener duración
|
||||
controller = VideoPlayerController.network(video.fileUrl!);
|
||||
await controller.initialize();
|
||||
|
||||
final durationSeconds = controller.value.duration.inSeconds;
|
||||
|
||||
if (durationSeconds > 0) {
|
||||
// Obtener metadata actual
|
||||
final response = await supabaseML
|
||||
.from('media_files')
|
||||
.select('metadata_json')
|
||||
.eq('media_file_id', video.mediaFileId)
|
||||
.eq('organization_fk', organizationId)
|
||||
.single();
|
||||
|
||||
final metadata =
|
||||
response['metadata_json'] as Map<String, dynamic>? ?? {};
|
||||
|
||||
// Actualizar metadata con duración
|
||||
metadata['duration_seconds'] = durationSeconds;
|
||||
|
||||
// Actualizar tanto seconds como metadata_json
|
||||
await supabaseML
|
||||
.from('media_files')
|
||||
.update({
|
||||
'seconds': durationSeconds,
|
||||
'metadata_json': metadata,
|
||||
})
|
||||
.eq('media_file_id', video.mediaFileId)
|
||||
.eq('organization_fk', organizationId);
|
||||
|
||||
updated++;
|
||||
print('✅ Video ${video.mediaFileId}: $durationSeconds segundos');
|
||||
} else {
|
||||
failed++;
|
||||
print('⚠️ Video ${video.mediaFileId}: duración inválida');
|
||||
}
|
||||
} catch (e) {
|
||||
print('❌ Error procesando video ${video.mediaFileId}: $e');
|
||||
failed++;
|
||||
} finally {
|
||||
// Limpiar recursos del controller
|
||||
controller?.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
// Recargar datos
|
||||
await loadMediaFiles();
|
||||
|
||||
return {
|
||||
'success': true,
|
||||
'updated': updated,
|
||||
'failed': failed,
|
||||
'total': videosWithoutDuration.length,
|
||||
};
|
||||
} catch (e) {
|
||||
print('Error en updateMissingDurations: $e');
|
||||
return {'success': false, 'error': e.toString()};
|
||||
}
|
||||
}
|
||||
|
||||
// ========== SEARCH & FILTER ==========
|
||||
|
||||
/// Search videos by title or description
|
||||
@@ -782,6 +871,10 @@ class VideosProvider extends ChangeNotifier {
|
||||
value: media.seconds != null
|
||||
? _formatDuration(media.seconds!)
|
||||
: '-'),
|
||||
'file_size': PlutoCell(
|
||||
value: media.fileSizeBytes != null
|
||||
? _formatFileSize(media.fileSizeBytes!)
|
||||
: '-'),
|
||||
'createdAt': PlutoCell(
|
||||
value: media.createdAt?.toString().split('.')[0] ?? '-'),
|
||||
'tags': PlutoCell(value: media.tags.join(', ')),
|
||||
|
||||
Reference in New Issue
Block a user