Updated YoutubeExplode to v5
This commit is contained in:
@@ -8,8 +8,11 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="nunit" Version="3.12.0" />
|
<PackageReference Include="nunit" Version="3.12.0" />
|
||||||
<PackageReference Include="NUnit3TestAdapter" Version="3.13.0" />
|
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1">
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ using System.Threading.Tasks;
|
|||||||
using System.Xml;
|
using System.Xml;
|
||||||
using YouTube.Models;
|
using YouTube.Models;
|
||||||
using YoutubeExplode;
|
using YoutubeExplode;
|
||||||
using YoutubeExplode.Models;
|
using YoutubeExplode.Videos;
|
||||||
using YoutubeExplode.Models.MediaStreams;
|
using YoutubeExplode.Videos.Streams;
|
||||||
|
|
||||||
namespace YouTube.Generators
|
namespace YouTube.Generators
|
||||||
{
|
{
|
||||||
@@ -23,7 +23,7 @@ namespace YouTube.Generators
|
|||||||
YoutubeClient Client { get; }
|
YoutubeClient Client { get; }
|
||||||
string Id { get; }
|
string Id { get; }
|
||||||
Video Meta { get; set; }
|
Video Meta { get; set; }
|
||||||
MediaStreamInfoSet UrlsSet { get; set; }
|
StreamManifest UrlsSet { get; set; }
|
||||||
|
|
||||||
public ManifestGenerator(IClientService service, string id)
|
public ManifestGenerator(IClientService service, string id)
|
||||||
{
|
{
|
||||||
@@ -34,21 +34,22 @@ namespace YouTube.Generators
|
|||||||
|
|
||||||
public async Task<IReadOnlyList<DashManifest>> GenerateManifestsAsync()
|
public async Task<IReadOnlyList<DashManifest>> GenerateManifestsAsync()
|
||||||
{
|
{
|
||||||
Meta = await Client.GetVideoAsync(Id);
|
Meta = await Client.Videos.GetAsync(Id);
|
||||||
|
|
||||||
if (Meta == null)
|
if (Meta == null)
|
||||||
throw new FileNotFoundException("Video not found. Check video ID and visibility preferences");
|
throw new FileNotFoundException("Video not found. Check video ID and visibility preferences");
|
||||||
|
|
||||||
UrlsSet = await Client.GetVideoMediaStreamInfosAsync(Id);
|
if (!string.IsNullOrWhiteSpace(await Client.Videos.Streams.GetHttpLiveStreamUrlAsync(Id)))
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(UrlsSet.HlsLiveStreamUrl))
|
|
||||||
throw new NotSupportedException("This is livestream. Use 'YouTubeClient.VideoPlayback.List()' to get playback URLs");
|
throw new NotSupportedException("This is livestream. Use 'YouTubeClient.VideoPlayback.List()' to get playback URLs");
|
||||||
|
|
||||||
|
UrlsSet = await Client.Videos.Streams.GetManifestAsync(Id);
|
||||||
|
|
||||||
List<DashManifest> list = new List<DashManifest>
|
List<DashManifest> list = new List<DashManifest>
|
||||||
{
|
{
|
||||||
await GenerateManifest("Auto")
|
await GenerateManifest("Auto")
|
||||||
};
|
};
|
||||||
foreach (string i in UrlsSet.GetAllVideoQualityLabels())
|
|
||||||
|
foreach (string i in UrlsSet.GetVideo().Select(k => k.VideoQualityLabel).Distinct())
|
||||||
list.Add(await GenerateManifest(i));
|
list.Add(await GenerateManifest(i));
|
||||||
|
|
||||||
return list.AsReadOnly();
|
return list.AsReadOnly();
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using YoutubeExplode.Models.ClosedCaptions;
|
using YoutubeExplode.Videos.ClosedCaptions;
|
||||||
|
|
||||||
namespace YouTube.Models
|
namespace YouTube.Models
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using YoutubeExplode.Videos.Streams;
|
||||||
|
|
||||||
namespace YouTube.Models
|
namespace YouTube.Models
|
||||||
{
|
{
|
||||||
@@ -11,9 +12,9 @@ namespace YouTube.Models
|
|||||||
|
|
||||||
public class PlaybackUrlsData
|
public class PlaybackUrlsData
|
||||||
{
|
{
|
||||||
public IReadOnlyList<VideoPlaybackUrl> Video { get; set; }
|
public StreamManifest VideoFilesManifest { get; set; }
|
||||||
public IReadOnlyList<AudioPlaybackUrl> Audio { get; set; }
|
|
||||||
public string LiveStreamUrl { get; set; }
|
public string LiveStreamUrl { get; set; }
|
||||||
|
[Obsolete]
|
||||||
public DateTime ValidUntil { get; set; }
|
public DateTime ValidUntil { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ namespace YouTube.Resources
|
|||||||
public async Task<ClosedCaptionTrack> ExecuteAsync()
|
public async Task<ClosedCaptionTrack> ExecuteAsync()
|
||||||
{
|
{
|
||||||
YoutubeClient client = new YoutubeClient(Service.HttpClient);
|
YoutubeClient client = new YoutubeClient(Service.HttpClient);
|
||||||
var response = await client.GetClosedCaptionTrackAsync(CaptionInfo.TrackInfo);
|
var response = await client.Videos.ClosedCaptions.GetAsync(CaptionInfo.TrackInfo);
|
||||||
List<ClosedCaptionTrack.ClosedCaption> captions = new List<ClosedCaptionTrack.ClosedCaption>();
|
List<ClosedCaptionTrack.ClosedCaption> captions = new List<ClosedCaptionTrack.ClosedCaption>();
|
||||||
foreach (var i in response.Captions)
|
foreach (var i in response.Captions)
|
||||||
captions.Add(new ClosedCaptionTrack.ClosedCaption
|
captions.Add(new ClosedCaptionTrack.ClosedCaption
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
using Google.Apis.Services;
|
using Google.Apis.Services;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using YouTube.Models;
|
using YouTube.Models;
|
||||||
using YoutubeExplode;
|
using YoutubeExplode;
|
||||||
using YoutubeExplode.Models.ClosedCaptions;
|
using YoutubeExplode.Videos.ClosedCaptions;
|
||||||
using YoutubeExplode.Models.MediaStreams;
|
using YoutubeExplode.Videos.Streams;
|
||||||
|
|
||||||
namespace YouTube.Resources
|
namespace YouTube.Resources
|
||||||
{
|
{
|
||||||
@@ -29,60 +30,21 @@ namespace YouTube.Resources
|
|||||||
{
|
{
|
||||||
VideoPlayback item = new VideoPlayback();
|
VideoPlayback item = new VideoPlayback();
|
||||||
YoutubeClient client = new YoutubeClient(Service.HttpClient);
|
YoutubeClient client = new YoutubeClient(Service.HttpClient);
|
||||||
MediaStreamInfoSet streamSet = await client.GetVideoMediaStreamInfosAsync(Id);
|
|
||||||
item.Id = Id;
|
item.Id = Id;
|
||||||
item.PlaybackUrls.ValidUntil = streamSet.ValidUntil.DateTime;
|
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(streamSet.HlsLiveStreamUrl))
|
item.PlaybackUrls.ValidUntil = DateTime.Now + TimeSpan.FromHours(1);
|
||||||
{
|
|
||||||
item.PlaybackUrls.LiveStreamUrl = streamSet.HlsLiveStreamUrl;
|
item.PlaybackUrls.LiveStreamUrl = await client.Videos.Streams.GetHttpLiveStreamUrlAsync(Id);
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(item.PlaybackUrls.LiveStreamUrl))
|
||||||
return item;
|
return item;
|
||||||
}
|
|
||||||
|
|
||||||
List<AudioPlaybackUrl> audio = new List<AudioPlaybackUrl>();
|
item.PlaybackUrls.VideoFilesManifest = await client.Videos.Streams.GetManifestAsync(Id);
|
||||||
foreach (AudioStreamInfo i in streamSet.Audio)
|
|
||||||
audio.Add(new AudioPlaybackUrl
|
|
||||||
{
|
|
||||||
Url = i.Url,
|
|
||||||
Bitrate = (int)i.Bitrate,
|
|
||||||
Format = (AudioFormat)i.AudioEncoding,
|
|
||||||
Quality = Extensions.RangeOffset((int)i.Bitrate / 1024, 128, 255) switch
|
|
||||||
{
|
|
||||||
-1 => AudioQuality.Low,
|
|
||||||
1 => AudioQuality.High,
|
|
||||||
_ => AudioQuality.Medium
|
|
||||||
}
|
|
||||||
});
|
|
||||||
item.PlaybackUrls.Audio = audio.AsReadOnly();
|
|
||||||
|
|
||||||
List<VideoPlaybackUrl> video = new List<VideoPlaybackUrl>();
|
ClosedCaptionManifest ccSet = await client.Videos.ClosedCaptions.GetManifestAsync(Id);
|
||||||
foreach (VideoStreamInfo i in streamSet.Video)
|
|
||||||
video.Add(new VideoPlaybackUrl
|
|
||||||
{
|
|
||||||
Format = (VideoFormat)i.VideoEncoding,
|
|
||||||
HasAudio = false,
|
|
||||||
Quality = i.VideoQualityLabel,
|
|
||||||
Url = i.Url,
|
|
||||||
Resolution = new Size(i.Resolution.Width, i.Resolution.Height),
|
|
||||||
Bitrate = (int)i.Bitrate
|
|
||||||
});
|
|
||||||
|
|
||||||
foreach (MuxedStreamInfo i in streamSet.Muxed)
|
|
||||||
video.Add(new VideoPlaybackUrl
|
|
||||||
{
|
|
||||||
Format = (VideoFormat)i.VideoEncoding,
|
|
||||||
HasAudio = true,
|
|
||||||
Quality = i.VideoQualityLabel,
|
|
||||||
Url = i.Url,
|
|
||||||
Resolution = new Size(i.Resolution.Width, i.Resolution.Height),
|
|
||||||
Bitrate = 0
|
|
||||||
});
|
|
||||||
item.PlaybackUrls.Video = video.AsReadOnly();
|
|
||||||
|
|
||||||
var ccSet = await client.GetVideoClosedCaptionTrackInfosAsync(Id);
|
|
||||||
|
|
||||||
List<ClosedCaptionInfo> captions = new List<ClosedCaptionInfo>();
|
List<ClosedCaptionInfo> captions = new List<ClosedCaptionInfo>();
|
||||||
foreach (ClosedCaptionTrackInfo i in ccSet)
|
foreach (ClosedCaptionTrackInfo i in ccSet.Tracks)
|
||||||
captions.Add(new ClosedCaptionInfo
|
captions.Add(new ClosedCaptionInfo
|
||||||
{
|
{
|
||||||
AutoGenerated = i.IsAutoGenerated,
|
AutoGenerated = i.IsAutoGenerated,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFrameworks>net46;netstandard2.0</TargetFrameworks>
|
<TargetFrameworks>net461;netstandard2.1</TargetFrameworks>
|
||||||
<AssemblyName>YouTube.API</AssemblyName>
|
<AssemblyName>YouTube.API</AssemblyName>
|
||||||
<RootNamespace>YouTube</RootNamespace>
|
<RootNamespace>YouTube</RootNamespace>
|
||||||
<Company>Michael "XFox" Gordeev</Company>
|
<Company>Michael "XFox" Gordeev</Company>
|
||||||
@@ -29,7 +29,7 @@
|
|||||||
<PackageReference Include="Google.Apis.YouTube.v3" Version="1.45.0.1929" />
|
<PackageReference Include="Google.Apis.YouTube.v3" Version="1.45.0.1929" />
|
||||||
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
|
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
|
||||||
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" PrivateAssets="all" />
|
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" PrivateAssets="all" />
|
||||||
<PackageReference Include="YoutubeExplode" Version="4.7.16" />
|
<PackageReference Include="YoutubeExplode" Version="5.0.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
Reference in New Issue
Block a user