Updated YoutubeExplode to v5
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user