Example #1
0
    /// <summary>
    /// Upload new Media File by using V2 API
    /// </summary>
    /// <param name="SecretKey">Backlot Secret Key</param>
    /// <param name="APIKey">Backlot API Key</param>
    /// <param name="hs">File's Standard Metadata in Hashtable Format</param>
    /// <param name="file">Upload File Object</param>
    public static void NewMediaUploadStream(string SecretKey, string APIKey, string id, Stream inStream)
    {
        ArrayList resHS = new ArrayList();
        string    json  = OoyalaAPI.getJSON(SecretKey, APIKey, string.Format(formatUploadURLs, id), null);

        resHS = (ArrayList)JSON.JsonDecode(json);
        foreach (string uploadurl in resHS)
        {
            System.Net.Cache.RequestCachePolicy requestCachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.NoCacheNoStore);
            HttpWebRequest request = HttpWebRequest.Create(uploadurl) as HttpWebRequest;
            request.CachePolicy = requestCachePolicy;
            request.Method      = "PUT";
            request.AllowWriteStreamBuffering = false;
            request.Timeout       = UPLOAD_TIMEOUT;
            request.SendChunked   = false;
            request.ContentLength = inStream.Length;
            var    outStream = request.GetRequestStream();
            byte[] b         = new byte[1024];
            int    r;
            while ((r = inStream.Read(b, 0, b.Length)) > 0)
            {
                outStream.Write(b, 0, r);
            }
            outStream.Flush();
            outStream.Close();
        }
    }
Example #2
0
        public static OoyalaVideo GetOoyalaVideo(string assetId, VideoIndexerSettings settings)
        {
            if (settings == null || string.IsNullOrEmpty(settings.OoyalaKey) || string.IsNullOrEmpty(settings.OoyalaSecret))
            {
                return(null);
            }

            var api = new OoyalaAPI(settings.OoyalaKey, settings.OoyalaSecret);

            var output = new OoyalaVideo();

            var asset = api.get("assets/" + assetId, EmptyDict) as Hashtable;

            output.Description = asset?["description"] as string;
            output.Title       = asset?["name"] as string;

            var metadata = api.get($"assets/{assetId}/metadata", EmptyDict) as Hashtable;

            output.Keywords = (metadata?["keywords"] as string)?.Split(',')?.ToList();

            if (api.get($"assets/{assetId}/streams", EmptyDict) is ArrayList streams)
            {
                var q = from stream in streams.OfType <Hashtable>()
                        let streamInfo = stream["is_source"] as bool?
                                         where streamInfo == true
                                         select stream;

                var sourceStream = q.FirstOrDefault();
                output.Url = sourceStream?["url"] as string;
            }

            return(output);
        }
Example #3
0
    /// <summary>
    /// Apply Labels to Media Assets by using V2 API
    /// </summary>
    /// <param name="SecretKey">Backlot Secret Key</param>
    /// <param name="APIKey">Backlot API Key</param>
    /// <param name="id">Media Asset ID</param>
    /// <param name="labelList">Selected Lables which are to be applied to given media asset</param>
    public static void ApplyLabelsToAssets(string SecretKey, string APIKey, String id, ArrayList labelList)
    {
        string postPath     = string.Empty;
        string jsonbody     = "[";
        bool   isLabelAvail = false;

        foreach (string tnValue in labelList)
        {
            if (!string.IsNullOrEmpty(tnValue))
            {
                if (isLabelAvail)
                {
                    jsonbody += ",\"" + tnValue + "\"";
                }
                else
                {
                    jsonbody += "\"" + tnValue + "\"";
                }

                isLabelAvail = true;
            }
        }
        jsonbody += "]";
        if (isLabelAvail)
        {
            postPath = string.Format(formatLabels, id);
            OoyalaAPI.post(SecretKey, APIKey, postPath, jsonbody);
        }
    }
Example #4
0
    /// <summary>
    /// Get Media Player based on Player ID
    /// </summary>
    /// <param name="SecretKey">Backlot Secret Key</param>
    /// <param name="APIKey">Backlot API Key</param>
    /// <param name="id">Player ID</param>
    /// <returns></returns>
    public static OoyalaData.Players.Item GetPlayer(string SecretKey, string APIKey, String id)
    {
        OoyalaData.Players.Item itm = new OoyalaData.Players.Item();
        string json = OoyalaAPI.getJSON(SecretKey, APIKey, pathPlayer + "/" + id, null);

        itm = JsonHelper.JsonDeserialize <OoyalaData.Players.Item>(json);
        return(itm);
    }
