static public void Run(IScripting scripting, string arguments) { scripting.GetConsole().Clear(); ISelection selection = scripting.GetSelection(); List <long> selected = selection.GetSelectedVideos(); foreach (long video in selected) { // Get the video file entry var entry = scripting.GetVideoCatalogService().GetVideoFileEntry(video); scripting.GetConsole().WriteLine(System.Convert.ToString("Processing..." + entry.FilePath)); // Get the date of the file DateTime creation = File.GetCreationTime(entry.FilePath); String creeation_string = creation.ToString("yyyyMMdd_HHmmss"); // Copy the video file type extension var extension_start = entry.FilePath.LastIndexOf("."); creeation_string += entry.FilePath.Substring(extension_start); // and create the path to the file. var path_end = entry.FilePath.LastIndexOf("\\"); String target_path = entry.FilePath.Substring(0, path_end); scripting.GetConsole().WriteLine(System.Convert.ToString("Newname to:" + target_path + "\\" + creeation_string)); // rename the file System.IO.File.Move(entry.FilePath, target_path + "\\" + creeation_string); // and update the catalog witb the new file path scripting.GetVideoCatalogService().SetVideoProperty(video, "FilePath", target_path + "\\" + creeation_string); } // refresh the gui to show the changed file paths. scripting.GetGUI().Refresh(""); }
/// <summary> /// Class constructor, extract the selected data from the interface and store in class members. /// </summary> ConvertVideo(IScripting scripting) { m_scripting = scripting; ISelection selection = m_scripting.GetSelection(); var catalog = m_scripting.GetVideoCatalogService(); List <long> selected = selection.GetSelectedVideos(); if (selected.Count == 1) { long video = selected[0]; var entry = catalog.GetVideoFileEntry(video); IUtilities utilities = m_scripting.GetUtilities(); m_SelectedVideoPath = utilities.ConvertToLocalPath(entry.FilePath); m_SelectedVideoTitle = entry.Title; byte[] image_data = catalog.GetVideoFileImage(video); if (image_data == null) { return; } MemoryStream stream = new MemoryStream(image_data); m_VideoImage = System.Drawing.Bitmap.FromStream(stream); } }
/// <summary> /// the tool to execute is passed as argument. /// </summary> static public async System.Threading.Tasks.Task Run(IScripting scripting, string argument) { ISelection selection = scripting.GetSelection(); var catalog = scripting.GetVideoCatalogService(); List <long> selected = selection.GetSelectedVideos(); if (selected.Count == 0) { System.Windows.MessageBox.Show("No Video selected", "Execute sample"); return; } foreach (long video in selected) { var entry = catalog.GetVideoFileEntry(video); System.Diagnostics.Process process = new System.Diagnostics.Process(); System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; startInfo.FileName = "cmd.exe"; string cmd_line = " copy \"" + entry.FilePath + "\" \"" + entry.FilePath + "_bak\""; startInfo.Arguments = "/C " + cmd_line; process.StartInfo = startInfo; process.Start(); process.WaitForExit(); } }
/// <summary> /// </summary> static public void Run(IScripting scripting, string argument) { ISelection selection = scripting.GetSelection(); List <long> selected = selection.GetSelectedVideos(); if (selected == null) { scripting.GetConsole().WriteLine("Please select videos to add keywords to"); return; } Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); dlg.FileName = "csvfile"; // Default file name dlg.DefaultExt = ".csv"; // Default file extension dlg.Filter = "csv file (.csv)|*.csv|All files (.*)|*.*"; // Filter files by extension Nullable <bool> result = dlg.ShowDialog(); if (result == true) { var catalog = scripting.GetVideoCatalogService(); string csv_path = dlg.FileName; char[] separator = { ',', ';', '.' }; try { using (var textReader = new StreamReader(csv_path)) { scripting.GetConsole().WriteLine("Reading from " + csv_path); string line = textReader.ReadLine(); while (line != null) { string[] columns = line.Split(separator); //perform your logic foreach (string new_tag_string in columns) { foreach (long video_id in selected) { catalog.TagVideo(video_id, new_tag_string); scripting.GetConsole().WriteLine("Adding keyword " + new_tag_string + " to video " + video_id); } } line = textReader.ReadLine(); } scripting.GetConsole().WriteLine("Import done"); } } catch (Exception ex) { Console.WriteLine(ex.Message); } } }
/// <summary> /// Run sample. This is the entry function called by fvc. /// </summary> static public async System.Threading.Tasks.Task Run(IScripting scripting, string argument) { scripting.GetConsole().Clear(); ISelection selection = scripting.GetSelection(); List <long> selected = selection.GetSelectedVideos(); foreach (long video in selected) { scripting.GetConsole().WriteLine(System.Convert.ToString(video)); } }
/// <summary> /// Run sample. This is the entry function called by fvc. /// </summary> static public void Run(IScripting scripting, string argument) { ISelection selection = scripting.GetSelection(); var catalog = scripting.GetVideoCatalogService(); List <long> selected = selection.GetSelectedVideos(); foreach (long video in selected) { // set the Rating property to 1 for each of the selected videos scripting.GetVideoCatalogService().SetVideoProperty(video, "Rating", "1"); } }
/// <summary> /// Run sample. This is the entry function called by fvc. /// </summary> static public void Run(IScripting scripting, string argument) { ISelection selection = scripting.GetSelection(); var catalog = scripting.GetVideoCatalogService(); List <long> selected = selection.GetSelectedVideos(); foreach (long video in selected) { var entry = catalog.GetVideoFileEntry(selected[0]); System.Windows.MessageBox.Show(entry.FilePath, "Selected Video"); } }
/// <summary> /// Run sample. This is the entry function called by fvc. /// </summary> static public async System.Threading.Tasks.Task Run(IScripting scripting, string argument) { ISelection selection = scripting.GetSelection(); var catalog = scripting.GetVideoCatalogService(); List <long> selected = selection.GetSelectedVideos(); if (selected.Count > 0) { byte[] image = catalog.GetVideoFileImage(selected[0]); ShowImagePopup(image); } }
/// <summary> /// Run sample. This is the entry function called by fvc. /// </summary> static public async System.Threading.Tasks.Task Run(IScripting scripting, string argument) { scripting.GetConsole().Clear(); ISelection selection = scripting.GetSelection(); var catalog = scripting.GetVideoCatalogService(); long summary_playlist = -1; string playlist_name = "Sumary"; var all_playlists = catalog.GetAllVideoPlaylists( ); if (all_playlists != null) { foreach (var playlist in all_playlists) { if (playlist.Name == playlist_name) { int[] playlist_clips = catalog.GetPlaylistClipIDs(playlist.ID); foreach (int video_clip in playlist_clips) { catalog.RemovePlaylistClip(playlist.ID, video_clip); catalog.DeleteVideoClip(video_clip); } summary_playlist = playlist.ID; } } } if (summary_playlist == -1) { summary_playlist = catalog.CreateVideoPlaylist(playlist_name); } VideoCataloger.RemoteCatalogService.VideoClip clip = new VideoCataloger.RemoteCatalogService.VideoClip(); clip.ID = -1; // -1 to create new clip clip.StartTime = 20; clip.EndTime = 25; int playlist_position = 0; List <long> selected = selection.GetSelectedVideos(); if (selected != null) { foreach (long video in selected) { clip.VideoFileID = video; int new_clip_id = catalog.SetVideoClip(clip); catalog.SetClipToPlaylist(summary_playlist, playlist_position++, new_clip_id); } } scripting.GetGUI().Refresh(""); }
/// <summary> /// This is the entry function called by fvc. /// </summary> static public void Run(IScripting scripting, string argument) { scripting.GetConsole().Clear(); ISelection selection = scripting.GetSelection(); List <long> selected = selection.GetSelectedVideos(); if (selected.Count == 1) { scripting.GetConsole().WriteLine("Select more than one video"); return; } ConcatVideos merger = new ConcatVideos(scripting); merger.Concat(null, null); }
/// <summary> /// Run sample. This is the entry function called by fvc. /// </summary> static public void Run(IScripting scripting, string argument) { if (argument == "") { scripting.GetConsole().WriteLine("Enter a genre string as argument"); return; } string genre_to_set_to = argument; scripting.GetConsole().WriteLine("Setting genre for selected videos to " + genre_to_set_to); ISelection selection = scripting.GetSelection(); var catalog = scripting.GetVideoCatalogService(); List <long> selected = selection.GetSelectedVideos(); foreach (long video in selected) { // set the Genre to ActionRating property to 1 for each of the selected videos scripting.GetVideoCatalogService().SetVideoGenre(video, genre_to_set_to); } }
static public void Run(IScripting scripting, string arguments) { scripting.GetConsole().Clear(); ISelection selection = scripting.GetSelection(); List <long> selected = selection.GetSelectedVideos(); foreach (long video in selected) { var entry = scripting.GetVideoCatalogService().GetVideoFileEntry(video); var path_start = entry.FilePath.LastIndexOf("\\"); string folder_string = entry.FilePath.Substring(0, path_start); var name_start = entry.Encrypted.LastIndexOf("\\"); string name_string = entry.Encrypted.Substring(name_start); string target_path = folder_string + name_string; scripting.GetVideoCatalogService().SetVideoProperty(video, "Encrypted", target_path); scripting.GetUtilities().Unmask(video); } scripting.GetGUI().Refresh(""); }
static public void Run(IScripting scripting, string arguments) { scripting.GetConsole().Clear(); var service = scripting.GetVideoCatalogService(); ISelection selection = scripting.GetSelection(); List <long> selected = selection.GetSelectedVideos(); foreach (long video_id in selected) { var video_file_entry = service.GetVideoFileEntry(video_id); string target_folder = video_file_entry.FilePath; // this is where the images are saved int path_end = target_folder.LastIndexOf('\\'); target_folder = target_folder.Substring(0, path_end + 1); target_folder += "Thumbnails\\"; try { DirectoryInfo info = Directory.CreateDirectory(target_folder); } catch (Exception ex) { scripting.GetConsole().WriteLine(ex.Message); } long image_no = 1; Dictionary <long, ThumbnailEntry> thumbnails = service.GetThumbnailsForVideo(video_id, true); foreach (KeyValuePair <long, ThumbnailEntry> thumbnail_entry in thumbnails) { byte[] image_data = thumbnail_entry.Value.Image; string filename = target_folder + image_no.ToString() + ".jpg"; scripting.GetConsole().WriteLine("Saving image to : " + filename); System.IO.File.WriteAllBytes(filename, image_data); image_no++; } } }
/// <summary> /// Run sample. This is the entry function called by fvc. /// </summary> static public void Run(IScripting scripting, string argument) { ISelection selection = scripting.GetSelection(); var catalog = scripting.GetVideoCatalogService(); List <long> selected = selection.GetSelectedVideos(); ImageCodecInfo jpgEncoder = GetEncoder(ImageFormat.Jpeg); EncoderParameter jpeg_param = new EncoderParameter(Encoder.Quality, 85L); EncoderParameters jpeg_params = new EncoderParameters(1); jpeg_params.Param[0] = jpeg_param; foreach (long video_id in selected) { Dictionary <long, ThumbnailEntry> all_images = catalog.GetThumbnailsForVideo(video_id, true); long frame_no = 0; foreach (var pair in all_images) { MemoryStream stream = new MemoryStream(pair.Value.Image); System.Drawing.Image image = System.Drawing.Bitmap.FromStream(stream); image.RotateFlip(RotateFlipType.Rotate90FlipNone); MemoryStream out_stream = new MemoryStream(); image.Save(out_stream, jpgEncoder, jpeg_params); pair.Value.Image = out_stream.ToArray(); pair.Value.FrameNo = frame_no++; catalog.AddVideoThumbnail(pair.Value); catalog.DeleteThumbnail(pair.Key); stream.Close(); out_stream.Close(); image.Dispose(); } scripting.GetGUI().Refresh(""); } }
/// <summary> /// Call the cmd line tool. The sample just use -i that goes on the file extensions. /// Use the conversion_parameters for more advanced conversions. /// </summary> private void Concat(string out_file, string conversion_parameters) { string tool_path = GetFFMPEGPath(); string tmp_file_path = System.IO.Path.GetTempFileName(); var stream_writer = System.IO.File.CreateText(tmp_file_path); if (stream_writer == null) { System.Windows.MessageBox.Show(tool_path, "Failed to write temporary text file"); return; } ISelection selection = m_scripting.GetSelection(); IUtilities utilities = m_scripting.GetUtilities(); var catalog = m_scripting.GetVideoCatalogService(); string extension = null; string video_format = null; string video_width = null; string video_height = null; string audio_format = null; List <long> selected = selection.GetSelectedVideos(); bool can_do_pure_concat = true; foreach (long video_id in selected) { var entry = catalog.GetVideoFileEntry(video_id); string video_path = utilities.ConvertToLocalPath(entry.FilePath); var extended = catalog.GetVideoFileExtendedProperty((int)video_id); foreach (var prop in extended) { if (prop.Property == "video_Format") { if (video_format == null) { video_format = prop.Value; m_scripting.GetConsole().WriteLine(video_path + " - Video format is " + video_format); } else if (video_format != prop.Value) { string msg = "Aborting. All videos must be in the same video format.\n'"; msg += video_path + "' is in " + prop.Value + "\n"; msg += " previous was in " + video_format + "\n"; m_scripting.GetConsole().WriteLine(msg); can_do_pure_concat = false; } } else if (prop.Property == "video_Width") { if (video_width == null) { video_width = prop.Value; m_scripting.GetConsole().WriteLine(video_path + " - Video width is " + video_width); } else if (video_width != prop.Value) { string msg = "Aborting. All videos must be in the same dimension.\n'"; msg += video_path + "' width is " + prop.Value + "\n"; msg += " previous was in " + video_width + "\n"; m_scripting.GetConsole().WriteLine(msg); can_do_pure_concat = false; } } if (prop.Property == "video_Height") { if (video_height == null) { video_height = prop.Value; m_scripting.GetConsole().WriteLine(video_path + " - Video height is " + video_height); } else if (video_height != prop.Value) { string msg = "Aborting. All videos must be in the same dimension.\n'"; msg += video_path + "' height is " + prop.Value + "\n"; msg += " previous was in " + video_height + "\n"; m_scripting.GetConsole().WriteLine(msg); can_do_pure_concat = false; } } if (prop.Property == "audio_Format") { if (audio_format == null) { audio_format = prop.Value; m_scripting.GetConsole().WriteLine(video_path + " - Audio format is " + audio_format); } else if (audio_format != prop.Value) { string msg = "Aborting. All videos must be in the same audio format.\n"; msg += video_path + "is in " + prop.Value + "\n"; msg += " previous was in " + audio_format + "\n"; m_scripting.GetConsole().WriteLine(msg); can_do_pure_concat = false; } } } stream_writer.Write("file '" + video_path + "'"); stream_writer.WriteLine(); // if we can not do a pure concat we abort here. To continue we would need to re-encode the file and that // takes a bit more care and user intervention if (!can_do_pure_concat) { return; } if (extension == null) { int extension_start = video_path.LastIndexOf("."); extension = video_path.Substring(extension_start); } } stream_writer.Close(); if (out_file == null) { Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog(); dlg.FileName = "concat" + extension; dlg.DefaultExt = extension; dlg.Filter = "All files|*.*"; Nullable <bool> result = dlg.ShowDialog(); if (result == false) { return; } out_file = dlg.FileName; } // // do concatination // System.Diagnostics.Process process = new System.Diagnostics.Process(); System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); startInfo.FileName = "cmd.exe"; string cmd_line = " -f concat -safe 0 -i " + tmp_file_path + conversion_parameters + " -c copy \"" + out_file + "\""; startInfo.Arguments = "/C " + tool_path + " " + cmd_line; // use /K instead of /C to keep the cmd window up process.StartInfo = startInfo; m_scripting.GetConsole().WriteLine("Running " + startInfo.Arguments); process.Start(); process.WaitForExit(); File.Delete(tmp_file_path); // // Show video in shell player // System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo() { FileName = out_file, UseShellExecute = true, Verb = "open" }); }
static public void Run(IScripting scripting, string argument) { scripting.GetConsole().Clear(); var catalog = scripting.GetVideoCatalogService(); ISelection selection = scripting.GetSelection(); List <long> selected = selection.GetSelectedVideos(); foreach (long video in selected) { try { var entry = catalog.GetVideoFileEntry(video); IUtilities utilities = scripting.GetUtilities(); var selected_path = utilities.ConvertToLocalPath(entry.FilePath); var file = ShellFile.FromFilePath(selected_path); var selected_videos = new long[1]; selected_videos[0] = video; var TagInstances = catalog.GetTagsForVideos(selected_videos); List <string> tag_list = new List <string>(); foreach (var tag in TagInstances) { tag_list.Add(tag.Name); } scripting.GetConsole().Write("Tagging : " + selected_path + " ..."); ShellPropertyWriter propertyWriter = file.Properties.GetPropertyWriter(); propertyWriter.WriteProperty(SystemProperties.System.Keywords, tag_list.ToArray()); int Rating = 0; if (entry.Rating == 1) { Rating = 1; } if (entry.Rating == 2) { Rating = 25; } if (entry.Rating == 3) { Rating = 50; } if (entry.Rating == 4) { Rating = 75; } if (entry.Rating == 5) { Rating = 99; } propertyWriter.WriteProperty(SystemProperties.System.Rating, Rating); propertyWriter.WriteProperty(SystemProperties.System.Comment, entry.Description); propertyWriter.Close(); scripting.GetConsole().WriteLine("Done "); } catch (Exception ex) { scripting.GetConsole().WriteLine(ex.Message); } } }
static public async System.Threading.Tasks.Task Run(IScripting scripting, string arguments) { scripting.GetConsole().Clear(); var catalog = scripting.GetVideoCatalogService(); ISelection selection = scripting.GetSelection(); List <long> selected = selection.GetSelectedVideos(); foreach (long video in selected) { // Get the video file entry var entry = catalog.GetVideoFileEntry(video); scripting.GetConsole().WriteLine(System.Convert.ToString("Processing..." + entry.FilePath)); char[] separators = { ' ', ',', '.', '-', '[', ']', '{', '}', '_' }; string[] ignore_words = { "is", "are", "who", "where" }; string title = entry.Title; string[] keywords = title.Split(separators); int min_length = 3; foreach (string word in keywords) { if (word.Length >= min_length) { if (!ignore_words.Contains(word)) { if (word.Contains("@")) { // Actor string[] names = word.Split('@'); string first_name = names[0]; string last_name = names[1]; scripting.GetConsole().WriteLine("Actor FirstName:" + first_name + " LastName:" + last_name); int actor_id = -1; VideoCataloger.RemoteCatalogService.Actor[] current_actors = catalog.GetActors(null, first_name, last_name, true); if (current_actors.Length >= 1) { actor_id = current_actors[0].ID; } else { VideoCataloger.RemoteCatalogService.Actor actor = new VideoCataloger.RemoteCatalogService.Actor(); actor.FirstName = first_name; actor.LastName = last_name; actor_id = catalog.AddActorToDB(actor); } if (actor_id != -1) { catalog.AddActorToVideo(video, actor_id); } } else { // Keywords scripting.GetConsole().WriteLine("Keyword:" + word); scripting.GetVideoCatalogService().TagVideo(video, word); } } } } } // refresh the gui to show the changed file paths. scripting.GetGUI().Refresh(""); }
static public async System.Threading.Tasks.Task Run(IScripting scripting, string arguments) { scripting.GetConsole().Clear(); var service = scripting.GetVideoCatalogService(); ISelection selection = scripting.GetSelection(); List <long> selected = selection.GetSelectedVideos(); if (selected.Count == 0) { scripting.GetConsole().WriteLine("Select videos to export"); return; } string target_folder = "c:\\export\\"; try { DirectoryInfo info = Directory.CreateDirectory(target_folder); } catch (Exception ex) { scripting.GetConsole().WriteLine(ex.Message); } string html_header = "<html><head></head><body>"; string html_footer = "</body></html>"; string filename = target_folder + "index.html"; System.IO.File.WriteAllText(filename, html_header); int item = 0; int items_per_row = 1; bool in_row = false; string table_start = "<table>"; string table_end = "</table>"; System.IO.File.AppendAllText(filename, table_start); foreach (long video_id in selected) { if (in_row && (item % items_per_row) == 0) { System.IO.File.AppendAllText(filename, "</tr>"); in_row = false; } if ((item % items_per_row) == 0) { System.IO.File.AppendAllText(filename, "<tr>"); in_row = true; } var video_file_entry = service.GetVideoFileEntry(video_id); string line = ""; string video_thumb_name = item + ".jpg"; line = "<td>" + video_file_entry.ID.ToString() + "</td>"; line = "<td><img src=\""; System.IO.File.AppendAllText(filename, line); line = video_thumb_name; System.IO.File.AppendAllText(filename, line); line = "\"></td>"; System.IO.File.AppendAllText(filename, line); string path = scripting.GetUtilities().ConvertToLocalPath(video_file_entry.FilePath); line = "<td><a href=\"" + path + "\">" + video_file_entry.Title + "</a></td>"; System.IO.File.AppendAllText(filename, line); line = "<td>" + video_file_entry.Rating + "</td>"; System.IO.File.AppendAllText(filename, line); line = "<td>" + video_file_entry.Description + "</td>"; System.IO.File.AppendAllText(filename, line); byte[] video_image = service.GetVideoFileImage(video_id); System.IO.File.WriteAllBytes(target_folder + video_thumb_name, video_image); item++; } if (in_row) { System.IO.File.AppendAllText(filename, "</tr>"); } System.IO.File.AppendAllText(filename, table_end); System.IO.File.AppendAllText(filename, html_footer); scripting.GetConsole().WriteLine("Html exported to: " + filename); }