new_version_init

This commit is contained in:
2024-02-13 02:59:40 +01:00
Unverified
parent e36c1404ee
commit 91f9b645bd
352 changed files with 6777 additions and 8326 deletions

View File

@@ -0,0 +1,21 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VDownload.Sources.Twitch.Api.GQL.GetVideoToken.Request
{
public class GetVideoTokenExtensions
{
[JsonProperty("durationMilliseconds")]
public int DurationMilliseconds { get; set; }
[JsonProperty("operationName")]
public string OperationName { get; set; }
[JsonProperty("requestID")]
public string RequestID { get; set; }
}
}

View File

@@ -0,0 +1,21 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VDownload.Sources.Twitch.Search.Models.GetVideoToken.Request
{
public class GetVideoTokenRequest
{
[JsonProperty("operationName")]
public string OperationName { get; set; }
[JsonProperty("query")]
public string Query { get; set; }
[JsonProperty("variables")]
public GetVideoTokenVariables Variables { get; set; }
}
}

View File

@@ -0,0 +1,27 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VDownload.Sources.Twitch.Search.Models.GetVideoToken.Request
{
public class GetVideoTokenVariables
{
[JsonProperty("isLive")]
public bool IsLive { get; set; }
[JsonProperty("login")]
public string Login { get; set; }
[JsonProperty("isVod")]
public bool IsVod { get; set; }
[JsonProperty("vodID")]
public string VodID { get; set; }
[JsonProperty("playerType")]
public string PlayerType { get; set; }
}
}

View File

@@ -0,0 +1,21 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VDownload.Sources.Twitch.Api.GQL.GetVideoToken.Request
{
public class GetVideoTokenVideoPlaybackAccessToken
{
[JsonProperty("value")]
public string Value { get; set; }
[JsonProperty("signature")]
public string Signature { get; set; }
[JsonProperty("__typename")]
public string Typename { get; set; }
}
}

View File

@@ -0,0 +1,16 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VDownload.Sources.Twitch.Api.GQL.GetVideoToken.Request;
namespace VDownload.Sources.Twitch.Api.GQL.GetVideoToken.Response
{
public class GetVideoTokenData
{
[JsonProperty("videoPlaybackAccessToken")]
public GetVideoTokenVideoPlaybackAccessToken VideoPlaybackAccessToken { get; set; }
}
}

View File

@@ -0,0 +1,19 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VDownload.Sources.Twitch.Api.GQL.GetVideoToken.Request;
namespace VDownload.Sources.Twitch.Api.GQL.GetVideoToken.Response
{
public class GetVideoTokenResponse
{
[JsonProperty("data")]
public GetVideoTokenData Data { get; set; }
[JsonProperty("extensions")]
public GetVideoTokenExtensions Extensions { get; set; }
}
}

View File

@@ -0,0 +1,62 @@
using Newtonsoft.Json;
using System.Collections.Generic;
using System;
namespace VDownload.Sources.Twitch.Api.Helix.GetVideos.Response
{
public class Data
{
[JsonProperty("id")]
public string Id { get; set; }
[JsonProperty("stream_id")]
public object StreamId { get; set; }
[JsonProperty("user_id")]
public string UserId { get; set; }
[JsonProperty("user_login")]
public string UserLogin { get; set; }
[JsonProperty("user_name")]
public string UserName { get; set; }
[JsonProperty("title")]
public string Title { get; set; }
[JsonProperty("description")]
public string Description { get; set; }
[JsonProperty("created_at")]
public DateTime CreatedAt { get; set; }
[JsonProperty("published_at")]
public DateTime PublishedAt { get; set; }
[JsonProperty("url")]
public string Url { get; set; }
[JsonProperty("thumbnail_url")]
public string ThumbnailUrl { get; set; }
[JsonProperty("viewable")]
public string Viewable { get; set; }
[JsonProperty("view_count")]
public int ViewCount { get; set; }
[JsonProperty("language")]
public string Language { get; set; }
[JsonProperty("type")]
public string Type { get; set; }
[JsonProperty("duration")]
public string Duration { get; set; }
[JsonProperty("muted_segments")]
public List<MutedSegment> MutedSegments { get; set; }
}
}

View File

@@ -0,0 +1,16 @@
using Newtonsoft.Json;
using System.Collections.Generic;
namespace VDownload.Sources.Twitch.Api.Helix.GetVideos.Response
{
public class GetVideosResponse
{
[JsonProperty("data")]
public List<Data> Data { get; set; }
[JsonProperty("pagination")]
public Pagination Pagination { get; set; }
}
}

View File

@@ -0,0 +1,14 @@
using Newtonsoft.Json;
namespace VDownload.Sources.Twitch.Api.Helix.GetVideos.Response
{
public class MutedSegment
{
[JsonProperty("duration")]
public int Duration { get; set; }
[JsonProperty("offset")]
public int Offset { get; set; }
}
}

