filter controls, default thumbnail, playlist search video removing

This commit is contained in:
2024-03-02 01:05:44 +01:00
Unverified
parent 9465be8d76
commit 17245bb91f
28 changed files with 352 additions and 71 deletions

View File

@@ -4,7 +4,7 @@ namespace VDownload.Sources.Twitch.Configuration.Models{
public class Download
{
[ConfigurationKeyName("vod")]
public Vod Vod { get; set; }
public DownloadVod Vod { get; set; }
}
}

View File

@@ -0,0 +1,18 @@
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VDownload.Sources.Twitch.Configuration.Models
{
public class DownloadVod
{
[ConfigurationKeyName("chunk_regex")]
public string ChunkRegex { get; set; }
[ConfigurationKeyName("file_name")]
public string FileName { get; set; }
}
}

View File

@@ -7,7 +7,7 @@ namespace VDownload.Sources.Twitch.Configuration.Models{
public List<string> GeneralRegexes { get; } = new List<string>();
[ConfigurationKeyName("vod")]
public Vod Vod { get; set; }
public SearchVod Vod { get; set; }
[ConfigurationKeyName("clip")]
public Clip Clip { get; set; }

View File

@@ -1,7 +1,7 @@
using Microsoft.Extensions.Configuration;
namespace VDownload.Sources.Twitch.Configuration.Models{
public class Vod
public class SearchVod
{
[ConfigurationKeyName("regexes")]
public List<string> Regexes { get; } = new List<string>();
@@ -9,14 +9,11 @@ namespace VDownload.Sources.Twitch.Configuration.Models{
[ConfigurationKeyName("thumbnail")]
public Thumbnail Thumbnail { get; set; }
[ConfigurationKeyName("live_thumbnail_url_regex")]
public string LiveThumbnailUrlRegex { get; set; }
[ConfigurationKeyName("stream_playlist_regex")]
public string StreamPlaylistRegex { get; set; }
[ConfigurationKeyName("chunk_regex")]
public string ChunkRegex { get; set; }
[ConfigurationKeyName("file_name")]
public string FileName { get; set; }
}
}

View File

@@ -19,8 +19,8 @@ namespace VDownload.Sources.Twitch
{
public interface ITwitchSearchService : ISourceSearchService
{
Task<TwitchPlaylist> SearchPlaylist(string url, int maxVideoCount);
Task<TwitchVideo> SearchVideo(string url);
new Task<TwitchPlaylist> SearchPlaylist(string url, int maxVideoCount);
new Task<TwitchVideo> SearchVideo(string url);
}
@@ -120,17 +120,17 @@ namespace VDownload.Sources.Twitch
List<Task<TwitchVod>> tasks = new List<Task<TwitchVod>>();
string? cursor = null;
List<Api.Helix.GetVideos.Response.Data> videosList;
count = count == 0 ? int.MaxValue : count;
int videos = 0;
do
{
videos = count == 0 || count > 100 ? 100 : count;
videos = count > 100 ? 100 : count;
GetVideosResponse videosResponse = await _apiService.HelixGetUserVideos(channel.Id, token, videos, cursor);
videosList = videosResponse.Data;
count -= videosList.Count;
cursor = videosResponse.Pagination.Cursor;
tasks.AddRange(videosList.Select(ParseVod));
}
while (videosList.Count == videos);
while (tasks.Count < count && videosList.Count == videos);
await Task.WhenAll(tasks);
@@ -143,7 +143,13 @@ namespace VDownload.Sources.Twitch
{
Task<IEnumerable<TwitchVodStream>> streamsTask = GetVodStreams(data.Id);
Thumbnail thumbnail = _configurationService.Twitch.Search.Vod.Thumbnail;
Thumbnail thumbnailConfig = _configurationService.Twitch.Search.Vod.Thumbnail;
Regex liveThumbnailRegex = new Regex(_configurationService.Twitch.Search.Vod.LiveThumbnailUrlRegex);
Uri? thumbnail = null;
if (!liveThumbnailRegex.IsMatch(data.ThumbnailUrl))
{
thumbnail = new Uri(data.ThumbnailUrl.Replace("%{width}", thumbnailConfig.Width.ToString()).Replace("%{height}", thumbnailConfig.Height.ToString()));
}
TwitchVod vod = new TwitchVod
{
Title = data.Title,
@@ -152,7 +158,7 @@ namespace VDownload.Sources.Twitch
PublishDate = data.PublishedAt,
Duration = ParseVodDuration(data.Duration),
Views = data.ViewCount,
ThumbnailUrl = new Uri(data.ThumbnailUrl.Replace("%{width}", thumbnail.Width.ToString()).Replace("%{height}", thumbnail.Height.ToString())),
ThumbnailUrl = thumbnail,
Url = new Uri(data.Url),
};