Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Model rework #21

Merged
merged 10 commits into from
Apr 21, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
GetVideoInfoAsync now works with new models
  • Loading branch information
Oleksii Holub committed Apr 21, 2017
commit db58235c2a0d6ac36a92f06bae8322e94c84f15e
16 changes: 9 additions & 7 deletions DemoConsole/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Threading.Tasks;
using Tyrrrz.Extensions;
using YoutubeExplode.Models;

namespace YoutubeExplode.DemoConsole
{
Expand Down Expand Up @@ -56,16 +57,17 @@ private static async Task MainAsync()
Console.WriteLine($"Id: {videoInfo.Id} | Title: {videoInfo.Title} | Author: {videoInfo.Author}");

// Get the most preferable stream
Console.WriteLine("Looking for the best stream that has both video and audio tracks...");
var streamInfo = videoInfo.Streams
.Where(s => s.ContainsVideo && s.ContainsAudio)
.OrderBy(s => s.Quality)
Console.WriteLine("Looking for the best mixed stream...");
var streamInfo = videoInfo.MixedStreams
.OrderBy(s => s.VideoQuality)
.Last();
string normalizedFileSize = NormalizeFileSize(streamInfo.FileSize);
Console.WriteLine($"Quality: {streamInfo.QualityLabel} | Container: {streamInfo.ContainerType} | Size: {normalizedFileSize}");
string normalizedFileSize = NormalizeFileSize(streamInfo.ContentLength);
string qualityLabel = streamInfo.VideoQuality.GetLabel();
Console.WriteLine($"Quality: {qualityLabel} | Container: {streamInfo.Container} | Size: {normalizedFileSize}");

// Compose file name, based on metadata
string fileName = $"{videoInfo.Title}.{streamInfo.QualityLabel}.{streamInfo.FileExtension}";
string fileExtension = streamInfo.Container.GetFileExtension();
string fileName = $"{videoInfo.Title}.{qualityLabel}.{fileExtension}";

// Remove illegal characters from file name
fileName = fileName.Except(Path.GetInvalidFileNameChars());
Expand Down
44 changes: 34 additions & 10 deletions Tests/Extensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Tyrrrz.Extensions;
using YoutubeExplode.Models;
using YoutubeExplode.Models.ClosedCaptions;
using YoutubeExplode.Models.MediaStreams;

namespace YoutubeExplode.Tests
{
Expand Down Expand Up @@ -37,20 +39,38 @@ public static void IsSet(this Assert assert, VideoInfo videoInfo)
Assert.IsNotNull(videoInfo.Keywords);
Assert.IsNotNull(videoInfo.Watermarks);

Assert.IsNotNull(videoInfo.Streams);
foreach (var streamInfo in videoInfo.Streams)
Assert.IsNotNull(videoInfo.MixedStreams);
Assert.IsNotNull(videoInfo.AudioStreams);
Assert.IsNotNull(videoInfo.VideoStreams);

foreach (var streamInfo in videoInfo.MixedStreams)
{
Assert.IsNotNull(streamInfo);
Assert.That.IsNotBlank(streamInfo.Url);
Assert.IsTrue(0 < streamInfo.ContentLength);
}

foreach (var streamInfo in videoInfo.AudioStreams)
{
Assert.IsNotNull(streamInfo);
Assert.That.IsNotBlank(streamInfo.Url);
Assert.IsTrue(0 < streamInfo.ContentLength);
Assert.IsTrue(0 < streamInfo.Bitrate);
}

foreach (var streamInfo in videoInfo.VideoStreams)
{
Assert.IsNotNull(streamInfo);
Assert.That.IsNotBlank(streamInfo.Url);
Assert.AreNotEqual(MediaStreamVideoQuality.Unknown, streamInfo.Quality);
Assert.AreNotEqual(MediaStreamContainerType.Unknown, streamInfo.ContainerType);
Assert.That.IsNotBlank(streamInfo.QualityLabel);
Assert.That.IsNotBlank(streamInfo.FileExtension);
Assert.AreNotEqual(0, streamInfo.FileSize);
Assert.IsTrue(0 < streamInfo.ContentLength);
Assert.IsTrue(0 < streamInfo.Bitrate);
Assert.IsTrue(0 < streamInfo.VideoFramerate);
}

Assert.IsNotNull(videoInfo.ClosedCaptionTracks);
foreach (var captionTrack in videoInfo.ClosedCaptionTracks)
{
Assert.IsNotNull(captionTrack);
Assert.That.IsNotBlank(captionTrack.Url);
Assert.IsNotNull(captionTrack.Culture);
}
Expand All @@ -61,10 +81,8 @@ public static void IsSet(this Assert assert, PlaylistInfo playlistInfo)
Assert.IsNotNull(playlistInfo);

Assert.That.IsNotBlank(playlistInfo.Id);
Assert.AreNotEqual(PlaylistType.Unknown, playlistInfo.Type);
Assert.That.IsNotBlank(playlistInfo.Title);
if (playlistInfo.Type != PlaylistType.VideoMix)
Assert.IsNotNull(playlistInfo.Author);
Assert.IsNotNull(playlistInfo.Author);
Assert.IsNotNull(playlistInfo.Description);
Assert.IsNotNull(playlistInfo.VideoIds);
}
Expand All @@ -82,6 +100,12 @@ public static void IsSet(this Assert assert, ClosedCaptionTrack closedCaption)
Assert.IsNotNull(closedCaption);
Assert.IsNotNull(closedCaption.Info);
Assert.IsNotNull(closedCaption.Captions);

foreach (var caption in closedCaption.Captions)
{
Assert.IsNotNull(caption);
Assert.IsNotNull(caption.Text);
}
}
}
}
190 changes: 0 additions & 190 deletions Tests/YoutubeClientTests.Static.cs

This file was deleted.

Loading