Example #5
0
    /// <summary>
    /// Set Upload status for Media asset after uploading by using V2 API
    /// </summary>
    /// <param name="SecretKey">Backlot Secret Key</param>
    /// <param name="APIKey">Backlot API Key</param>
    /// <param name="id">Media Asset ID</param>
    /// <param name="status">Upload Status</param>
    public static void SetMediaFileStatus(string SecretKey, string APIKey, string id, string status)
    {
        string    postStatus = string.Format(formatStatus, id);
        Hashtable hsStatus   = new Hashtable();

        hsStatus.Add("status", status);
        OoyalaAPI.put(SecretKey, APIKey, postStatus, hsStatus);
    }
Example #6
0
    /// <summary>
    /// Get all available Labels in Ooyala by using V2 API
    /// </summary>
    /// <param name="SecretKey">Backlot Secret Key</param>
    /// <param name="APIKey">Backlot API Key</param>
    /// <returns>List of Labels</returns>
    public static List <OoyalaData.Labels.Item> GetAllLabels(string SecretKey, string APIKey)
    {
        var list = new List <OoyalaData.Labels.Item>();

        OoyalaData.Labels.OoyalaLabelDataResult odr = new OoyalaData.Labels.OoyalaLabelDataResult();
        string json = OoyalaAPI.getJSON(SecretKey, APIKey, pathLabel, null);

        odr = JsonHelper.JsonDeserialize <OoyalaData.Labels.OoyalaLabelDataResult>(json);
        list.AddRange(odr.items);
        return(list);
    }
Example #7
0
    /// <summary>
    /// Validate API Key and Secret Key by using V2 API
    /// </summary>
    /// <param name="secretKey"></param>
    /// <param name="APIKey"></param>
    /// <returns>Whether API and Secret Key are valid or not.</returns>
    public static bool ValidateAPIInfo(string secretKey, string APIKey)
    {
        System.Collections.Generic.Dictionary <string, string> parameters = new System.Collections.Generic.Dictionary <string, string>();
        string expireValue = DateTime.Now.AddHours(1).Ticks.ToString();

        parameters.Add("api_key", APIKey);
        parameters.Add("expires", expireValue);
        parameters.Add("limit", "1");
        var res = OoyalaAPI.getJSON(secretKey, APIKey, "players", parameters);

        return(res != null);
    }
Example #8
0
    /// <summary>
    /// Get Labels of given Asset ID by using V2 API
    /// </summary>
    /// <param name="SecretKey">Backlot Secret Key</param>
    /// <param name="APIKey">Backlot API Key</param>
    /// <param name="id">Media Asset ID</param>
    /// <returns>List of Labels for given Asset ID</returns>
    public static List <OoyalaData.Labels.Item> GetAssetLabels(string SecretKey, string APIKey, String asset_id)
    {
        var    list     = new List <OoyalaData.Labels.Item>();
        string postPath = postPath = string.Format(formatLabels, asset_id);

        OoyalaData.Labels.OoyalaLabelDataResult odr = new OoyalaData.Labels.OoyalaLabelDataResult();
        string json = OoyalaAPI.getJSON(SecretKey, APIKey, postPath, null);

        odr = JsonHelper.JsonDeserialize <OoyalaData.Labels.OoyalaLabelDataResult>(json);
        list.AddRange(odr.items);
        return(list);
    }
Example #9
0
    /// <summary>
    /// Update Label Settings in Ooyala based on given Label ID by using V2 API
    /// </summary>
    /// <param name="SecretKey">Backlot Secret Key</param>
    /// <param name="APIKey">Backlot API Key</param>
    /// <param name="id">Label ID</param>
    /// <param name="hs">Label Settings in Hashtable Format</param>
    public static string EditLabel(string SecretKey, string APIKey, string id, Hashtable hs)
    {
        var res = OoyalaAPI.patch(SecretKey, APIKey, pathLabel + "/" + id, hs);

        if (res != null)
        {
            return(res["name"].ToString());
        }
        else
        {
            return(null);
        }
    }
Example #10
0
    /// <summary>
    /// Add a New Label by using V2 API
    /// </summary>
    /// <param name="SecretKey">Backlot Secret Key</param>
    /// <param name="APIKey">Backlot API Key</param>
    /// <param name="hs">Label Settings in Hashtable Format</param>
    public static string AddNewLabel(string SecretKey, string APIKey, Hashtable hs)
    {
        var res = OoyalaAPI.post(SecretKey, APIKey, pathLabel, hs);

        if (res != null)
        {
            return(res["name"].ToString());
        }
        else
        {
            return(null);
        }
    }
