1.0-dev16 (GUI code cleaning, media not found exception handling added)
This commit is contained in:
@@ -1,8 +0,0 @@
|
||||
namespace VDownload.Core.EventArgs
|
||||
{
|
||||
public class PlaylistSearchEventArgs : System.EventArgs
|
||||
{
|
||||
public string Url { get; set; }
|
||||
public int VideosCount { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using VDownload.Core.Interfaces;
|
||||
|
||||
namespace VDownload.Core.EventArgs
|
||||
{
|
||||
public class PlaylistSearchSuccessedEventArgs : System.EventArgs
|
||||
{
|
||||
public IPlaylistService PlaylistService { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
namespace VDownload.Core.EventArgs
|
||||
{
|
||||
public class VideoSearchEventArgs : System.EventArgs
|
||||
{
|
||||
public string Url { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using VDownload.Core.Interfaces;
|
||||
|
||||
namespace VDownload.Core.EventArgs
|
||||
{
|
||||
public class VideoSearchSuccessedEventArgs : System.EventArgs
|
||||
{
|
||||
public IVideoService VideoService { get; set; }
|
||||
}
|
||||
}
|
||||
15
VDownload.Core/Exceptions/MediaNotFoundException.cs
Normal file
15
VDownload.Core/Exceptions/MediaNotFoundException.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VDownload.Core.Exceptions
|
||||
{
|
||||
public class MediaNotFoundException : Exception
|
||||
{
|
||||
public MediaNotFoundException() { }
|
||||
public MediaNotFoundException(string message) : base(message) { }
|
||||
public MediaNotFoundException(string message, Exception inner) : base(message, inner) { }
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ namespace VDownload.Core.Services
|
||||
// PLAYLIST SOURCES REGULAR EXPRESSIONS
|
||||
private static readonly (Regex Regex, PlaylistSource Type)[] PlaylistSources = new (Regex Regex, PlaylistSource Type)[]
|
||||
{
|
||||
(new Regex(@"^https://www.twitch.tv/(?<id>[^?]+)"), PlaylistSource.TwitchChannel),
|
||||
(new Regex(@"^https://www.twitch.tv/(?<id>[^?/]+)"), PlaylistSource.TwitchChannel),
|
||||
};
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -49,7 +49,9 @@ namespace VDownload.Core.Services.Sources.Twitch
|
||||
using (WebClient client = await Client.Helix())
|
||||
{
|
||||
client.QueryString.Add("login", ID);
|
||||
response = JObject.Parse(await client.DownloadStringTaskAsync("https://api.twitch.tv/helix/users"))["data"][0];
|
||||
response = JObject.Parse(await client.DownloadStringTaskAsync("https://api.twitch.tv/helix/users"))["data"];
|
||||
if (((JArray)response).Count > 0) response = response[0];
|
||||
else throw new MediaNotFoundException($"Twitch Channel (ID: {ID}) was not found");
|
||||
}
|
||||
|
||||
// Create unified playlist url
|
||||
|
||||
@@ -54,7 +54,9 @@ namespace VDownload.Core.Services.Sources.Twitch
|
||||
using (WebClient client = await Client.Helix())
|
||||
{
|
||||
client.QueryString.Add("id", ID);
|
||||
response = JObject.Parse(await client.DownloadStringTaskAsync("https://api.twitch.tv/helix/clips")).GetValue("data")[0];
|
||||
response = JObject.Parse(await client.DownloadStringTaskAsync("https://api.twitch.tv/helix/clips")).GetValue("data");
|
||||
if (((JArray)response).Count > 0) response = response[0];
|
||||
else throw new MediaNotFoundException($"Twitch Clip (ID: {ID}) was not found");
|
||||
}
|
||||
|
||||
// Create unified video url
|
||||
|
||||
@@ -2,12 +2,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using VDownload.Core.Enums;
|
||||
using VDownload.Core.Exceptions;
|
||||
using VDownload.Core.Interfaces;
|
||||
using VDownload.Core.Services.Sources.Twitch.Helpers;
|
||||
using VDownload.Core.Structs;
|
||||
@@ -52,7 +54,16 @@ namespace VDownload.Core.Services.Sources.Twitch
|
||||
{
|
||||
client.QueryString.Add("id", ID);
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
response = JObject.Parse(await client.DownloadStringTaskAsync("https://api.twitch.tv/helix/videos")).GetValue("data")[0];
|
||||
try
|
||||
{
|
||||
response = JObject.Parse(await client.DownloadStringTaskAsync("https://api.twitch.tv/helix/videos")).GetValue("data")[0];
|
||||
}
|
||||
catch (WebException ex)
|
||||
{
|
||||
if (ex.Response != null && new StreamReader(ex.Response.GetResponseStream()).ReadToEnd().Contains("Not Found")) throw new MediaNotFoundException($"Twitch VOD (ID: {ID}) was not found");
|
||||
else if (ex.Response != null && new StreamReader(ex.Response.GetResponseStream()).ReadToEnd() == string.Empty && ex.Message.Contains("400")) throw new MediaNotFoundException($"Twitch VOD (ID: {ID}) was not found");
|
||||
else throw;
|
||||
}
|
||||
}
|
||||
|
||||
// Set parameters
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VDownload.Core.Services
|
||||
{
|
||||
@@ -15,17 +12,15 @@ namespace VDownload.Core.Services
|
||||
string formattedTimeSpan = string.Empty;
|
||||
|
||||
int maxTHLength = 0;
|
||||
if (Math.Floor(timeSpan.TotalHours) > 0)
|
||||
foreach (TimeSpan format in formatBase.Concat(new TimeSpan[] { timeSpan }))
|
||||
{
|
||||
maxTHLength = Math.Floor(timeSpan.TotalHours).ToString().Length;
|
||||
foreach (TimeSpan format in formatBase)
|
||||
{
|
||||
int THLength = Math.Floor(format.TotalHours) > 0 ? Math.Floor(timeSpan.TotalHours).ToString().Length : 0;
|
||||
if (THLength > maxTHLength) maxTHLength = THLength;
|
||||
}
|
||||
formattedTimeSpan += $"{((int)Math.Floor(timeSpan.TotalHours)).ToString($"D{maxTHLength}")}:";
|
||||
int THLength = Math.Floor(format.TotalHours) > 0 ? Math.Floor(timeSpan.TotalHours).ToString().Length : 0;
|
||||
if (THLength > maxTHLength) maxTHLength = THLength;
|
||||
}
|
||||
formattedTimeSpan += $"{((int)Math.Floor(timeSpan.TotalHours)).ToString($"D{maxTHLength}")}:";
|
||||
|
||||
formattedTimeSpan += maxTHLength == 0 ? $"{timeSpan.Minutes}:" : $"{timeSpan.Minutes:00}:";
|
||||
|
||||
formattedTimeSpan += $"{timeSpan.Seconds:00}";
|
||||
|
||||
return formattedTimeSpan;
|
||||
@@ -37,22 +32,20 @@ namespace VDownload.Core.Services
|
||||
string formattedTimeSpan = string.Empty;
|
||||
|
||||
int maxTHLength = 0;
|
||||
if (Math.Floor(timeSpan.TotalHours) > 0)
|
||||
foreach (TimeSpan format in formatBase.Concat(new TimeSpan[] { timeSpan }))
|
||||
{
|
||||
maxTHLength = Math.Floor(timeSpan.TotalHours).ToString().Length;
|
||||
foreach (TimeSpan format in formatBase)
|
||||
{
|
||||
int THLength = Math.Floor(format.TotalHours) > 0 ? Math.Floor(timeSpan.TotalHours).ToString().Length : 0;
|
||||
if (THLength > maxTHLength) maxTHLength = THLength;
|
||||
}
|
||||
formattedTimeSpan += $"{((int)Math.Floor(timeSpan.TotalHours)).ToString($"D{maxTHLength}")}:";
|
||||
int THLength = Math.Floor(format.TotalHours) > 0 ? Math.Floor(timeSpan.TotalHours).ToString().Length : 0;
|
||||
if (THLength > maxTHLength) maxTHLength = THLength;
|
||||
}
|
||||
formattedTimeSpan += $"{((int)Math.Floor(timeSpan.TotalHours)).ToString($"D{maxTHLength}")}:";
|
||||
|
||||
bool MM = false;
|
||||
if (Math.Floor(timeSpan.TotalMinutes) > 0)
|
||||
if (Math.Floor(timeSpan.TotalMinutes) > 0 || maxTHLength > 0)
|
||||
{
|
||||
formattedTimeSpan += maxTHLength > 0 ? $"{timeSpan.Minutes:00}:" : $"{timeSpan.Minutes}:";
|
||||
MM = true;
|
||||
}
|
||||
|
||||
formattedTimeSpan += MM ? $"{timeSpan.Seconds:00}:" : $"{timeSpan.Seconds}:";
|
||||
|
||||
return formattedTimeSpan;
|
||||
|
||||
@@ -8,13 +8,6 @@ namespace VDownload.Core.Structs
|
||||
public struct TaskData
|
||||
{
|
||||
public IVideoService VideoService { get; set; }
|
||||
public MediaType MediaType { get; set; }
|
||||
public BaseStream Stream { get; set; }
|
||||
public TimeSpan TrimStart { get; set; }
|
||||
public TimeSpan TrimEnd { get; set; }
|
||||
public string Filename { get; set; }
|
||||
public MediaFileExtension Extension { get; set; }
|
||||
public StorageFolder Location { get; set; }
|
||||
public double Schedule { get; set; }
|
||||
public TaskOptions TaskOptions { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
18
VDownload.Core/Structs/TaskOptions.cs
Normal file
18
VDownload.Core/Structs/TaskOptions.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using VDownload.Core.Enums;
|
||||
using Windows.Storage;
|
||||
|
||||
namespace VDownload.Core.Structs
|
||||
{
|
||||
public struct TaskOptions
|
||||
{
|
||||
public MediaType MediaType { get; set; }
|
||||
public BaseStream Stream { get; set; }
|
||||
public TimeSpan TrimStart { get; set; }
|
||||
public TimeSpan TrimEnd { get; set; }
|
||||
public string Filename { get; set; }
|
||||
public MediaFileExtension Extension { get; set; }
|
||||
public StorageFolder Location { get; set; }
|
||||
public double Schedule { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -130,8 +130,9 @@
|
||||
<Compile Include="Enums\TaskStatus.cs" />
|
||||
<Compile Include="EventArgs\ProgressChangedEventArgs.cs" />
|
||||
<Compile Include="EventArgs\TasksAddingRequestedEventArgs.cs" />
|
||||
<Compile Include="EventArgs\VideoSearchEventArgs.cs" />
|
||||
<Compile Include="EventArgs\PlaylistSearchEventArgs.cs" />
|
||||
<Compile Include="EventArgs\PlaylistSearchSuccessedEventArgs.cs" />
|
||||
<Compile Include="EventArgs\VideoSearchSuccessedEventArgs.cs" />
|
||||
<Compile Include="Exceptions\MediaNotFoundException.cs" />
|
||||
<Compile Include="Exceptions\TwitchAccessTokenNotFoundException.cs" />
|
||||
<Compile Include="Exceptions\TwitchAccessTokenNotValidException.cs" />
|
||||
<Compile Include="Interfaces\IPlaylistService.cs" />
|
||||
@@ -149,6 +150,7 @@
|
||||
<Compile Include="Services\Sources\Twitch\Clip.cs" />
|
||||
<Compile Include="Services\Sources\Twitch\Vod.cs" />
|
||||
<Compile Include="Services\TaskId.cs" />
|
||||
<Compile Include="Structs\TaskOptions.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
|
||||
|
||||
Reference in New Issue
Block a user