Using web browser from scripts

Using a web browser in Fast video cataloger

The start/help window in Fast video cataloger is a web browser. It uses the chromium embedded framework and you can access and use it easily from scripts.

You get the browser interface from the standard scripting interface

var browser = scripting.GetBrowser();

This is a standard chromium (chrome) browser interface and the official documentation can be found here:

To open a web site in the browser you would simply write:
browser.Address = "https://google.com/";

And here is a full example:

using System.Runtime;
using System.Collections.Generic;
using VideoCataloger;
using VideoCataloger.RemoteCatalogService;
class Script
{
  static public async System.Threading.Tasks.Task Run ( IScripting scripting, string arguments ) 
  { 
    var browser = scripting.GetBrowser();
    browser.Address = "https://google.com/";
  }
}

The use of the browser has almost endless possibilities. You can use it to present information and info from your scripts, you can fetch data from other systems or even create custom user interfaces.

Add keywords from video filename

Have you ever wanted to create keywords based on the filename of a video?

With the scripting support in Fast video cataloger, this is actually pretty easy. Here is a sample script to do just that, create keywords from the filename or path of a video.

The provided script takes the currently selected videos and adds keywords and actors based on the name of the video file.

You might want to tweak the script a bit to suit your own naming standard.

The array of separators list the characters that should be treated as keyword separators.

The array ignore_words is a list of common words that should simply be ignored and not added as keywords.

The integer min_length is the number of characters that a word needs to contains to be added as a keyword.

Finally, if a string contains the @ character that sentence will be treated as an actor. First name before the @ and last name after the @. The actors are created and added as cast to the video.

As usual, to run a script in Fast video cataloger you load it into the console window and click the Run button.

Script console and web browser open.

 

#region title_to_keywords


using System;
using System.IO;
using System.Runtime;
using System.Linq;
using System.Collections.Generic;
using VideoCataloger;

/// <summary>
///  Take the title and use it to generate keywords.  
///  If there is a @ in the title we treat that as an actor
///  the text before @ is first name and the text after is last name
///  if an actor with that name already exist we use that one.
/// </summary>
class KeywordsFromTitle
{
    static public void 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("");
    } 
}
#endregion

Search for video file name

How to search for a video file in a catalog

Here is a short sample script to search for a video file in the catalog given a filename.

Simply use the search api and provide the VideoQueryProperties. FilePath is a part of the video path you are searching for.

If the search failes to find any videos it will return null.

If it finds videos it will return an array of VideoFileEntry. The entries includes, among other things, the ID of the video. You use the id as key for the other APIs.

As usual, copy paste the script into the script window in Fast video cataloger. This is just a small sample, if you are developing your own script make sure to check our other developer resources.

using System.Runtime;
using System.Collections.Generic;
using VideoCataloger;
using VideoCataloger.RemoteCatalogService;
class Script
{
  static public async System.Threading.Tasks.Task Run ( IScripting scripting, string arguments ) 
  { 
    scripting.GetConsole().Clear();

    VideoQuery query = new VideoQuery();
    query.Properties = new VideoQueryProperties();
    query.Properties.Description = "";
    query.Properties.Link="";
    query.Properties.Title = "";
    query.Properties.FilePath = "part_of_filename";
    VideoFileEntry[] result = scripting.GetVideoCatalogService().SearchVideos( query );
    if (result!=null)
    {
      foreach (VideoFileEntry entry in result)
      {
        scripting.GetConsole().WriteLine( "ID=" + entry.ID );
      }
    }
  }
}

Video web search in Fast video cataloger

I will show you how to access the web browser in Fast video cataloger to easily integrate a web search with your video catalog. In Fast video cataloger 6.31 we opened up the integrated web browser in Fast video cataloger for scripting. If you are on an older version please update to the latest version from our download page or click the upgrade button in the program.

Web browser window

The web browser is what you see when you click on the view button and Help.

Click the help button to open the web browser.

Here is how it looks with just the script console and the web browser open in Fast video cataloger.

Script console and web browser open.

Scripting the browser

IScripting has a new member function GetBrowser(); that will get you the top-level interface to the integrated chromium web browser. The complete interface is documented on the cef GitHub site. To load a web page to the browser window you simply need to call Load() and give your URL as argument.

To get the underlying browser object and access the dom model you can call GetBrowser() to get and IBrowser object. The IBrowser interface has a MainFrame property of type IFrame and from here you can get access to execute javascript. That is outside the scope of this text, let me know if you are interested in more example on how to use that functionality.

Google search

You can do google searches by giving the right arguments to the google URL. http://www.google.com/search is the root URL. Search arguments are passed as q=[search terms]. Search terms need to be separated by a + sign. There are plenty of extra arguments to customize your search, for example, as_filetype=[file extension] to search for a specific filetype or as_sitesearch=[site URL] to search only at a specific site. In this example, I will only use the basic search query but you can easily expand on it to fit your needs. Remember to use & between arguments if you want to send more than the q argument y.

The search sample

We start by getting your current video selection. Then we fetch the VideoFileEntry for that selection using the VideoCatalogService interface. This is very similar to most other samples. Then we do a bit of string manipulation. Spaces in the Google query should be separated by + so we replace all spaces and also all _ as they are probably meant as spaces in the title. Last we check if the title has a “.” in there somewhere and get rid of everything after the . as that is probably a file extension. Now we have the string we want to search for. We need to pass this to google as q= so we put that in the query string.
Next, we get the browser with GetBrowser() and then call Load() with the Google base URL and the search query.

Script Code

Copy-paste the following into the script console to use the selected video title as a search term on google. Click Run to execute the script.

using System.Runtime;
using System.Collections.Generic;
using VideoCataloger;
using VideoCataloger.RemoteCatalogService;
class Script
{
  static public async System.Threading.Tasks.Task Run ( IScripting scripting, string arguments ) { 
  var selection = scripting.GetSelection();
  List selected_videos = selection.GetSelectedVideos();
  if (selected_videos.Count>0) {
    var cataloger = scripting.GetVideoCatalogService();
    var video_entry = cataloger.GetVideoFileEntry( selected_videos[0] );
    string title = video_entry.Title;
    title = title.Replace(' ', '+');
    title = title.Replace('_', '+');
    int extension = title.LastIndexOf(".");
    if (extension!=-1)
      title = title.Substring(0,extension);

    string query = "q=" + title;
    var browser = scripting.GetBrowser();
    browser.Load("http://www.google.com/search?" + query);
    }
  }
}