Example #11
0
    /// <summary>
    /// Used to create New Media Asset by using V2 API
    /// </summary>
    /// <param name="SecretKey"></param>
    /// <param name="APIKey"></param>
    /// <param name="hs"></param>
    /// <returns></returns>
    public static string NewMediaAsset(string SecretKey, string APIKey, Hashtable hs)
    {
        var res = OoyalaAPI.post(SecretKey, APIKey, pathAsset, hs);

        if (res != null)
        {
            return(res["embed_code"].ToString());
        }
        else
        {
            return(null);
        }
    }
Example #12
0
    /// <summary>
    /// Apply Standard Metadata to Media asset based on Asset ID by using V2 API
    /// </summary>
    /// <param name="SecretKey">Backlot Secret Key</param>
    /// <param name="APIKey">Backlot API Key</param>
    /// <param name="id">Media Asset ID</param>
    /// <param name="hs">Standard Metadata in Hashtable Format</param>
    public static string ApplyMetadataToAssets(string SecretKey, string APIKey, String id, Hashtable hs)
    {
        string postPath = postPath = string.Format(formatAsset, id);
        var    res      = OoyalaAPI.patch(SecretKey, APIKey, postPath, hs);

        if (res != null)
        {
            return(res["name"].ToString());
        }
        else
        {
            return(null);
        }
    }
Example #13
0
    /// <summary>
    /// Update Player Settings in Ooyala using V2 API
    /// </summary>
    /// <param name="SecretKey">Backlot Secret Key</param>
    /// <param name="APIKey">Backlot API Key</param>
    /// <param name="player">Media Player Object</param>
    public static string EditPlayer(string SecretKey, string APIKey, OoyalaData.Players.Item player)
    {
        string    jsonstr = JsonHelper.JsonSerializer <OoyalaData.Players.Item>(player);
        Hashtable hs      = (Hashtable)JSON.JsonDecode(jsonstr);
        var       res     = OoyalaAPI.patch(SecretKey, APIKey, pathPlayer + "/" + player.id, hs);

        if (res != null)
        {
            return(res["name"].ToString());
        }
        else
        {
            return(null);
        }
    }
Example #14
0
    /// <summary>
    /// Add a New Media Player with Player Name as NewPlayer using V2 API
    /// </summary>
    /// <param name="SecretKey">Backlot Secret Key</param>
    /// <param name="APIKey">Backlot API Key</param>
    public static string AddNewPlayer(string SecretKey, string APIKey)
    {
        Hashtable hs = new Hashtable();

        hs.Add("name", "New Player");
        var res = OoyalaAPI.post(SecretKey, APIKey, pathPlayer, hs);

        if (res != null)
        {
            return(res["name"].ToString());
        }
        else
        {
            return(null);
        }
    }
Example #15
0
    /// <summary>
    /// Get Media Assets based on Live Status by using V2 API
    /// </summary>
    /// <param name="SecretKey">Backlot Secret Key</param>
    /// <param name="APIKey">Backlot API Key</param>
    /// <returns>List of Media Assets</returns>
    public static List <OoyalaData.Assets.Item> GetLiveAssets(string SecretKey, string APIKey)
    {
        var list = new List <OoyalaData.Assets.Item>();

        OoyalaData.Assets.OoyalaAssetDataResult odr = new OoyalaData.Assets.OoyalaAssetDataResult();

        System.Collections.Generic.Dictionary <string, string> parameters = new System.Collections.Generic.Dictionary <string, string>();
        string expireValue = DateTime.Now.AddHours(1).Ticks.ToString();

        parameters.Add("api_key", APIKey);
        parameters.Add("expires", expireValue);
        parameters.Add("where", string.Format(formatSearch, "status", "live"));
        parameters.Add("orderby", "name");
        string json = OoyalaAPI.getJSON(SecretKey, APIKey, pathAsset, parameters);

        odr = JsonHelper.JsonDeserialize <OoyalaData.Assets.OoyalaAssetDataResult>(json);
        list.AddRange(odr.items);
        return(list);
    }
