Return to the Panopto API index page
Something we’ve struggled with over the years is how to handle our retention policy. There are a lot of videos in a lot of places and once you delete a video it is exceptionally hard to get it back.
The following code follows on from the looping code on 203. It doesn’t delete any files, but instead renames them. The idea is as follows
- Find all videos made that are due to be deleted due to the retention policy
- Rename all the videos so that video owners can check which files will be deleted (and allow them to remove the deletion warning
- Search using the main Panopto website for the deletion warning on the day in the warning, select all and delete
Here is the code
1 2 |
DateTime latestDateToMarkForDeletion = new DateTime(2010, 12, 31); DateTime dateSessionWillBeDeleted = new DateTime(2014, 06, 12); |
These are the a) The last date that is suitable to be found and b) the date you are planning on deleting the video files.
These dates are used in
1 |
PanoptoSessionManagement.ListSessionsRequest request = new PanoptoSessionManagement.ListSessionsRequest { Pagination = pagination, EndDate = latestDateToMarkForDeletion }; |
Pro Tip: If your have a rolling retention policy (18 months, not “every summer”) then useĀ StartDate to ensure you don’t constantly mark an old video for deletion that should be kept.
Then we add this code to our results
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
foreach (Session session in response.Results) { Console.WriteLine(session.Id + ": " + session.Name); if (!session.Name.Contains("[DELETION WARNING:")) { Console.WriteLine(" will marked for deleted on " + dateSessionWillBeDeleted.ToShortDateString()); sessionMgr.UpdateSessionName(sessionAuthInfo, session.Id, session.Name + " [DELETION WARNING: Session will be deleted on " + dateSessionWillBeDeleted.ToShortDateString() + "] "); } else { Console.WriteLine(" already contains a deletion warning"); } } |
The code is very simple. It checks to see if the warning is already placed on the video, and if it isn’t it will add the text [DELETION WARNING: Session will be deleted on xx/xx/xxxx] to the end of the title
Running the code will rename the video files
Then when the date comes, just search for the deletion warning, select all and delete. If an academic wants to keep the video, they simply need to rename the session to remove the warning.
Full code below
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net; using System.Security.Cryptography.X509Certificates; using ConsolePanoptoAPI.PanoptoAccessManagement; using ConsolePanoptoAPI.PanoptoAuth; using ConsolePanoptoAPI.PanoptoRemoteRecorderManagement; using ConsolePanoptoAPI.PanoptoSessionManagement; using ConsolePanoptoAPI.PanoptoUsageReporting; using ConsolePanoptoAPI.PanoptoUserManagement; // ANY NEW NAMESPACES SHOULD BE ADDED HERE // END OF NAMESPACES namespace ConsolePanoptoAPI { class Program { static bool hasBeenInitialized = false; static void Main(string[] args) { // PUT YOUR AUTHENTICATION DETAILS HERE PanoptoSessionManagement.AuthenticationInfo sessionAuthInfo = new PanoptoSessionManagement.AuthenticationInfo() { UserKey = "api", Password = "s2ezupajePhasaP5" }; // END OF AUTHENTICATION DETAILS // START WRITING CODE HERE bool lastPage = false; int resultsPerPage = 5; int page = 0; DateTime latestDateToMarkForDeletion = new DateTime(2010, 12, 31); DateTime dateSessionWillBeDeleted = new DateTime(2014, 06, 12); while(!lastPage) { PanoptoSessionManagement.Pagination pagination = new PanoptoSessionManagement.Pagination { MaxNumberResults = resultsPerPage, PageNumber = page }; PanoptoSessionManagement.ListSessionsRequest request = new PanoptoSessionManagement.ListSessionsRequest { Pagination = pagination, EndDate = latestDateToMarkForDeletion }; ISessionManagement sessionMgr = new SessionManagementClient(); ListSessionsResponse response = sessionMgr.GetSessionsList(sessionAuthInfo, request, null); if (resultsPerPage * (page + 1) >= response.TotalNumberResults) { lastPage = true; Console.WriteLine("There are {0} results, at {1} results per page and on page {2} means we are on the last page", response.TotalNumberResults, resultsPerPage, page + 1); } else { Console.WriteLine("There are {0} results, at {1} results per page and on page {2} means there are more pages to loop through", response.TotalNumberResults, resultsPerPage, page + 1); } if (response.Results.Length > 0) { foreach (Session session in response.Results) { Console.WriteLine(session.Id + ": " + session.Name); if (!session.Name.Contains("[DELETION WARNING:")) { Console.WriteLine(" will marked for deleted on " + dateSessionWillBeDeleted.ToShortDateString()); sessionMgr.UpdateSessionName(sessionAuthInfo, session.Id, session.Name + " [DELETION WARNING: Session will be deleted on " + dateSessionWillBeDeleted.ToShortDateString() + "] "); } else { Console.WriteLine(" already contains a deletion warning"); } } } else { Console.WriteLine("No sessions found"); } page++; } // STOP WRITING CODE HERE Console.WriteLine("Press Enter to exit"); Console.ReadLine(); } /// /// Ensures that our custom certificate validation has been applied /// public static void EnsureCertificateValidation() { if (!hasBeenInitialized) { ServicePointManager.ServerCertificateValidationCallback += new System.Net.Security.RemoteCertificateValidationCallback(CustomCertificateValidation); hasBeenInitialized = true; } } /// /// Ensures that server certificate is authenticated /// private static bool CustomCertificateValidation(object sender, X509Certificate cert, X509Chain chain, System.Net.Security.SslPolicyErrors error) { return true; } /// /// Creates an auth code. Used when we want to authenticate a user, but don't know their password. /// ///The instance name as set in Panopto > System > Identity Providors ///Username as defined by Panopto ///The full server name as defined by Panopto > System > Settings > General site settings > Web server FQDN ///The key produced through Panopto > System > Identity Providors /// private static string CreateAuthCode(string identityProviderInstanceName, string username, string serverFqdn, string applicationKey) { string payload = identityProviderInstanceName + "\\" + username + "@" + serverFqdn.ToLower() + "|" + applicationKey.ToLower(); var data = Encoding.ASCII.GetBytes(payload); var hashData = new System.Security.Cryptography.SHA1Managed().ComputeHash(data); var hash = string.Empty; foreach (var b in hashData) hash += b.ToString("X2"); return hash; } } } |
Return to the Panopto API index page