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
Next Next commit
Refactor MediaStreamInfo models and some other stuff
  • Loading branch information
Oleksii Holub committed Apr 19, 2017
commit 178b38c6a28919dc508dc4ec4038b96dc204aa4f
21 changes: 13 additions & 8 deletions Tests/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@ public static void IsNotBlank(this Assert assert, string str)
Assert.IsTrue(str.IsNotBlank());
}

public static void IsSet(this Assert assert, UserInfo userInfo)
{
Assert.IsNotNull(userInfo);
Assert.That.IsNotBlank(userInfo.Id);
Assert.That.IsNotBlank(userInfo.Name);
Assert.That.IsNotBlank(userInfo.DisplayName);
Assert.That.IsNotBlank(userInfo.ChannelTitle);
Assert.That.IsNotBlank(userInfo.ChannelUrl);
Assert.That.IsNotBlank(userInfo.ChannelBannerUrl);
Assert.That.IsNotBlank(userInfo.ChannelLogoUrl);
}

public static void IsSet(this Assert assert, VideoInfo videoInfo)
{
Assert.IsNotNull(videoInfo);
Expand All @@ -20,14 +32,7 @@ public static void IsSet(this Assert assert, VideoInfo videoInfo)
Assert.AreNotEqual(0, videoInfo.Duration.TotalSeconds);
Assert.IsNotNull(videoInfo.Description);

Assert.IsNotNull(videoInfo.Author);
Assert.That.IsNotBlank(videoInfo.Author.Id);
Assert.That.IsNotBlank(videoInfo.Author.Name);
Assert.That.IsNotBlank(videoInfo.Author.DisplayName);
Assert.That.IsNotBlank(videoInfo.Author.ChannelTitle);
Assert.That.IsNotBlank(videoInfo.Author.ChannelUrl);
Assert.That.IsNotBlank(videoInfo.Author.ChannelBannerUrl);
Assert.That.IsNotBlank(videoInfo.Author.ChannelLogoUrl);
Assert.That.IsSet(videoInfo.Author);

Assert.IsNotNull(videoInfo.Keywords);
Assert.IsNotNull(videoInfo.Watermarks);
Expand Down
21 changes: 21 additions & 0 deletions YoutubeExplode/Exceptions/ItagMappingException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;

namespace YoutubeExplode.Exceptions
{
/// <summary>
/// Thrown when a mapping between an itag and stream metadata could not be resolved
/// </summary>
public class ItagMappingException : Exception
{
/// <summary>
/// Itag
/// </summary>
public int Itag { get; }

internal ItagMappingException(int itag)
: base($"Could not resolve mapping for itag [{itag}]")
{
Itag = itag;
}
}
}
151 changes: 0 additions & 151 deletions YoutubeExplode/Internal/ItagHelper.cs

This file was deleted.

9 changes: 5 additions & 4 deletions YoutubeExplode/Internal/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using YoutubeExplode.Exceptions;
using YoutubeExplode.Internal.CipherOperations;
using YoutubeExplode.Models;
using YoutubeExplode.Models.Streams;

namespace YoutubeExplode.Internal
{
Expand Down Expand Up @@ -167,8 +168,8 @@ public static IEnumerable<MediaStreamInfo> MediaStreamInfosFromUrlEncoded(string
int width = (dic.GetOrDefault("size")?.SubstringUntil("x")).ParseIntOrDefault();
int height = (dic.GetOrDefault("size")?.SubstringAfter("x")).ParseIntOrDefault();
result.Resolution = width != 0 && height != 0
? new MediaStreamVideoResolution(width, height)
: MediaStreamVideoResolution.Empty;
? new VideoResolution(width, height)
: VideoResolution.Empty;

yield return result;
}
Expand Down Expand Up @@ -202,8 +203,8 @@ public static IEnumerable<MediaStreamInfo> MediaStreamInfosFromXml(string rawXml
int width = (xStreamInfo.Attribute("width")?.Value).ParseIntOrDefault();
int height = (xStreamInfo.Attribute("height")?.Value).ParseIntOrDefault();
result.Resolution = width != 0 && height != 0
? new MediaStreamVideoResolution(width, height)
: MediaStreamVideoResolution.Empty;
? new VideoResolution(width, height)
: VideoResolution.Empty;

yield return result;
}
Expand Down
78 changes: 78 additions & 0 deletions YoutubeExplode/Models/Extensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using System;
using YoutubeExplode.Models.Streams;

namespace YoutubeExplode.Models
{
/// <summary>
/// Model extensions
/// </summary>
public static class Extensions
{
/// <summary>
/// Get file extension based on container type
/// </summary>
public static string GetFileExtension(ContainerType containerType)
{
switch (containerType)
{
case ContainerType.Mp4:
return "mp4";
case ContainerType.M4A:
return "m4a";
case ContainerType.WebM:
return "webm";
case ContainerType.Tgpp:
return "3gpp";
case ContainerType.Flv:
return "flv";
case ContainerType.Ts:
return "ts";
default:
throw new ArgumentOutOfRangeException(nameof(containerType), "Unknown container type");
}
}

/// <summary>
/// Get video quality label based on video quality and framerate
/// </summary>
public static string GetLabel(VideoQuality videoQuality, double framerate = 0)
{
// Video quality
string qualityPart;
if (videoQuality == VideoQuality.Low144)
qualityPart = "144p";

else if (videoQuality == VideoQuality.Low240)
qualityPart = "240p";

else if (videoQuality == VideoQuality.Medium360)
qualityPart = "360p";

else if (videoQuality == VideoQuality.Medium480)
qualityPart = "480p";

else if (videoQuality == VideoQuality.High720)
qualityPart = "720p";

else if (videoQuality == VideoQuality.High1080)
qualityPart = "1080p";

else if (videoQuality == VideoQuality.High1440)
qualityPart = "1440p";

else if (videoQuality == VideoQuality.High2160)
qualityPart = "2160p";

else if (videoQuality == VideoQuality.High3072)
qualityPart = "3072p";

else
throw new ArgumentOutOfRangeException(nameof(videoQuality), "Unknown video quality");

// Framerate
var frameratePart = framerate > 30 ? framerate.ToString("F0") : string.Empty;

return qualityPart + frameratePart;
}
}
}
71 changes: 0 additions & 71 deletions YoutubeExplode/Models/MediaStream.cs

This file was deleted.

Loading