Example #16
0
    /// <summary>
    /// Get Media Assets based on Search Creteria and Page Limit by using V2 API
    /// </summary>
    /// <param name="SecretKey">Backlot Secret Key</param>
    /// <param name="APIKey">Backlot API Key</param>
    /// <param name="limit">No of Media Asset needs to be return</param>
    /// <param name="searchBy">Search By String(e.g., Name, Description, Label, Status)</param>
    /// <param name="searchText">Search Text</param>
    /// <param name="pageToken">Next Page Token, it is used to support Previous, Next Page Results</param>
    /// <returns>List of Media Assets</returns>
    public static OoyalaData.Assets.OoyalaAssetDataResult GetLimitedAssets(string SecretKey, string APIKey, int limit, string searchBy, string searchText, string pageToken, bool IncludeMetadata, bool IncludeLabels)
    {
        System.Collections.Generic.Dictionary <string, string> parameters = new System.Collections.Generic.Dictionary <string, string>();
        string expireValue = DateTime.Now.AddHours(1).Ticks.ToString();

        parameters.Add("api_key", APIKey);
        parameters.Add("expires", expireValue);
        parameters.Add("limit", limit.ToString());

        if (IncludeLabels && IncludeMetadata)
        {
            parameters.Add("include", "metadata,labels");
        }
        else if (IncludeLabels && !IncludeMetadata)
        {
            parameters.Add("include", "metadata");
        }
        else if (!IncludeLabels && IncludeMetadata)
        {
            parameters.Add("include", "labels");
        }

        if (searchBy.Contains("metadata")) //for metadata when searchtext is empty value search
        {
            parameters.Add("where", string.Format(formatSearch, searchBy, searchText));
        }
        else if (!string.IsNullOrEmpty(searchText))
        {
            parameters.Add("where", string.Format(formatSearch, searchBy, searchText));
        }

        if (!string.IsNullOrEmpty(pageToken))
        {
            parameters.Add("page_token", pageToken);
        }

        parameters.Add("orderby", "name");
        string json = OoyalaAPI.getJSON(SecretKey, APIKey, pathAsset, parameters);

        return(JsonHelper.JsonDeserialize <OoyalaData.Assets.OoyalaAssetDataResult>(json));
    }
Example #17
0
    /// <summary>
    /// Delete Media Asset based on Asset ID using V2 API
    /// </summary>
    /// <param name="SecretKey">Backlot Secret Key</param>
    /// <param name="APIKey">Backlot API Key</param>
    /// <param name="id">Player ID</param>
    public static bool DeleteMediaAsset(string SecretKey, string APIKey, string id)
    {
        var res = OoyalaAPI.delete(SecretKey, APIKey, pathAsset + "/" + id);

        return(res);
    }
Example #18
0
 /// <summary>
 /// Remove Labels from Media Assets by using V2 API
 /// </summary>
 /// <param name="SecretKey">Backlot Secret Key</param>
 /// <param name="APIKey">Backlot API Key</param>
 /// <param name="id">Media Asset ID</param>
 public static void DeleteLabelsFromAssets(string SecretKey, string APIKey, String id)
 {
     OoyalaAPI.delete(SecretKey, APIKey, string.Format(formatLabels, id));
 }
Example #19
0
    /// <summary>
    /// Apply Custom Metadata to Media asset based on Asset ID by using V2 API
    /// </summary>
    /// <param name="SecretKey">Backlot Secret Key</param>
    /// <param name="APIKey">Backlot API Key</param>
    /// <param name="id">Media Asset ID</param>
    /// <param name="hs">Custom Metadata in Hashtable Format</param>
    public static void ApplyCustomMetadataToAssets(string SecretKey, string APIKey, String id, Hashtable hs)
    {
        string postPath = postPath = string.Format(formatMetadata, id);

        OoyalaAPI.put(SecretKey, APIKey, postPath, hs);
    }
Example #20
0
    /// <summary>
    /// Get Custom Metadata of given Asset ID by using V2 API
    /// </summary>
    /// <param name="SecretKey">Backlot Secret Key</param>
    /// <param name="APIKey">Backlot API Key</param>
    /// <param name="id">Media Asset ID</param>
    /// <returns>Custom Metadata of given Asset ID</returns>
    public static Hashtable GetAssetCustomMetadata(string SecretKey, string APIKey, String asset_id)
    {
        string postPath = postPath = string.Format(formatMetadata, asset_id);

        return(OoyalaAPI.get(SecretKey, APIKey, postPath, null));
    }
