Beispiel #1
0
        private void OnWatcherRenamed(object source, RenamedEventArgs e)
        {
            log.Info($"File: {e.OldFullPath} renamed to {e.FullPath}");

            var status = StatusList.FirstOrDefault(s => s.SourceFile == e.OldFullPath);

            if (status != null)
            {
                status.SourceFile = e.FullPath;
                OnFileRenamed?.Invoke(this, e);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Splits a file at the cuts specified and renames the episodes if possible.
        /// </summary>
        /// <param name="file">The file to split.</param>
        /// <param name="episodeInfo">If exists will try to rename the split files to the episode info.</param>
        /// <param name="cuts">All the cuts the file should be split at.</param>
        public void Split(string file, EpisodeInfo[] episodeInfo, params TimeSpan[] cuts)
        {
            if (!File.Exists(file))
            {
                throw new FileNotFoundException(file);
            }

            string rootFolder = Path.GetDirectoryName(file);

            string cutOffs          = string.Join(",", cuts.Where(i => i != TimeSpan.Zero).Select(i => Math.Floor(i.TotalSeconds)));
            string tempNameTemplate = Path.Combine(rootFolder, "split_" + Path.GetFileNameWithoutExtension(file) + "_{0}" + Path.GetExtension(file));

            _proc.StartInfo.Arguments = $"-i \"{file}\" -f segment -segment_atclocktime 1 -segment_times {cutOffs} -c:v copy -c:a copy \"{string.Format(tempNameTemplate, "%03d")}\"";
            _proc.Start();
            string output = _proc.StandardError.ReadToEnd();

            _proc.WaitForExit();
            Thread.Sleep(1000);

            // TODO: Rename videos and move original file.
            if (episodeInfo != null)
            {
                for (int i = 0; i < episodeInfo.Length; i++)
                {
                    string name    = string.Format(tempNameTemplate, i.ToString("000"));
                    string newName = Path.Combine(rootFolder, episodeInfo[i].ToString().Trim() + Path.GetExtension(file));

                    // Rename to single episodes
                    File.Move(name, newName);
                    OnFileRenamed?.Invoke(Path.GetFileName(name), Path.GetFileName(newName));

                    // Move original file.
                    string destination = Path.Combine(rootFolder, "Originals", Path.GetFileName(file));

                    if (!Directory.Exists(Path.GetDirectoryName(destination)))
                    {
                        Directory.CreateDirectory(Path.GetDirectoryName(destination));
                    }

                    if (File.Exists(file))
                    {
                        File.Move(file, destination);
                        OnFileMoved?.Invoke(file, destination);
                    }
                }
            }
        }