View File

@@ -0,0 +1,11 @@
using Newtonsoft.Json;
namespace VDownload.Sources.Twitch.Api.Helix.GetVideos.Response
{
public class Pagination
{
[JsonProperty("cursor")]
public string Cursor { get; set; }
}
}

View File

@@ -0,0 +1,119 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VDownload.Services.HttpClient;
using VDownload.Sources.Twitch.Api.GQL.GetVideoToken.Response;
using VDownload.Sources.Twitch.Api.Helix.GetVideos.Response;
using VDownload.Sources.Twitch.Configuration;
using VDownload.Sources.Twitch.Search.Models.GetVideoToken.Request;
namespace VDownload.Sources.Twitch.Api
{
public interface ITwitchApiService
{
Task<string> AuthValidate(byte[] token);
Task<GetVideoTokenResponse> GQLGetVideoToken(string id);
Task<GetVideosResponse> HelixGetVideos(string id, byte[] token);
Task<string> UsherGetVideoPlaylist(string id, string videoToken, string videoTokenSignature);
}
public class TwitchApiService : ITwitchApiService
{
#region SERVICES
private readonly TwitchApiAuthConfiguration _apiAuthConfiguration;
private readonly TwitchApiHelixConfiguration _apiHelixConfiguration;
private readonly TwitchApiGQLConfiguration _apiGQLConfiguration;
private readonly TwitchApiUsherConfiguration _apiUsherConfiguration;
private readonly IHttpClientService _httpClientService;
#endregion
#region CONSTRUCTORS
public TwitchApiService(TwitchConfiguration configuration, IHttpClientService httpClientService)
{
_apiAuthConfiguration = configuration.Api.Auth;
_apiHelixConfiguration = configuration.Api.Helix;
_apiGQLConfiguration = configuration.Api.GQL;
_apiUsherConfiguration = configuration.Api.Usher;
_httpClientService = httpClientService;
}
#endregion
#region PUBLIC METHODS
public async Task<string> AuthValidate(byte[] token)
{
Token tokenData = new Token(_apiAuthConfiguration.TokenSchema, token);
HttpRequest request = new HttpRequest(HttpMethodType.GET, _apiAuthConfiguration.Endpoints.Validate);
request.Headers.Add("Authorization", $"{tokenData}");
return await _httpClientService.SendRequestAsync(request);
}
public async Task<GetVideosResponse> HelixGetVideos(string id, byte[] token)
{
Token tokenData = new Token(_apiHelixConfiguration.TokenSchema, token);
HttpRequest request = new HttpRequest(HttpMethodType.GET, _apiHelixConfiguration.Endpoints.GetVideos);
request.Query.Add("id", id);
request.Headers.Add("Authorization", tokenData.ToString());
request.Headers.Add("Client-Id", _apiHelixConfiguration.ClientId);
return await _httpClientService.SendRequestAsync<GetVideosResponse>(request);
}
public async Task<GetVideoTokenResponse> GQLGetVideoToken(string id)
{
TwitchApiGQLQueriesQueryExtendedConfiguration configuration = _apiGQLConfiguration.Queries.GetVideoToken;
GetVideoTokenRequest requestBody = new GetVideoTokenRequest
{
OperationName = configuration.OperationName,
Query = configuration.Query,
Variables = new GetVideoTokenVariables
{
IsLive = false,
Login = string.Empty,
IsVod = true,
VodID = id,
PlayerType = "embed"
}
};
HttpRequest request = new HttpRequest(HttpMethodType.POST, _apiGQLConfiguration.Endpoint)
{
Body = requestBody,
};
request.Headers.Add("Client-Id", _apiGQLConfiguration.ClientId);
return await _httpClientService.SendRequestAsync<GetVideoTokenResponse>(request);
}
public async Task<string> UsherGetVideoPlaylist(string id, string videoToken, string videoTokenSignature)
{
string url = string.Format(_apiUsherConfiguration.Endpoints.GetVideoPlaylist, id);
HttpRequest request = new HttpRequest(HttpMethodType.GET, url);
request.Query.Add("token", videoToken);
request.Query.Add("sig", videoTokenSignature);
request.Query.Add("allow_source", true);
request.Query.Add("allow_audio_only", true);
request.Query.Add("platform", "web");
request.Query.Add("player_backend", "mediaplayer");
request.Query.Add("playlist_include_framerate", true);
request.Query.Add("supported_codecs", "av1,h264");
return await _httpClientService.SendRequestAsync(request);
}
#endregion
}
}

View File

@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\VDownload.Services\VDownload.Services.HttpClient\VDownload.Services.HttpClient.csproj" />
<ProjectReference Include="..\VDownload.Sources.Twitch.Configuration\VDownload.Sources.Twitch.Configuration.csproj" />
</ItemGroup>
</Project>