1
0

Updated YoutubeExplode to v5

This commit is contained in:
Michael Gordeev
2020-05-10 15:11:42 +03:00
parent 1d636120cc
commit cc6940bab7
7 changed files with 32 additions and 65 deletions
+5 -2
View File
@@ -8,8 +8,11 @@
<ItemGroup>
<PackageReference Include="nunit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.13.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
</ItemGroup>
<ItemGroup>
+9 -8
View File
@@ -12,8 +12,8 @@ using System.Threading.Tasks;
using System.Xml;
using YouTube.Models;
using YoutubeExplode;
using YoutubeExplode.Models;
using YoutubeExplode.Models.MediaStreams;
using YoutubeExplode.Videos;
using YoutubeExplode.Videos.Streams;
namespace YouTube.Generators
{
@@ -23,7 +23,7 @@ namespace YouTube.Generators
YoutubeClient Client { get; }
string Id { get; }
Video Meta { get; set; }
MediaStreamInfoSet UrlsSet { get; set; }
StreamManifest UrlsSet { get; set; }
public ManifestGenerator(IClientService service, string id)
{
@@ -34,21 +34,22 @@ namespace YouTube.Generators
public async Task<IReadOnlyList<DashManifest>> GenerateManifestsAsync()
{
Meta = await Client.GetVideoAsync(Id);
Meta = await Client.Videos.GetAsync(Id);
if (Meta == null)
throw new FileNotFoundException("Video not found. Check video ID and visibility preferences");
UrlsSet = await Client.GetVideoMediaStreamInfosAsync(Id);
if (!string.IsNullOrWhiteSpace(UrlsSet.HlsLiveStreamUrl))
if (!string.IsNullOrWhiteSpace(await Client.Videos.Streams.GetHttpLiveStreamUrlAsync(Id)))
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>
{
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));
return list.AsReadOnly();
+1 -1
View File
@@ -1,5 +1,5 @@
using System.Globalization;
using YoutubeExplode.Models.ClosedCaptions;
using YoutubeExplode.Videos.ClosedCaptions;
namespace YouTube.Models
{
+3 -2
View File
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using YoutubeExplode.Videos.Streams;
namespace YouTube.Models
{
@@ -11,9 +12,9 @@ namespace YouTube.Models
public class PlaybackUrlsData
{
public IReadOnlyList<VideoPlaybackUrl> Video { get; set; }
public IReadOnlyList<AudioPlaybackUrl> Audio { get; set; }
public StreamManifest VideoFilesManifest { get; set; }
public string LiveStreamUrl { get; set; }
[Obsolete]
public DateTime ValidUntil { get; set; }
}
}
+1 -1
View File
@@ -29,7 +29,7 @@ namespace YouTube.Resources
public async Task<ClosedCaptionTrack> ExecuteAsync()
{
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>();
foreach (var i in response.Captions)
captions.Add(new ClosedCaptionTrack.ClosedCaption
+11 -49
View File
@@ -1,12 +1,13 @@
using Google.Apis.Services;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Globalization;
using System.Threading.Tasks;
using YouTube.Models;
using YoutubeExplode;
using YoutubeExplode.Models.ClosedCaptions;
using YoutubeExplode.Models.MediaStreams;
using YoutubeExplode.Videos.ClosedCaptions;
using YoutubeExplode.Videos.Streams;
namespace YouTube.Resources
{
@@ -29,60 +30,21 @@ namespace YouTube.Resources
{
VideoPlayback item = new VideoPlayback();
YoutubeClient client = new YoutubeClient(Service.HttpClient);
MediaStreamInfoSet streamSet = await client.GetVideoMediaStreamInfosAsync(Id);
item.Id = Id;
item.PlaybackUrls.ValidUntil = streamSet.ValidUntil.DateTime;
if (!string.IsNullOrWhiteSpace(streamSet.HlsLiveStreamUrl))
{
item.PlaybackUrls.LiveStreamUrl = streamSet.HlsLiveStreamUrl;
item.PlaybackUrls.ValidUntil = DateTime.Now + TimeSpan.FromHours(1);
item.PlaybackUrls.LiveStreamUrl = await client.Videos.Streams.GetHttpLiveStreamUrlAsync(Id);
if (!string.IsNullOrWhiteSpace(item.PlaybackUrls.LiveStreamUrl))
return item;
}
List<AudioPlaybackUrl> audio = new List<AudioPlaybackUrl>();
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();
item.PlaybackUrls.VideoFilesManifest = await client.Videos.Streams.GetManifestAsync(Id);
List<VideoPlaybackUrl> video = new List<VideoPlaybackUrl>();
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);
ClosedCaptionManifest ccSet = await client.Videos.ClosedCaptions.GetManifestAsync(Id);
List<ClosedCaptionInfo> captions = new List<ClosedCaptionInfo>();
foreach (ClosedCaptionTrackInfo i in ccSet)
foreach (ClosedCaptionTrackInfo i in ccSet.Tracks)
captions.Add(new ClosedCaptionInfo
{
AutoGenerated = i.IsAutoGenerated,
+2 -2
View File
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net46;netstandard2.0</TargetFrameworks>
<TargetFrameworks>net461;netstandard2.1</TargetFrameworks>
<AssemblyName>YouTube.API</AssemblyName>
<RootNamespace>YouTube</RootNamespace>
<Company>Michael "XFox" Gordeev</Company>
@@ -29,7 +29,7 @@
<PackageReference Include="Google.Apis.YouTube.v3" Version="1.45.0.1929" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<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>