diff --git a/CDN-Video-Uploader.csproj.user b/CDN-Video-Uploader.csproj.user index c62d3da..5031ba2 100644 --- a/CDN-Video-Uploader.csproj.user +++ b/CDN-Video-Uploader.csproj.user @@ -8,6 +8,9 @@ Form + + Form + Form diff --git a/Forms/FormShowUrls.Designer.cs b/Forms/FormShowUrls.Designer.cs new file mode 100644 index 0000000..59d0259 --- /dev/null +++ b/Forms/FormShowUrls.Designer.cs @@ -0,0 +1,95 @@ + +namespace CDN_Video_Uploader.Forms +{ + partial class FormShowUrls + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.textBoxUrls = new System.Windows.Forms.TextBox(); + this.buttonClose = new System.Windows.Forms.Button(); + this.label1 = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // textBoxUrls + // + this.textBoxUrls.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.textBoxUrls.Location = new System.Drawing.Point(7, 28); + this.textBoxUrls.Multiline = true; + this.textBoxUrls.Name = "textBoxUrls"; + this.textBoxUrls.Size = new System.Drawing.Size(1298, 598); + this.textBoxUrls.TabIndex = 0; + // + // buttonClose + // + this.buttonClose.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonClose.DialogResult = System.Windows.Forms.DialogResult.OK; + this.buttonClose.Font = new System.Drawing.Font("Microsoft Sans Serif", 10.2F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); + this.buttonClose.Image = global::CDN_Video_Uploader.Properties.Resources.cancel_button_icon; + this.buttonClose.Location = new System.Drawing.Point(1184, 638); + this.buttonClose.Name = "buttonClose"; + this.buttonClose.Size = new System.Drawing.Size(121, 44); + this.buttonClose.TabIndex = 10; + this.buttonClose.Text = " Close"; + this.buttonClose.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + this.buttonClose.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText; + this.buttonClose.UseVisualStyleBackColor = true; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(4, 6); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(173, 17); + this.label1.TabIndex = 11; + this.label1.Text = "URLs at the CDN network:"; + // + // FormShowUrls + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1312, 693); + this.Controls.Add(this.label1); + this.Controls.Add(this.buttonClose); + this.Controls.Add(this.textBoxUrls); + this.MinimizeBox = false; + this.Name = "FormShowUrls"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "URLs at the CDN"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.TextBox textBoxUrls; + private System.Windows.Forms.Button buttonClose; + private System.Windows.Forms.Label label1; + } +} \ No newline at end of file diff --git a/Forms/FormShowUrls.cs b/Forms/FormShowUrls.cs new file mode 100644 index 0000000..a27b27d --- /dev/null +++ b/Forms/FormShowUrls.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Windows.Forms; + +namespace CDN_Video_Uploader.Forms +{ + public partial class FormShowUrls : Form + { + public FormShowUrls() + { + InitializeComponent(); + } + + public FormShowUrls(IEnumerable urls) : this() + { + this.textBoxUrls.Text = string.Join(Environment.NewLine, urls); + } + } +} diff --git a/Forms/FormShowUrls.resx b/Forms/FormShowUrls.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Forms/FormShowUrls.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Forms/FormVideoUploader.Designer.cs b/Forms/FormVideoUploader.Designer.cs index 2567ee2..9e3452d 100644 --- a/Forms/FormVideoUploader.Designer.cs +++ b/Forms/FormVideoUploader.Designer.cs @@ -30,16 +30,15 @@ private void InitializeComponent() { System.Windows.Forms.Label labelDragAndDropFiles; System.Windows.Forms.Label labelOr; - System.Windows.Forms.PictureBox pictureBoxUploadImage; System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle(); System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle(); System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle(); System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle4 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.PictureBox pictureBoxUploadImage; this.labelFTP = new System.Windows.Forms.Label(); this.textBoxFTPPath = new System.Windows.Forms.TextBox(); this.labelQueue = new System.Windows.Forms.Label(); this.panelUploadBox = new System.Windows.Forms.Panel(); - this.buttonChooseFilesToUpload = new System.Windows.Forms.Button(); this.dataGridViewFTPFolders = new System.Windows.Forms.DataGridView(); this.ColumnFolderName = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.ColumnFolderDate = new System.Windows.Forms.DataGridViewTextBoxColumn(); @@ -55,24 +54,26 @@ private void InitializeComponent() this.ColumnProgress = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.ColumnDetails = new System.Windows.Forms.DataGridViewButtonColumn(); this.dataGridViewCompletedJobs = new System.Windows.Forms.DataGridView(); - this.buttonSettings = new System.Windows.Forms.Button(); - this.buttonFTPGo = new System.Windows.Forms.Button(); - this.buttonFTPUp = new System.Windows.Forms.Button(); - this.buttonFTPConnect = new System.Windows.Forms.Button(); this.ColumnCompletedJob = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.ColumnResult = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.ColumnExecutionTime = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.ColumnVideoURL = new System.Windows.Forms.DataGridViewLinkColumn(); this.ColumnCompletedJobDetails = new System.Windows.Forms.DataGridViewButtonColumn(); + this.buttonShowCDNUrls = new System.Windows.Forms.Button(); + this.buttonSettings = new System.Windows.Forms.Button(); + this.buttonFTPGo = new System.Windows.Forms.Button(); + this.buttonChooseFilesToUpload = new System.Windows.Forms.Button(); + this.buttonFTPUp = new System.Windows.Forms.Button(); + this.buttonFTPConnect = new System.Windows.Forms.Button(); labelDragAndDropFiles = new System.Windows.Forms.Label(); labelOr = new System.Windows.Forms.Label(); pictureBoxUploadImage = new System.Windows.Forms.PictureBox(); - ((System.ComponentModel.ISupportInitialize)(pictureBoxUploadImage)).BeginInit(); this.panelUploadBox.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridViewFTPFolders)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGridViewFTPFiles)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGridViewActiveJobs)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGridViewCompletedJobs)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(pictureBoxUploadImage)).BeginInit(); this.SuspendLayout(); // // labelDragAndDropFiles @@ -95,19 +96,6 @@ private void InitializeComponent() labelOr.Text = "or"; labelOr.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // - // pictureBoxUploadImage - // - pictureBoxUploadImage.ErrorImage = null; - pictureBoxUploadImage.Image = global::CDN_Video_Uploader.Properties.Resources.upload_icon; - pictureBoxUploadImage.InitialImage = null; - pictureBoxUploadImage.Location = new System.Drawing.Point(12, 12); - pictureBoxUploadImage.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); - pictureBoxUploadImage.Name = "pictureBoxUploadImage"; - pictureBoxUploadImage.Size = new System.Drawing.Size(77, 72); - pictureBoxUploadImage.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; - pictureBoxUploadImage.TabIndex = 1; - pictureBoxUploadImage.TabStop = false; - // // labelFTP // this.labelFTP.AutoSize = true; @@ -157,20 +145,6 @@ private void InitializeComponent() this.panelUploadBox.DragDrop += new System.Windows.Forms.DragEventHandler(this.panelUploadBox_DragDrop); this.panelUploadBox.DragEnter += new System.Windows.Forms.DragEventHandler(this.panelUploadBox_DragEnter); // - // buttonChooseFilesToUpload - // - this.buttonChooseFilesToUpload.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); - this.buttonChooseFilesToUpload.Image = global::CDN_Video_Uploader.Properties.Resources.browse_icon_20px; - this.buttonChooseFilesToUpload.Location = new System.Drawing.Point(253, 43); - this.buttonChooseFilesToUpload.Name = "buttonChooseFilesToUpload"; - this.buttonChooseFilesToUpload.Size = new System.Drawing.Size(220, 40); - this.buttonChooseFilesToUpload.TabIndex = 2; - this.buttonChooseFilesToUpload.Text = " Choose Files to Upload ..."; - this.buttonChooseFilesToUpload.TextAlign = System.Drawing.ContentAlignment.MiddleRight; - this.buttonChooseFilesToUpload.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText; - this.buttonChooseFilesToUpload.UseVisualStyleBackColor = true; - this.buttonChooseFilesToUpload.Click += new System.EventHandler(this.buttonChooseFilesToUpload_Click); - // // dataGridViewFTPFolders // this.dataGridViewFTPFolders.AllowUserToDeleteRows = false; @@ -413,6 +387,69 @@ private void InitializeComponent() this.dataGridViewCompletedJobs.Text = "dataGridView1"; this.dataGridViewCompletedJobs.CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridViewCompletedJobs_CellClick); // + // ColumnCompletedJob + // + this.ColumnCompletedJob.DataPropertyName = "Description"; + this.ColumnCompletedJob.FillWeight = 191.2675F; + this.ColumnCompletedJob.HeaderText = "Completed Job"; + this.ColumnCompletedJob.MinimumWidth = 6; + this.ColumnCompletedJob.Name = "ColumnCompletedJob"; + this.ColumnCompletedJob.ReadOnly = true; + // + // ColumnResult + // + this.ColumnResult.DataPropertyName = "StateAsText"; + this.ColumnResult.FillWeight = 80F; + this.ColumnResult.HeaderText = "Result"; + this.ColumnResult.MinimumWidth = 6; + this.ColumnResult.Name = "ColumnResult"; + this.ColumnResult.ReadOnly = true; + // + // ColumnExecutionTime + // + this.ColumnExecutionTime.DataPropertyName = "ExecutionTimeAsText"; + this.ColumnExecutionTime.FillWeight = 35F; + this.ColumnExecutionTime.HeaderText = "Time"; + this.ColumnExecutionTime.MinimumWidth = 6; + this.ColumnExecutionTime.Name = "ColumnExecutionTime"; + // + // ColumnVideoURL + // + this.ColumnVideoURL.DataPropertyName = "VideoURL"; + this.ColumnVideoURL.FillWeight = 110F; + this.ColumnVideoURL.HeaderText = "Video URL"; + this.ColumnVideoURL.MinimumWidth = 6; + this.ColumnVideoURL.Name = "ColumnVideoURL"; + this.ColumnVideoURL.ReadOnly = true; + this.ColumnVideoURL.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic; + this.ColumnVideoURL.TrackVisitedState = false; + // + // ColumnCompletedJobDetails + // + this.ColumnCompletedJobDetails.FillWeight = 40F; + this.ColumnCompletedJobDetails.HeaderText = "Details"; + this.ColumnCompletedJobDetails.MinimumWidth = 6; + this.ColumnCompletedJobDetails.Name = "ColumnCompletedJobDetails"; + this.ColumnCompletedJobDetails.Resizable = System.Windows.Forms.DataGridViewTriState.True; + this.ColumnCompletedJobDetails.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic; + this.ColumnCompletedJobDetails.Text = "View"; + this.ColumnCompletedJobDetails.UseColumnTextForButtonValue = true; + // + // buttonShowCDNUrls + // + this.buttonShowCDNUrls.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); + this.buttonShowCDNUrls.Image = global::CDN_Video_Uploader.Properties.Resources.http_icon_23px; + this.buttonShowCDNUrls.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft; + this.buttonShowCDNUrls.Location = new System.Drawing.Point(355, 4); + this.buttonShowCDNUrls.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonShowCDNUrls.Name = "buttonShowCDNUrls"; + this.buttonShowCDNUrls.Size = new System.Drawing.Size(161, 26); + this.buttonShowCDNUrls.TabIndex = 15; + this.buttonShowCDNUrls.Text = " CDN URLs"; + this.buttonShowCDNUrls.TextImageRelation = System.Windows.Forms.TextImageRelation.TextBeforeImage; + this.buttonShowCDNUrls.UseVisualStyleBackColor = true; + this.buttonShowCDNUrls.Click += new System.EventHandler(this.buttonShowCDNUrls_Click); + // // buttonSettings // this.buttonSettings.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); @@ -443,6 +480,33 @@ private void InitializeComponent() this.buttonFTPGo.UseVisualStyleBackColor = true; this.buttonFTPGo.Click += new System.EventHandler(this.buttonFTPGo_Click); // + // buttonChooseFilesToUpload + // + this.buttonChooseFilesToUpload.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); + this.buttonChooseFilesToUpload.Image = global::CDN_Video_Uploader.Properties.Resources.browse_icon_20px; + this.buttonChooseFilesToUpload.Location = new System.Drawing.Point(253, 43); + this.buttonChooseFilesToUpload.Name = "buttonChooseFilesToUpload"; + this.buttonChooseFilesToUpload.Size = new System.Drawing.Size(220, 40); + this.buttonChooseFilesToUpload.TabIndex = 2; + this.buttonChooseFilesToUpload.Text = " Choose Files to Upload ..."; + this.buttonChooseFilesToUpload.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + this.buttonChooseFilesToUpload.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText; + this.buttonChooseFilesToUpload.UseVisualStyleBackColor = true; + this.buttonChooseFilesToUpload.Click += new System.EventHandler(this.buttonChooseFilesToUpload_Click); + // + // pictureBoxUploadImage + // + pictureBoxUploadImage.ErrorImage = null; + pictureBoxUploadImage.Image = global::CDN_Video_Uploader.Properties.Resources.upload_icon; + pictureBoxUploadImage.InitialImage = null; + pictureBoxUploadImage.Location = new System.Drawing.Point(12, 12); + pictureBoxUploadImage.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + pictureBoxUploadImage.Name = "pictureBoxUploadImage"; + pictureBoxUploadImage.Size = new System.Drawing.Size(77, 72); + pictureBoxUploadImage.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; + pictureBoxUploadImage.TabIndex = 1; + pictureBoxUploadImage.TabStop = false; + // // buttonFTPUp // this.buttonFTPUp.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); @@ -470,58 +534,11 @@ private void InitializeComponent() this.buttonFTPConnect.UseVisualStyleBackColor = true; this.buttonFTPConnect.Click += new System.EventHandler(this.buttonFTPConnect_Click); // - // ColumnCompletedJob - // - this.ColumnCompletedJob.DataPropertyName = "Description"; - this.ColumnCompletedJob.FillWeight = 191.2675F; - this.ColumnCompletedJob.HeaderText = "Completed Job"; - this.ColumnCompletedJob.MinimumWidth = 6; - this.ColumnCompletedJob.Name = "ColumnCompletedJob"; - this.ColumnCompletedJob.ReadOnly = true; - // - // ColumnResult - // - this.ColumnResult.DataPropertyName = "StateAsText"; - this.ColumnResult.FillWeight = 80F; - this.ColumnResult.HeaderText = "Result"; - this.ColumnResult.MinimumWidth = 6; - this.ColumnResult.Name = "ColumnResult"; - this.ColumnResult.ReadOnly = true; - // - // ColumnExecutionTime - // - this.ColumnExecutionTime.DataPropertyName = "ExecutionTimeAsText"; - this.ColumnExecutionTime.FillWeight = 35F; - this.ColumnExecutionTime.HeaderText = "Time"; - this.ColumnExecutionTime.MinimumWidth = 6; - this.ColumnExecutionTime.Name = "ColumnExecutionTime"; - // - // ColumnVideoURL - // - this.ColumnVideoURL.DataPropertyName = "VideoURL"; - this.ColumnVideoURL.FillWeight = 110F; - this.ColumnVideoURL.HeaderText = "Video URL"; - this.ColumnVideoURL.MinimumWidth = 6; - this.ColumnVideoURL.Name = "ColumnVideoURL"; - this.ColumnVideoURL.ReadOnly = true; - this.ColumnVideoURL.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic; - this.ColumnVideoURL.TrackVisitedState = false; - // - // ColumnCompletedJobDetails - // - this.ColumnCompletedJobDetails.FillWeight = 40F; - this.ColumnCompletedJobDetails.HeaderText = "Details"; - this.ColumnCompletedJobDetails.MinimumWidth = 6; - this.ColumnCompletedJobDetails.Name = "ColumnCompletedJobDetails"; - this.ColumnCompletedJobDetails.Resizable = System.Windows.Forms.DataGridViewTriState.True; - this.ColumnCompletedJobDetails.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic; - this.ColumnCompletedJobDetails.Text = "View"; - this.ColumnCompletedJobDetails.UseColumnTextForButtonValue = true; - // // FormVideoUploader // this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; this.ClientSize = new System.Drawing.Size(1370, 754); + this.Controls.Add(this.buttonShowCDNUrls); this.Controls.Add(this.buttonSettings); this.Controls.Add(this.dataGridViewCompletedJobs); this.Controls.Add(this.dataGridViewActiveJobs); @@ -543,12 +560,12 @@ private void InitializeComponent() this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.FormVideoUploader_FormClosing); this.Load += new System.EventHandler(this.FormVideoUploader_Load); this.Shown += new System.EventHandler(this.FormVideoUploader_Shown); - ((System.ComponentModel.ISupportInitialize)(pictureBoxUploadImage)).EndInit(); this.panelUploadBox.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.dataGridViewFTPFolders)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGridViewFTPFiles)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGridViewActiveJobs)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGridViewCompletedJobs)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(pictureBoxUploadImage)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -585,6 +602,7 @@ private void InitializeComponent() private System.Windows.Forms.DataGridViewTextBoxColumn ColumnExecutionTime; private System.Windows.Forms.DataGridViewLinkColumn ColumnVideoURL; private System.Windows.Forms.DataGridViewButtonColumn ColumnCompletedJobDetails; + private System.Windows.Forms.Button buttonShowCDNUrls; } } diff --git a/Forms/FormVideoUploader.cs b/Forms/FormVideoUploader.cs index c2459b8..3f7639e 100644 --- a/Forms/FormVideoUploader.cs +++ b/Forms/FormVideoUploader.cs @@ -9,6 +9,7 @@ using System.Diagnostics; using CDN_Video_Uploader.Forms; using System.ComponentModel; +using System.Text.RegularExpressions; namespace CDN_Video_Uploader { @@ -278,7 +279,7 @@ private void AppendFileForProcessing(string fileName) } string ftpPath = this.textBoxFTPPath.Text; - string hlsVideoURL = GetVideoUrl(ftpPath, fileInfo.Name); + string hlsVideoURL = GetHlsVideoUrl(ftpPath, fileInfo.Name); if (hlsVideoURL == null) { LogError($"Cannot find video URL pattern at the CDN for the current FTP path {ftpPath}. Choose an FTP folder first."); @@ -299,7 +300,15 @@ private void AppendFileForProcessing(string fileName) this.activeJobsQueue.Add(job); } - private string GetVideoUrl(string ftpPath, string shortFileName) + private string GetHlsVideoUrl(string ftpPath, string shortFileName) + { + string profilesList = "," + GetVideoProfileNames().Join(",") + ","; + string fileNameWithoutExt = Path.GetFileNameWithoutExtension(shortFileName); + return GetHlsVideoUrl(ftpPath, fileNameWithoutExt, profilesList); + } + + private string GetHlsVideoUrl( + string ftpPath, string videoFilePrefix, string profilesList) { if (!ftpPath.EndsWith("/")) ftpPath += "/"; @@ -311,10 +320,9 @@ private string GetVideoUrl(string ftpPath, string shortFileName) if (ftpPath.StartsWith(ftpRootFolder)) { string ftpPathWithoutRoot = ftpPath.Remove(0, ftpRootFolder.Length); - string fileNameWithoutExt = Path.GetFileNameWithoutExtension(shortFileName); - string profilesList = "," + GetVideoProfileNames().Join(",") + ","; + string hlsVideoURL = videoUrlPattern - .Replace("{input}", ftpPathWithoutRoot + fileNameWithoutExt) + .Replace("{input}", ftpPathWithoutRoot + videoFilePrefix) .Replace("{profiles}", profilesList); return hlsVideoURL; } @@ -322,6 +330,27 @@ private string GetVideoUrl(string ftpPath, string shortFileName) return null; } + private string GetCDNFileUrl(string ftpPath, string shortFileName) + { + if (!ftpPath.EndsWith("/")) + ftpPath += "/"; + foreach (string pattern in AppSettings.Default.VideoUrlPatternsAtCDN) + { + var patternParts = pattern.Split('|'); + string ftpRootFolder = patternParts[0].Trim(); + string videoUrlPattern = patternParts[1].Trim(); + string ftpPathWithoutRoot = ftpPath.Remove(0, ftpRootFolder.Length); + if (ftpPath.StartsWith(ftpRootFolder)) + { + string cdnHost = videoUrlPattern.Split( + new string[] { "/hls/" }, StringSplitOptions.None)[0]; + string cdnUrl = cdnHost + "/" + ftpPathWithoutRoot + shortFileName; + return cdnUrl; + } + } + return null; + } + private List CreateActionsForFile(FileInfo fileInfo) { var actions = new List(); @@ -610,5 +639,86 @@ private void ViewJobDetails(Job job) FormViewJob formViewJob = new FormViewJob(job); formViewJob.ShowDialog(); } + + private void buttonShowCDNUrls_Click(object sender, EventArgs e) + { + if (this.ftpClient == null || (!this.ftpClient.IsConnected)) + { + LogError("not connected to the FTP server"); + return; + } + + try + { + var ftpPath = this.textBoxFTPPath.Text; + FtpListItem[] ftpItems = this.ftpClient.GetListing(ftpPath); + + var fileNames = ftpItems + .Where(item => item.Type == FtpFileSystemObjectType.File) + .Select(item => item.Name) + .ToList(); + + if (fileNames.Count == 0) + { + LogError("no files found in the currrent folder at the FTP server."); + return; + } + + Log($"Loaded the file list from the FTP: {String.Join(", ", fileNames)}"); + + var urls = new SortedSet(); + foreach (var fileName in fileNames) + { + string fileExtension = Path.GetExtension(fileName); + if (fileExtension.ToLower() == ".mp4") + { + var videoProfiles = ExtractVideoProfiles(fileName, fileNames); + string profilesList = "," + videoProfiles.Join(",") + ","; + if (videoProfiles != null) + { + string fileNameWithoutProfile = + fileName.Substring(0, fileName.LastIndexOf("-")); + var url = GetHlsVideoUrl( + ftpPath, fileNameWithoutProfile, profilesList); + urls.Add(url); + } + else + { + var url = GetCDNFileUrl(ftpPath, fileName); + urls.Add(url); + } + } + else + { + var url = GetCDNFileUrl(ftpPath, fileName); + urls.Add(url); + } + } + + var formShowUrls = new FormShowUrls(urls); + formShowUrls.ShowDialog(); + } + catch (Exception ex) + { + this.LogError($"retrieving CDN URLs from FTP failed. {ex.Message}"); + } + } + + private List ExtractVideoProfiles( + string fileName, List allFileNames) + { + int lastHyphenIndex = fileName.LastIndexOf('-'); + if (lastHyphenIndex == -1) + return null; + + string videoFilePrefix = fileName.Substring(0, lastHyphenIndex); + var profiles = allFileNames + .Where(f => f.StartsWith(videoFilePrefix)) + .Select(f => f.Substring(videoFilePrefix.Length + 1)) + .Select(f => Path.GetFileNameWithoutExtension(f)) + .OrderByDescending(f => f.Length).ThenByDescending(f => f) + .ToList(); + return profiles; + } } } diff --git a/Properties/Resources.Designer.cs b/Properties/Resources.Designer.cs index eb7f077..06407a1 100644 --- a/Properties/Resources.Designer.cs +++ b/Properties/Resources.Designer.cs @@ -110,6 +110,16 @@ internal static System.Drawing.Bitmap connect_icon_16px { } } + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap http_icon_23px { + get { + object obj = ResourceManager.GetObject("http_icon_23px", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// diff --git a/Properties/Resources.resx b/Properties/Resources.resx index 79a8e3e..405fd13 100644 --- a/Properties/Resources.resx +++ b/Properties/Resources.resx @@ -145,4 +145,7 @@ ..\Resources\settings-icon-16px.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\http-icon-23px.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + \ No newline at end of file diff --git a/Resources/http-icon-23px.png b/Resources/http-icon-23px.png new file mode 100644 index 0000000..ac5a4c2 Binary files /dev/null and b/Resources/http-icon-23px.png differ