Skip to content

Commit

Permalink
Minor changes to prepare for package release
Browse files Browse the repository at this point in the history
  • Loading branch information
Agash committed May 1, 2024
1 parent bbb0dd7 commit 6403e90
Show file tree
Hide file tree
Showing 9 changed files with 209 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Common/Constants.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace YTLiveChat.Common
{
public class Constants
internal class Constants
{
public const string YTBaseUrl = "https://www.youtube.com";

Expand Down
28 changes: 28 additions & 0 deletions Contracts/Models/Author.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,45 @@
namespace YTLiveChat.Contracts.Models
{
/// <summary>
/// Represents the Author of the message
/// </summary>
public class Author
{
/// <summary>
/// Public name of the Author
/// </summary>
public required string Name { get; set; }

/// <summary>
/// ImagePart containing the Authors Thumbnail
/// </summary>
public ImagePart? Thumbnail { get; set; }

/// <summary>
/// ChannelId if available
/// </summary>
public string? ChannelId { get; set; }

/// <summary>
/// Current Badge of the Author within the Live Channel
/// </summary>
public Badge? Badge { get; set; }

}

/// <summary>
/// Badges available on YouTube for Users
/// </summary>
public class Badge
{
/// <summary>
/// Text representation of the Badge
/// </summary>
public required string Label { get; set; }

/// <summary>
/// ImagePart containing the Badge Thumbnail
/// </summary>
public ImagePart? Thumbnail { get; set; }
}
}
38 changes: 38 additions & 0 deletions Contracts/Models/ChatItem.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,53 @@
namespace YTLiveChat.Contracts.Models
{
/// <summary>
/// ChatItem containing the full object with any MessageParts and Author details
/// </summary>
public class ChatItem
{
/// <summary>
/// Unique Identifier
/// </summary>
public required string Id { get; set; }

/// <summary>
/// Author of the ChatItem
/// </summary>
public required Author Author { get; set; }

/// <summary>
/// Array of all message parts (Image, Text or Emoji variant)
/// </summary>
public required MessagePart[] Message { get; set; }

/// <summary>
/// Contains the Superchat if any was given
/// </summary>
public Superchat? Superchat { get; set; }

/// <summary>
/// Whether or not Author has a Membership on the current Live Channel
/// </summary>
public bool IsMembership { get; set; }

/// <summary>
/// Whether or not Author is Verified on YT
/// </summary>
public bool IsVerified { get; set; }

/// <summary>
/// Whether or not Author is Owner of the current Live Channel
/// </summary>
public bool IsOwner { get; set; }

/// <summary>
/// Whether or not Author is a Moderator of the current Live Channel
/// </summary>
public bool IsModerator { get; set; }

/// <summary>
/// Timestamp of the ChatItem creation
/// </summary>
public DateTime Timestamp { get; set; } = DateTime.Now;
}
}
29 changes: 29 additions & 0 deletions Contracts/Models/MessagePart.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,48 @@
namespace YTLiveChat.Contracts.Models
{
/// <summary>
/// Base class for individual message parts
/// </summary>
public abstract class MessagePart { }

/// <summary>
/// Image variant of a message part
/// </summary>
public class ImagePart : MessagePart
{
/// <summary>
/// URL of the image
/// </summary>
public required string Url { get; set; }
/// <summary>
/// Alt string of the image
/// </summary>
public string? Alt { get; set; }
}

/// <summary>
/// Emoji variant of a message part
/// </summary>
public class EmojiPart : ImagePart
{
/// <summary>
/// Text representation of the emoji
/// </summary>
public required string EmojiText { get; set; }
/// <summary>
/// Whether or not Emoji is a custom emoji of the channel
/// </summary>
public bool IsCustomEmoji { get; set; }
};

/// <summary>
/// Text variant of a message part
/// </summary>
public class TextPart : MessagePart
{
/// <summary>
/// Contained text of the message
/// </summary>
public required string Text { get; set; }
}
}
14 changes: 14 additions & 0 deletions Contracts/Models/Superchat.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
namespace YTLiveChat.Contracts.Models
{
/// <summary>
/// Represents a Superchat
/// </summary>
public class Superchat
{
/// <summary>
/// Amount of $ gifted
/// </summary>
public required string Amount { get; set; }

/// <summary>
/// Color of Superchat
/// </summary>
public required string Color { get; set; }

/// <summary>
/// If Superchat is a sticker, contains an ImagePart with said Sticker
/// </summary>
public ImagePart? Sticker { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,22 @@

namespace YTLiveChat.Contracts
{
public static class ServiceCollectionExtension
/// <summary>
/// Extensions class
/// </summary>
public static class ServiceCollectionExtensions
{
/// <summary>
/// Adds all relevant services as well as the Service backing IYTLiveChat to the ServiceCollection
/// </summary>
/// <param name="services">IServiceCollection to add the services to</param>
/// <returns>return IServiceCollection after the services have been added</returns>
public static IServiceCollection AddYTLiveChat(this IServiceCollection services)
{
_ = services.AddSingleton<IYTLiveChat, YTLiveChat.Services.YTLiveChat>();
_ = services.AddHttpClient<YTHttpClient>("YouTubeClient", x => { x.BaseAddress = new Uri(Constants.YTBaseUrl); });
_ = services.AddSingleton<YTHttpClientFactory>();

return services;
}
}
Expand Down
54 changes: 54 additions & 0 deletions Contracts/Services/IYTLiveChat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,87 @@

namespace YTLiveChat.Contracts.Services
{
/// <summary>
/// Represents the YouTube Live Chat Service
/// </summary>
public interface IYTLiveChat
{
/// <summary>
/// Fires after the initial Live page was loaded
/// </summary>
public event EventHandler<InitialPageLoadedEventArgs>? InitialPageLoaded;

/// <summary>
/// Fires after Chat was stopped
/// </summary>
public event EventHandler<ChatStoppedEventArgs>? ChatStopped;

/// <summary>
/// Fires when a ChatItem was received
/// </summary>
public event EventHandler<ChatReceivedEventArgs>? ChatReceived;

/// <summary>
/// Fires on any error from backend or within service
/// </summary>
public event EventHandler<ErrorOccurredEventArgs>? ErrorOccurred;

/// <summary>
/// Starts the Listeners for the LiveChat and fires InitialPageLoaded when successful. Either <paramref name="handle"/>, <paramref name="channelId"/> or <paramref name="liveId"/> must be given.
/// </summary>
/// <remarks>
/// This method initially loads the stream page from whatever param was given. If called again, it'll simply register the listeners again, but not load another live stream. If another live stream should be loaded, <paramref name="overwrite"/> should be set to true.
/// </remarks>
/// <param name="handle">The handle of the channel (eg. "@Original151")</param>
/// <param name="channelId">The channelId of the channel (eg. "UCtykdsdm9cBfh5JM8xscA0Q")</param>
/// <param name="liveId">The video ID of the live video (eg. "WZafWA1NVrU")</param>
/// <param name="overwrite"></param>
public void Start(string? handle = null, string? channelId = null, string? liveId = null, bool overwrite = false);

/// <summary>
/// Stops the listeners
/// </summary>
public void Stop();

}

/// <summary>
/// EventArgs for InitialPageLoaded event
/// </summary>
public class InitialPageLoadedEventArgs : EventArgs
{
/// <summary>
/// Video ID selected or found
/// </summary>
public required string LiveId { get; set; }
}

/// <summary>
/// EventArgs for ChatStopped event
/// </summary>
public class ChatStoppedEventArgs : EventArgs
{
/// <summary>
/// Reason why the stop occured
/// </summary>
public string? Reason { get; set; }
}

/// <summary>
/// EventArgs for ChatReceived event
/// </summary>
public class ChatReceivedEventArgs : EventArgs
{
/// <summary>
/// ChatItem that was received
/// </summary>
public required ChatItem ChatItem { get; set; }
}

/// <summary>
/// EventArgs for ErrorOccurred event
/// </summary>
/// <param name="exception">Exception that triggered the event</param>
public class ErrorOccurredEventArgs(Exception exception) : ErrorEventArgs(exception)
{
}
Expand Down
38 changes: 29 additions & 9 deletions YTLiveChat.csproj
Original file line number Diff line number Diff line change
@@ -1,14 +1,34 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Authors>Agash Thamo.</Authors>
<Description>InnerTube API for YouTube LiveChat to get Live Chat messages without API restrictions. Mainly intended for use in application for the streamer.</Description>
<PackageProjectUrl>https://github.com/Agash/YTLiveChat/wiki</PackageProjectUrl>
<PackageTags>library, youtube, live-chat, yt, streamer</PackageTags>
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
<PackageReadmeFile>README.md</PackageReadmeFile>

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<PackageId>Agash.YTLiveChat</PackageId>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<EnablePackageValidation>true</EnablePackageValidation>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />
<PackageReference Include="MinVer" Version="5.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="DotNet.ReproducibleBuilds" Version="1.1.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<None Include="LICENSE.txt" Pack="true" PackagePath=""/>
<None Include="README.md" Pack="true" PackagePath=""/>
</ItemGroup>

</Project>
6 changes: 6 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"sdk": {
"rollForward": "feature",
"version": "8.0.204"
}
}

0 comments on commit 6403e90

Please sign in to comment.