public bool GetRecordingStatus(IProgram program, out RecordingStatus recordingStatus) { IProgramService programService = GlobalServiceProvider.Get <IProgramService>(); IProgramRecordingStatus recProgram = (IProgramRecordingStatus)programService.GetProgram(program.ProgramId).ToProgram(true); recordingStatus = recProgram.RecordingStatus; return(true); }
public CreateThumbsAndAddPictureToDBFolderThread(string Filepath) { _filepath = Filepath; work = new Work(new DoWorkHandler(this.PerformRequest)); work.ThreadPriority = ThreadPriority.BelowNormal; GlobalServiceProvider.Get <IThreadPool>().Add(work, QueuePriority.Low); }
private static void CancelSingleSchedule(Schedule schedule, Program canceledProgram) { ICanceledScheduleService canceledScheduleService = GlobalServiceProvider.Get <ICanceledScheduleService>(); CanceledSchedule canceledSchedule = CanceledScheduleFactory.CreateCanceledSchedule(schedule.IdSchedule, canceledProgram.IdChannel, canceledProgram.StartTime); canceledScheduleService.SaveCanceledSchedule(canceledSchedule); StopRecording(schedule); }
public bool GetPrograms(IChannel channel, DateTime from, DateTime to, out IList <IProgram> programs) { IProgramService programService = GlobalServiceProvider.Get <IProgramService>(); programs = programService.GetProgramsByChannelAndStartEndTimes(channel.ChannelId, from, to) .Select(tvProgram => tvProgram.ToProgram(true)) .ToList(); return(programs.Count > 0); }
public bool GetChannelGroups(out IList <IChannelGroup> groups) { IChannelGroupService channelGroupService = GlobalServiceProvider.Get <IChannelGroupService>(); groups = channelGroupService.ListAllChannelGroups() .Select(tvGroup => tvGroup.ToChannelGroup()) .ToList(); return(true); }
public bool GetChannels(IChannelGroup group, out IList <IChannel> channels) { IChannelGroupService channelGroupService = GlobalServiceProvider.Get <IChannelGroupService>(); channels = channelGroupService.GetChannelGroup(group.ChannelGroupId).GroupMaps .Select(groupMap => groupMap.Channel.ToChannel()) .ToList(); return(true); }
public override Task <bool> EditScheduleAsync(ISchedule schedule, IChannel channel = null, string title = null, DateTime?from = null, DateTime?to = null, ScheduleRecordingType?recordingType = null, int?preRecordInterval = null, int?postRecordInterval = null, string directory = null, int?priority = null) { try { ServiceRegistration.Get <ILogger>().Debug("Editing schedule {0} on channel {1} for {2}, {3} till {4}, type {5}", schedule.ScheduleId, channel.ChannelId, title, from, to, recordingType); IScheduleService scheduleService = GlobalServiceProvider.Get <IScheduleService>(); Schedule tvSchedule = scheduleService.GetSchedule(schedule.ScheduleId); tvSchedule.IdChannel = channel.ChannelId; if (title != null) { tvSchedule.ProgramName = title; } if (from != null) { tvSchedule.StartTime = from.Value; } if (to != null) { tvSchedule.EndTime = to.Value; } if (recordingType != null) { ScheduleRecordingType scheduleRecType = recordingType.Value; tvSchedule.ScheduleType = (int)scheduleRecType; } if (preRecordInterval != null) { tvSchedule.PreRecordInterval = preRecordInterval.Value; } if (postRecordInterval != null) { tvSchedule.PostRecordInterval = postRecordInterval.Value; } if (directory != null) { tvSchedule.Directory = directory; } if (priority != null) { tvSchedule.Priority = priority.Value; } scheduleService.SaveSchedule(tvSchedule); return(Task.FromResult(true)); } catch (Exception ex) { ServiceRegistration.Get <ILogger>().Warn(String.Format("Failed to edit schedule {0}", schedule.ScheduleId), ex); return(Task.FromResult(false)); } }
public bool CreateSchedule(IProgram program) { IScheduleService scheduleService = GlobalServiceProvider.Get <IScheduleService>(); Schedule schedule = ScheduleFactory.CreateSchedule(program.ChannelId, program.Title, program.StartTime, program.EndTime); schedule.PreRecordInterval = ServiceAgents.Instance.SettingServiceAgent.GetValue("preRecordInterval", 5); schedule.PostRecordInterval = ServiceAgents.Instance.SettingServiceAgent.GetValue("postRecordInterval", 5); scheduleService.SaveSchedule(schedule); return(true); }
public bool GetPrograms(string title, DateTime from, DateTime to, out IList <IProgram> programs) { IProgramService programService = GlobalServiceProvider.Get <IProgramService>(); programs = programService.GetProgramsByTitleAndStartEndTimes(title, from, to) .Select(tvProgram => tvProgram.ToProgram(true)) .Distinct(ProgramComparer.Instance) .ToList(); return(programs.Count > 0); }
public bool GetProgramsGroup(IChannelGroup channelGroup, DateTime from, DateTime to, out IList <IProgram> programs) { IProgramService programService = GlobalServiceProvider.Get <IProgramService>(); IChannelGroupService channelGroupService = GlobalServiceProvider.Get <IChannelGroupService>(); var channels = channelGroupService.GetChannelGroup(channelGroup.ChannelGroupId).GroupMaps.Select(groupMap => groupMap.Channel); IDictionary <int, IList <Program> > programEntities = programService.GetProgramsForAllChannels(from, to, channels); programs = programEntities.Values.SelectMany(x => x).Select(p => p.ToProgram()).ToList(); return(programs.Count > 0); }
// aFilePath must only be the path of the directory public FolderThumbCacher(string aFilePath, bool aOverWriteExisting) { lock (aFilePath) { _filename = aFilePath; _overWrite = aOverWriteExisting; work = new Work(new DoWorkHandler(this.PerformRequest)); work.ThreadPriority = ThreadPriority.Lowest; GlobalServiceProvider.Get <IThreadPool>().Add(work, QueuePriority.Low); } }
public bool GetChannels(IChannelGroup group, out IList <IChannel> channels) { IChannelGroupService channelGroupService = GlobalServiceProvider.Get <IChannelGroupService>(); channels = channelGroupService.GetChannelGroup(group.ChannelGroupId).GroupMaps .Where(groupMap => groupMap.Channel.VisibleInGuide) .OrderBy(groupMap => groupMap.SortOrder) .Select(groupMap => groupMap.Channel.ToChannel()) .ToList(); return(true); }
public bool RemoveSchedule(ISchedule schedule) { IScheduleService scheduleService = GlobalServiceProvider.Get <IScheduleService>(); if (scheduleService == null) { return(false); } scheduleService.DeleteSchedule(schedule.ScheduleId); return(true); }
public override bool CreateScheduleByTime(IChannel channel, DateTime from, DateTime to, out ISchedule schedule) { IScheduleService scheduleService = GlobalServiceProvider.Get <IScheduleService>(); Schedule tvSchedule = ScheduleFactory.CreateSchedule(channel.ChannelId, "Manual", from, to); tvSchedule.PreRecordInterval = ServiceAgents.Instance.SettingServiceAgent.GetValue("preRecordInterval", 5); tvSchedule.PostRecordInterval = ServiceAgents.Instance.SettingServiceAgent.GetValue("postRecordInterval", 5); tvSchedule.ScheduleType = (int)ScheduleRecordingType.Once; scheduleService.SaveSchedule(tvSchedule); schedule = tvSchedule.ToSchedule(); return(true); }
// Filename is a full path+file public FolderThumbCreator(string Filename, MusicTag FileTag) { lock (_filename) { _filename = Filename; _filetag = FileTag; work = new Work(new DoWorkHandler(this.PerformRequest)); work.ThreadPriority = ThreadPriority.Lowest; GlobalServiceProvider.Get <IThreadPool>().Add(work, QueuePriority.Low); } }
public override Task <AsyncResult <ISchedule> > CreateScheduleByTimeAsync(IChannel channel, string title, DateTime from, DateTime to, ScheduleRecordingType recordingType) { IScheduleService scheduleService = GlobalServiceProvider.Get <IScheduleService>(); Schedule tvSchedule = ScheduleFactory.CreateSchedule(channel.ChannelId, title, from, to); tvSchedule.PreRecordInterval = ServiceAgents.Instance.SettingServiceAgent.GetValue("preRecordInterval", 5); tvSchedule.PostRecordInterval = ServiceAgents.Instance.SettingServiceAgent.GetValue("postRecordInterval", 5); tvSchedule.ScheduleType = (int)recordingType; scheduleService.SaveSchedule(tvSchedule); var schedule = tvSchedule.ToSchedule(); return(Task.FromResult(new AsyncResult <ISchedule>(true, schedule))); }
/// <summary> /// Schedule saving of all settings in the near future /// </summary> public static void Save() { IThreadPool tp = GlobalServiceProvider.Get <IThreadPool>(); if (_delaySave == null) { _delaySave = tp.Add(LazySave, "Wait for saving SkinSettings"); } else if (_delaySave.State != WorkState.INPROGRESS && _delaySave.State != WorkState.INQUEUE) { _delaySave = tp.Add(LazySave, "Wait for saving SkinSettings"); } }
protected void OnPlayBD(String drive, int parentId) { ISelectBDHandler selectBDHandler; if (GlobalServiceProvider.IsRegistered <ISelectBDHandler>()) { selectBDHandler = GlobalServiceProvider.Get <ISelectBDHandler>(); } else { selectBDHandler = new SelectBDHandler(); GlobalServiceProvider.Add <ISelectBDHandler>(selectBDHandler); } selectBDHandler.OnPlayBD(drive, GetID); }
protected void UpdateServerState() { IInternalControllerService controller = GlobalServiceProvider.Instance.Get <IInternalControllerService>(); IRecordingService recordings = GlobalServiceProvider.Get <IRecordingService>(); IList <ISchedule> currentlyRecordingSchedules = recordings.ListAllActiveRecordingsByMediaType(MediaTypeEnum.TV) .Union(recordings.ListAllActiveRecordingsByMediaType(MediaTypeEnum.Radio)) .Select(r => r.Schedule.ToSchedule()).ToList(); TvServerState state = new TvServerState { IsRecording = controller.IsAnyCardRecording(), CurrentlyRecordingSchedules = currentlyRecordingSchedules }; ServiceRegistration.Get <IServerStateService>().UpdateState(TvServerState.STATE_ID, state); }
/// <summary> /// Starts MusicDBreorg /// </summary> public void Start() { Log.Info("MusicDBReorg: schedule: {0}:{1}", _runHours, _runMinutes); Log.Info( "MusicDBReorg: run on: monday:{0}, tuesday:{1}, wednesday:{2}, thursday:{3}, friday:{4}, saturday:{5}, sunday:{6}", _runMondays, _runTuesdays, _runWednesdays, _runThursdays, _runFridays, _runSaturdays, _runSundays); // Establish Handler to catch reorg events, when the reorg is from within the Settings GUI MusicDatabase.DatabaseReorgChanged += new MusicDBReorgEventHandler(ReorgStatusChange); _run = true; Work work = new Work(new DoWorkHandler(this.Run)); work.ThreadPriority = ThreadPriority.Lowest; work.Description = "MusicDBReorg Thread"; GlobalServiceProvider.Get <IThreadPool>().Add(work, QueuePriority.Low); Log.Info("MusicDBReorg: started"); }
public override bool OnMessage(GUIMessage message) { Log.Info("DVDFullscreen: Message: {0}", message.Message.ToString()); if (message.Message == GUIMessage.MessageType.GUI_MSG_WINDOW_INIT) { if (!bINIT_from_MyVideosFullScreen) { //if viz is on, this hides the DVD select dialog: GUIWindowManager.ReplaceWindow((int)GUIWindow.Window.WINDOW_FULLSCREEN_VIDEO); ISelectDVDHandler selectDVDHandler; if (GlobalServiceProvider.IsRegistered <ISelectDVDHandler>()) { selectDVDHandler = GlobalServiceProvider.Get <ISelectDVDHandler>(); } else { selectDVDHandler = new SelectDVDHandler(); GlobalServiceProvider.Add <ISelectDVDHandler>(selectDVDHandler); } string dvdToPlay = selectDVDHandler.ShowSelectDVDDialog(GetID); if (dvdToPlay == null || !selectDVDHandler.OnPlayDVD(dvdToPlay, GetID)) { Log.Info("DVDFullscreen: Returning from DVD screen"); GUIWindowManager.ShowPreviousWindow(); /*GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_WINDOW_DEINIT, this.GetID, 0, 0, GetID, 0, null); * return this.OnMessage(msg); // Send a de-init msg*/ } else { g_Player.ShowFullScreenWindow(); bINIT_from_MyVideosFullScreen = true; } } else { bINIT_from_MyVideosFullScreen = false; Log.Info("DVDFullscreen: Returning from DVD screen"); GUIWindowManager.ShowPreviousWindow(); } return(true); } return(base.OnMessage(message)); }
protected override void OnClicked(int controlId, GUIControl control, Action.ActionType actionType) { base.OnClicked(controlId, control, actionType); if (control == btnSavedPlaylists) { OnShowSavedPlaylists(m_strPlayListPath); } if (control == btnPlayDVD) { ISelectDVDHandler selectDVDHandler; if (GlobalServiceProvider.IsRegistered <ISelectDVDHandler>()) { selectDVDHandler = GlobalServiceProvider.Get <ISelectDVDHandler>(); } else { selectDVDHandler = new SelectDVDHandler(); GlobalServiceProvider.Add <ISelectDVDHandler>(selectDVDHandler); } string dvdToPlay = selectDVDHandler.ShowSelectDVDDialog(GetID); if (dvdToPlay != null) { OnPlayDVD(dvdToPlay, GetID); } return; } if (control == btnScanNew) { // Check Internet connection if (!Win32API.IsConnectedToInternet()) { GUIDialogOK dlgOk = (GUIDialogOK)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_OK); dlgOk.SetHeading(257); dlgOk.SetLine(1, GUILocalizeStrings.Get(703)); dlgOk.DoModal(GUIWindowManager.ActiveWindow); return; } OnSearchNew(); } }
public bool GetNowNextProgram(IChannel channel, out IProgram programNow, out IProgram programNext) { programNow = null; programNext = null; IProgramService programService = GlobalServiceProvider.Get <IProgramService>(); var programs = programService.GetNowAndNextProgramsForChannel(channel.ChannelId); var count = programs.Count; if (count >= 1) { programNow = programs[0].ToProgram(); } if (count >= 2) { programNext = programs[1].ToProgram(); } return(programNow != null || programNext != null); }
private void ClearBlacklistedThumbs() { IVideoThumbBlacklist blacklist; if (GlobalServiceProvider.IsRegistered <IVideoThumbBlacklist>()) { blacklist = GlobalServiceProvider.Get <IVideoThumbBlacklist>(); } else { blacklist = new VideoThumbBlacklistDBImpl(); GlobalServiceProvider.Add <IVideoThumbBlacklist>(blacklist); } if (blacklist != null) { blacklist.Clear(); } }
public bool CreateScheduleByTime(IChannel channel, DateTime from, DateTime to, out ISchedule schedule) { #if TVE3 TvDatabase.Schedule tvSchedule = _tvBusiness.AddSchedule(channel.ChannelId, "Manual", from, to, (int)ScheduleRecordingType.Once); tvSchedule.PreRecordInterval = Int32.Parse(_tvBusiness.GetSetting("preRecordInterval", "5").Value); tvSchedule.PostRecordInterval = Int32.Parse(_tvBusiness.GetSetting("postRecordInterval", "5").Value); tvSchedule.Persist(); _tvControl.OnNewSchedule(); #else IScheduleService scheduleService = GlobalServiceProvider.Get <IScheduleService>(); Schedule tvSchedule = ScheduleFactory.CreateSchedule(channel.ChannelId, "Manual", from, to); tvSchedule.PreRecordInterval = ServiceAgents.Instance.SettingServiceAgent.GetValue("preRecordInterval", 5); tvSchedule.PostRecordInterval = ServiceAgents.Instance.SettingServiceAgent.GetValue("postRecordInterval", 5); tvSchedule.ScheduleType = (int)ScheduleRecordingType.Once; scheduleService.SaveSchedule(tvSchedule); #endif schedule = tvSchedule.ToSchedule(); return(true); }
private void bttnClearBlaclistedThumbs_Click(object sender, EventArgs e) { IVideoThumbBlacklist blacklist; if (GlobalServiceProvider.IsRegistered <IVideoThumbBlacklist>()) { blacklist = GlobalServiceProvider.Get <IVideoThumbBlacklist>(); } else { blacklist = new VideoThumbBlacklistDBImpl(); GlobalServiceProvider.Add <IVideoThumbBlacklist>(blacklist); } if (blacklist != null) { blacklist.Clear(); } }
public bool GetNowNextProgram(IChannel channel, out IProgram programNow, out IProgram programNext) { programNow = null; programNext = null; IProgramService programService = GlobalServiceProvider.Get <IProgramService>(); var programs = programService.GetNowAndNextProgramsForChannel(channel.ChannelId).Select(p => p.ToProgram()).Distinct(ProgramComparer.Instance).ToList(); var count = programs.Count; if (count >= 1) { programNow = programs[0]; } if (count >= 2) { programNext = programs[1]; } return(programNow != null || programNext != null); }
protected override void OnPageLoad() { GUIWindowManager.ShowPreviousWindow(); ISelectDVDHandler selectDVDHandler; if (GlobalServiceProvider.IsRegistered <ISelectDVDHandler>()) { selectDVDHandler = GlobalServiceProvider.Get <ISelectDVDHandler>(); } else { selectDVDHandler = new SelectDVDHandler(); GlobalServiceProvider.Add <ISelectDVDHandler>(selectDVDHandler); } string dvdToPlay = selectDVDHandler.ShowSelectDriveDialog(GetID, false); if (!String.IsNullOrEmpty(dvdToPlay) && !g_Player.CurrentFile.StartsWith(dvdToPlay)) { MediaPortal.Ripper.AutoPlay.ExamineCD(dvdToPlay, true); } }
public static bool CreateVideoThumb(string aVideoPath, string aThumbPath, bool aCacheThumb, bool aOmitCredits) { //Log.Debug("VideoThumbCreator: args {0}, {1}!", aVideoPath, aThumbPath); LoadSettings(); if (String.IsNullOrEmpty(aVideoPath) || String.IsNullOrEmpty(aThumbPath)) { Log.Warn("VideoThumbCreator: Invalid arguments to generate thumbnails of your video!"); return(false); } if (!Util.Utils.FileExistsInCache(aVideoPath)) { Log.Warn("VideoThumbCreator: File {0} not found!", aVideoPath); return(false); } if (!Util.Utils.FileExistsInCache(ExtractorPath)) { Log.Warn("VideoThumbCreator: No {0} found to generate thumbnails of your video!", ExtractApp); return(false); } if (!LeaveShareThumb && !aCacheThumb) { Log.Warn( "VideoThumbCreator: No share thumbs wanted by config option AND no caching wanted - where should the thumb go then? Aborting.."); return(false); } IVideoThumbBlacklist blacklist = GlobalServiceProvider.Get <IVideoThumbBlacklist>(); if (blacklist != null && blacklist.Contains(aVideoPath)) { Log.Debug("Skipped creating thumbnail for {0}, it has been blacklisted because last attempt failed", aVideoPath); return(false); } // Params for ffmpeg // string ExtractorArgs = string.Format(" -i \"{0}\" -vframes 1 -ss {1} -s {2}x{3} \"{4}\"", aVideoPath, @"00:08:21", (int)Thumbs.ThumbLargeResolution, (int)Thumbs.ThumbLargeResolution, aThumbPath); // Params for mplayer (outputs 00000001.jpg in video resolution into working dir) -vf scale=600:-3 //string ExtractorArgs = string.Format(" -noconsolecontrols -nosound -vo jpeg:quality=90 -vf scale -frames 1 -ss {0} \"{1}\"", "501", aVideoPath); // Params for mtm (http://moviethumbnail.sourceforge.net/usage.en.html) // -D 8 : edge detection; 0:off >0:on; higher detects more; try -D4 -D6 or -D8 // -B 420/E 600 : omit this seconds from the beginning / ending TODO: use pre- / postrecording values // -c 2 / r 2 : # of column / # of rows // -b 0.60 : skip if % blank is higher; 0:skip all 1:skip really blank >1:off // -h 100 : minimum height of each shot; will reduce # of column to fit // -t : time stamp off // -i : info text off // -w 0 : width of output image; 0:column * movie width // -n : run at normal priority // -W : dont overwrite existing files, i.e. update mode // -P : dont pause before exiting; override -p const double flblank = 0.6; string blank = flblank.ToString("F", CultureInfo.CurrentCulture); int preGapSec = preRecordInterval * 60; int TimeToSeek = 3; // intRnd is used if user refresh the thumbnail from context menu int intRnd = 0; if (aOmitCredits) { Random rnd = new Random(); intRnd = rnd.Next(10, 300); } preGapSec = preGapSec + intRnd; Log.Debug("VideoThumbCreator: random value: {0}", intRnd); bool Success = false; MediaInfo = new MediaPortal.Player.MediaInfoWrapper(aVideoPath); int Duration = MediaInfo.VideoDuration / 1000; if (preGapSec > Duration) { preGapSec = (Duration / 100) * 20; // 20% of the duration } TimeBetweenThumbs = (Duration - preGapSec) / ((PreviewColumns * PreviewRows) + 1); Log.Debug("{0} duration is {1}.", aVideoPath, Duration); // Honour we are using a unix app //ExtractorArgs = ExtractorArgs.Replace('\\', '/'); try { // Set String string strFilenamewithoutExtension = Path.ChangeExtension(aVideoPath, null); // Use this for the working dir to be on the safe side string TempPath = Path.GetTempPath(); string OutputThumb = string.Format("{0}{1}", Path.ChangeExtension(aVideoPath, null), ".jpg"); string ShareThumb = OutputThumb.Replace(".jpg", ".jpg"); // Use Temp folder string strFilenamewithoutExtensionTemp = Path.GetTempPath() + Path.GetFileName(strFilenamewithoutExtension); string ShareThumbTemp = Path.GetTempPath() + Path.GetFileName(ShareThumb); // ffmpeg string ffmpegFallbackArgs = string.Format("yadif=0:-1:0,scale=600:337,setsar=1:1,tile={0}x{1}", PreviewColumns, PreviewRows); string ExtractorFallbackArgs = string.Format("-loglevel quiet -ss {0} -i \"{1}\" -y -ss {2} -vf {3} -vframes 1 -vsync 0 -an \"{4}.jpg\"", 5, aVideoPath, TimeToSeek, ffmpegFallbackArgs, strFilenamewithoutExtensionTemp); if ((LeaveShareThumb && !Util.Utils.FileExistsInCache(ShareThumb)) // No thumb in share although it should be there || (aOmitCredits) // or a refress needs by user (from context menu) || (!LeaveShareThumb && !Util.Utils.FileExistsInCache(aThumbPath))) // No thumb cached and no chance to find it in share { Log.Debug("VideoThumbCreator: No thumb in share {0} - trying to create.", aVideoPath); if (aOmitCredits) { File.Delete(ShareThumb); } List <string> pictureList = new List <string>(); string ffmpegArgs = null; string ExtractorArgs = null; int TimeOffset = 0; int i; for (i = 0; i < (PreviewColumns * PreviewRows); i++) { TimeOffset = preGapSec + i * TimeBetweenThumbs; ffmpegArgs = string.Format("yadif=0:-1:0,scale=600:337,setsar=1:1,tile=1x1"); ExtractorArgs = string.Format("-loglevel quiet -ss {0} -i \"{1}\" -y -ss {2} -vf {3} -vframes 1 -vsync 0 -an \"{4}_{5}.jpg\"", TimeOffset, aVideoPath, TimeToSeek, ffmpegArgs, strFilenamewithoutExtensionTemp, i); Success = Utils.StartProcess(ExtractorPath, ExtractorArgs, TempPath, 120000, true, GetMtnConditions()); Log.Debug("VideoThumbCreator: thumb creation {0}", ExtractorArgs); if (!Success) { Log.Debug("VideoThumbCreator: failed, try to fallback {0}", strFilenamewithoutExtensionTemp); break; } else { pictureList.Add(string.Format("{0}_{1}.jpg", strFilenamewithoutExtensionTemp, i)); } } // generate thumb if all sub pictures was created if (i == PreviewColumns * PreviewRows) { if (Util.Utils.CreateTileThumb(pictureList, string.Format("{0}.jpg", strFilenamewithoutExtensionTemp), PreviewColumns, PreviewRows)) { Log.Debug("VideoThumbCreator: thumb creation success {0}", ShareThumbTemp); File.SetAttributes(ShareThumbTemp, File.GetAttributes(ShareThumbTemp) & ~FileAttributes.Hidden); } else { Log.Debug("VideoThumbCreator: failed, try to fallback {0}", strFilenamewithoutExtensionTemp); } } else { // Maybe the pre-gap was too large or not enough sharp & light scenes could be caught Thread.Sleep(100); Success = Utils.StartProcess(ExtractorPath, ExtractorFallbackArgs, TempPath, 120000, true, GetMtnConditions()); if (!Success) { Log.Info("VideoThumbCreator: {0} has not been executed successfully with arguments: {1}", ExtractApp, ExtractorFallbackArgs); /*Utils.KillProcess(Path.ChangeExtension(ExtractApp, null)); * return false;*/ } } // give the system a few IO cycles Thread.Sleep(100); // make sure there's no process hanging Utils.KillProcess(Path.ChangeExtension(ExtractApp, null)); } else { // We have a thumbnail in share but the cache was wiped out - make sure it is recreated if (LeaveShareThumb && Util.Utils.FileExistsInCache(ShareThumb) && !Util.Utils.FileExistsInCache(aThumbPath)) { Success = true; } } Thread.Sleep(30); if (aCacheThumb && Success) { if (Picture.CreateThumbnailVideo(ShareThumbTemp, aThumbPath, (int)Thumbs.ThumbResolution, (int)Thumbs.ThumbResolution, 0, false)) { Picture.CreateThumbnailVideo(ShareThumbTemp, Utils.ConvertToLargeCoverArt(aThumbPath), (int)Thumbs.ThumbLargeResolution, (int)Thumbs.ThumbLargeResolution, 0, false); } } if (LeaveShareThumb) { if (Utils.FileExistsInCache(aThumbPath)) { try { string aThumbPathLarge = Utils.ConvertToLargeCoverArt(aThumbPath); if (Utils.FileExistsInCache(aThumbPathLarge)) { aThumbPath = aThumbPathLarge; } File.Copy(aThumbPath, ShareThumb); File.SetAttributes(ShareThumb, File.GetAttributes(ShareThumb) & ~FileAttributes.Hidden); } catch (Exception) { Log.Debug("TvThumbnails.VideoThumbCreator: Exception on File.Copy({0}, {1})", ShareThumbTemp, ShareThumb); } } } // delete final thumb from temp folder try { if (Utils.FileExistsInCache(ShareThumbTemp)) { File.Delete(ShareThumbTemp); } } catch (FileNotFoundException) { // No need to log } } catch (Exception ex) { Log.Error("VideoThumbCreator: Thumbnail generation failed - {0}!", ex.ToString()); } if (Util.Utils.FileExistsInCache(aThumbPath)) { return(true); } else { if (blacklist != null) { blacklist.Add(aVideoPath); } return(false); } }
public static bool CreateVideoThumb(string aVideoPath, string aThumbPath) { if (String.IsNullOrEmpty(aVideoPath) || String.IsNullOrEmpty(aThumbPath)) { logger.Warn("VideoThumbCreator: Invalid arguments to generate thumbnails of your video!"); return(false); } if (!MediaPortal.Util.Utils.FileExistsInCache(aVideoPath)) { logger.Warn("VideoThumbCreator: File {0} not found!", aVideoPath); return(false); } if (!MediaPortal.Util.Utils.FileExistsInCache(ExtractorPath)) { logger.Warn("VideoThumbCreator: No {0} found to generate thumbnails of your video!", ExtractApp); return(false); } IVideoThumbBlacklist blacklist = GlobalServiceProvider.Get <IVideoThumbBlacklist>(); if (blacklist != null && blacklist.Contains(aVideoPath)) { logger.Debug("Skipped creating thumbnail for {0}, it has been blacklisted because last attempt failed", aVideoPath); return(false); } // Params for ffmpeg // string ExtractorArgs = string.Format(" -i \"{0}\" -vframes 1 -ss {1} -s {2}x{3} \"{4}\"", aVideoPath, @"00:08:21", (int)Thumbs.ThumbLargeResolution, (int)Thumbs.ThumbLargeResolution, aThumbPath); // Params for mplayer (outputs 00000001.jpg in video resolution into working dir) -vf scale=600:-3 //string ExtractorArgs = string.Format(" -noconsolecontrols -nosound -vo jpeg:quality=90 -vf scale -frames 1 -ss {0} \"{1}\"", "501", aVideoPath); // Params for mtm (http://moviethumbnail.sourceforge.net/usage.en.html) // -D 8 : edge detection; 0:off >0:on; higher detects more; try -D4 -D6 or -D8 // -B 420/E 600 : omit this seconds from the beginning / ending TODO: use pre- / postrecording values // -c 2 / r 2 : # of column / # of rows // -b 0.60 : skip if % blank is higher; 0:skip all 1:skip really blank >1:off // -h 100 : minimum height of each shot; will reduce # of column to fit // -t : time stamp off // -i : info text off // -w 0 : width of output image; 0:column * movie width // -n : run at normal priority // -W : dont overwrite existing files, i.e. update mode // -P : dont pause before exiting; override -p // -O directory : save output files in the specified directory // Use this for the working dir to be on the safe side var tempPath = Path.GetTempPath(); _previewColumns = (int)mvCentralCore.Settings["videoThumbNail_cols"].Value; _previewRows = (int)mvCentralCore.Settings["videoThumbNail_rows"].Value; //string ExtractorArgs = string.Format(" -D 0 -c {0} -r {1} -t -i -w {2} -n -O \"{3}\" -P \"{4}\"", PreviewColumns, PreviewRows, 0, TempPath, aVideoPath); // Honour we are using a unix app //ExtractorArgs = ExtractorArgs.Replace('\\', '/'); const int preGapSec = 5; // int postGapSec = 5; var strFilenamewithoutExtension = Path.ChangeExtension(aVideoPath, null); if (strFilenamewithoutExtension != null) { strFilenamewithoutExtension = Path.Combine(tempPath, Path.GetFileName(strFilenamewithoutExtension)); } string ffmpegArgs = string.Format("select=isnan(prev_selected_t)+gte(t-prev_selected_t" + "\\" + ",5),yadif=0:-1:0,scale=600:337,setsar=1:1,tile={0}x{1}", _previewColumns, _previewRows); string extractorArgs = string.Format("-loglevel quiet -ss {0} -i \"{1}\" -vf {2} -vframes 1 -vsync 0 -an \"{3}_s.jpg\"", preGapSec, aVideoPath, ffmpegArgs, strFilenamewithoutExtension); string extractorFallbackArgs = string.Format("-loglevel quiet -ss {0} -i \"{1}\" -vf {2} -vframes 1 -vsync 0 -an \"{3}_s.jpg\"", 5, aVideoPath, ffmpegArgs, strFilenamewithoutExtension); try { string outputFilename = Path.Combine(tempPath, Path.GetFileName(aVideoPath)); string outputThumb = string.Format("{0}_s{1}", Path.ChangeExtension(outputFilename, null), ".jpg"); logger.Debug("ThreadID: {0} - About to start MTN process with {1}", Thread.CurrentThread.ManagedThreadId.ToString(), extractorArgs); Process processStatus = MediaPortal.Util.Utils.StartProcess(ExtractorPath, extractorArgs, true, true); if (!processStatus.HasExited) { logger.Debug("ThreadID:{0} - ffmpeg process not exited Status:{0)", Thread.CurrentThread.ManagedThreadId.ToString(), processStatus.ExitCode); } else { logger.Debug("ThreadID: {0} - Finished ffmpeg call with exit code:{1) using arguments {2}", Thread.CurrentThread.ManagedThreadId.ToString(), processStatus.ExitCode, extractorArgs); } // give the system a few IO cycles Thread.Sleep(500); if (!File.Exists(outputThumb)) { logger.Debug("*** ERROR *** - After ffmpeg the file {0} from Video {1} does not exist", Path.GetFileName(outputThumb), Path.GetFileName(aVideoPath)); } try { // remove the _s which mdn appends to its files File.Move(outputThumb, aThumbPath); } catch (FileNotFoundException) { logger.Debug("VideoThumbCreator: {0} did not extract a thumbnail to: {1}", ExtractApp, outputThumb); } catch (Exception e) { try { // Clean up logger.DebugException("VideoThumbCreator: Exception in file move", e); File.Delete(outputThumb); Thread.Sleep(50); } catch (Exception) { } } Thread.Sleep(30); } catch (Exception ex) { logger.Debug("VideoThumbCreator: Thumbnail generation failed - {0}!", ex.ToString()); } if (MediaPortal.Util.Utils.FileExistsInCache(aThumbPath)) { return(true); } else { if (blacklist != null) { blacklist.Add(aVideoPath); } return(false); } }