Example #21
0
    /// <summary>
    /// Delete Media Player based on Player ID using V2 API
    /// </summary>
    /// <param name="SecretKey">Backlot Secret Key</param>
    /// <param name="APIKey">Backlot API Key</param>
    /// <param name="id">Player ID</param>
    public static bool DeletePlayer(string SecretKey, string APIKey, string id)
    {
        var res = OoyalaAPI.delete(SecretKey, APIKey, pathPlayer + "/" + id);

        return(res);
    }
Example #22
0
        static void Main(string[] args)
        {
            // Create Download Directory
            if (!Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + "Downloads"))
            {
                Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + "Downloads");
                Console.WriteLine("Download Directory Created");
            }
            // Create Progress file
            if (!File.Exists(AppDomain.CurrentDomain.BaseDirectory + "progress.csv"))
            {
                using (StreamWriter file = File.CreateText(AppDomain.CurrentDomain.BaseDirectory + "progress.csv"))
                {
                    file.WriteLine("embed_code,original_file_name,name,description");
                }
                Console.WriteLine("CSV Created");
            }

            // Connect to OoyalaAPI
            OoyalaAPI api = new OoyalaAPI(apiKey, secretKey);
            Dictionary <String, String> parameters = new Dictionary <String, String>();

            parameters = Settings(parameters);

            bool NextPage = true;

            while (NextPage)
            {
                string OoyalaResponce = string.Empty;
                try
                {
                    OoyalaResponce = JsonConvert.SerializeObject(api.get("assets", parameters));
                    if (JObject.Parse(OoyalaResponce) == null)
                    {
                        throw new Exception();
                    }
                }
                catch (Exception)
                {
                    Console.WriteLine(DateTime.Now + " Probably a Request Expired Error. Resetting Pramaters, waiting 60 seconds and re Sending");
                    System.Threading.Thread.Sleep(60000);
                    parameters     = Settings(parameters);
                    OoyalaResponce = JsonConvert.SerializeObject(api.get("assets", parameters));
                }
                parameters.Clear();

                JObject o = JObject.Parse(OoyalaResponce);
                foreach (var item in o["items"])
                {
                    string filename = item["original_file_name"].ToString();
                    filename = filename.Replace(@"\", "");
                    filename = filename.Replace(@":", "");

                    if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + "Downloads\\" + filename))
                    {
                        Console.WriteLine("File Existed " + filename);
                    }
                    else
                    {
                        parameters.Clear();
                        string videoDownloadLinks = string.Empty;
                        try
                        {
                            videoDownloadLinks = JsonConvert.SerializeObject(api.get("assets/" + item["embed_code"] + "/streams", parameters));
                            if (JArray.Parse(videoDownloadLinks) == null)
                            {
                                throw new Exception();
                            }
                        }
                        catch (Exception)
                        {
                            Console.WriteLine(DateTime.Now + " Probably a 'Request limit exceeded' error, waiting 60 seonds to try again");
                            System.Threading.Thread.Sleep(60000);
                            videoDownloadLinks = JsonConvert.SerializeObject(api.get("assets/" + item["embed_code"] + "/streams", parameters));
                        }

                        JArray videoDownloadResponce = JArray.Parse(videoDownloadLinks);
                        foreach (var videoSource in videoDownloadResponce)
                        {
                            if (videoSource["is_source"].ToString() == "True")
                            {
                                OoyalaFileDownload(videoSource["url"].ToString(), filename);
                                using (System.IO.StreamWriter file = new System.IO.StreamWriter(AppDomain.CurrentDomain.BaseDirectory + "progress.csv", true))
                                {
                                    file.WriteLine(item["embed_code"] + "," + item["original_file_name"] + "," + item["name"] + "," + item["description"]);
                                }
                            }
                        }
                    }
                }

                if (o["next_page"] != null)
                {
                    NameValueCollection qscoll = HttpUtility.ParseQueryString(CleanNextpage(o["next_page"].ToString()));

                    foreach (var k in qscoll.AllKeys)
                    {
                        parameters.Add(k, qscoll[k]);
                    }
                    NextPage = true;
                }
                else
                {
                    NextPage = false;
                }
            }
        }
Example #23
0
    /// <summary>
    /// Delete available Label based on Lable ID by using V2 API
    /// </summary>
    /// <param name="SecretKey">Backlot Secret Key</param>
    /// <param name="APIKey">Backlot API Key</param>
    /// <param name="id">Label ID</param>
    public static bool DeleteLabel(string SecretKey, string APIKey, string id)
    {
        var res = OoyalaAPI.delete(SecretKey, APIKey, pathLabel + "/" + id);

        return(res);
    }