ExtendedYouTubeAPI 1.0.3
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package ExtendedYouTubeAPI --version 1.0.3
NuGet\Install-Package ExtendedYouTubeAPI -Version 1.0.3
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ExtendedYouTubeAPI" Version="1.0.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ExtendedYouTubeAPI --version 1.0.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: ExtendedYouTubeAPI, 1.0.3"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install ExtendedYouTubeAPI as a Cake Addin
#addin nuget:?package=ExtendedYouTubeAPI&version=1.0.3
// Install ExtendedYouTubeAPI as a Cake Tool
#tool nuget:?package=ExtendedYouTubeAPI&version=1.0.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
ExtendedYouTubeAPI
C# library which is used to extend the abilities of YouTube API v3
Features
- DASH manifests generation for videos
- HLS livestreams URLs extraction
- User's history management (list, add, delete, update)
- Watch later playlist management (list, add, delete)
- Video captions retrieval
- User's recommendations listing
- User's subscriptions videos listing
- Videos' URLs retrieval
- UWP authorization helpers
Get started
- Download and install package from NuGet
Authorization (UWP)
using System;
using Google.Apis.Auth.OAuth2;
using YouTube.Authorization;
using Windows.Security.Authentication.Web;
...
ClientSecrets secrets = new ClientSecrets // Initialize your project secrets
{
ClientId = "%CLIENT_ID%",
ClientSecret = "%CLIENT_SECRET%"
}
string[] scopes = new string[] // Define scopes you wanna access
{
Oauth2Service.Scope.UserinfoProfile,
Oauth2Service.Scope.UserinfoEmail,
YouTubeService.Scope.YoutubeForceSsl
};
Uri requestString = AuthorizationHelpers.FormQueryString(secrets, scopes); // Generate authorization link
WebAuthenticationResult result = await WebAuthenticationBroker.AuthenticateAsync(WebAuthenticationOptions.UseTitle, requestString, AuthorizationHelpers.Endpoint); // Call authentication broker with generated query string and predefined endpoint. WebAuthenticationOptions.UseTitle is required
if (result.ResponseStatus == WebAuthenticationStatus.Success) // Process response
{
string successCode = AuthorizationHelpers.ParseSuccessCode(result.ResponseData); // Retrieve success code
YouTube.Authorization.UserCredential credential = await AuthorizationHelpers.ExchangeToken(ClientSecrets, successCode); // Excahnge success token for UserCredential
// Use UserCredential to create YouTube.ExtendedYouTubeService
// Save refresh token for future use. Recommended way: PasswordVault
PasswordVault passwordVault = new PasswordVault();
PasswordCredential tokenData = new PasswordCredential("%ANY_ID%", "%AUTHORIZED_USER_ID%", credential.Token.RefreshToken)
passwordVault.Add(tokenData);
// Update stored refresh token on renew
credential.RefreshTokenUpdated += (s, e) =>
{
tokenData.Password = credential.Token.RefreshToken
}
}
else
{
// Do something
}
Service retrieval
using YouTube;
using YouTube.Authorization;
using Google.Apis.Services;
...
YouTubeExtendedService GetService(UserCredential credential = null)
{
BaseClientService.Initializer initializer = new BaseClientService.Initializer
{
ApplicationName = "%APP_NAME%",
ApiKey = "%API_KEY%", // In case there's no UserCredential and usage is anonymous
HttpClientInitializer = credential
};
ExtendedYouTubeService service = new ExtendedYouTubeService(initializer);
returnt service
}
DASH manifest retrieval
using YouTube;
using YouTube.Models;
using System.Collections.Generic;
using Windows.Media.Playback;
...
ExtendedYouTubeService service = new ExtendedYouTubeService(); // Get the Service
var request = service.DashManifests.List("%VIDEO_ID%");
// request.Id = "%VIDEO_ID%"; // Change video ID after request initialization
IReadOnlyList<DashManifest> manifests = await request.ExecuteAsync(); // Execute request. There will be manifests for all available qualities, including "Auto"
// DashManifest.Label - Quality label
// DashManifest.ValidUntil - After this date URLs in the manifest will be invalid
// DashManifest.Xml - XmlDocument instance of the manifest
Uri manifestUri = manifests[0].WriteManifest(TempFileStream); // Save manifest to temporary file to access it with MediaPlayer
...
// Play video with manifest
MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.Source = MediaSource.CreateFromUri(manifestUri);
mediaPlayer.Play();
Other data
Other resources are retrieved pretty much the same as in the vanilia library
TODO
- Create API Reference page
- Document code
- Setup CI/CD
- Add more tests
- Implement user history management
- Implement search history management
- Implement video recommendations/subscirptions listing
Special thanks
- Tyrrrz for YoutubeExplode library which is used in the my one
Copyrights
©2020 Michael "XFox" Gordeev
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
.NET Framework | net461 is compatible. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETFramework 4.6.1
- AngleSharp (>= 0.14.0)
- Google.Apis (>= 1.45.0)
- Google.Apis.Auth (>= 1.45.0)
- Google.Apis.Core (>= 1.45.0)
- Google.Apis.Oauth2.v2 (>= 1.45.0.1869)
- Google.Apis.YouTube.v3 (>= 1.45.0.1929)
- Microsoft.CSharp (>= 4.7.0)
- YoutubeExplode (>= 5.0.3)
-
.NETStandard 2.1
- AngleSharp (>= 0.14.0)
- Google.Apis (>= 1.45.0)
- Google.Apis.Auth (>= 1.45.0)
- Google.Apis.Core (>= 1.45.0)
- Google.Apis.Oauth2.v2 (>= 1.45.0.1869)
- Google.Apis.YouTube.v3 (>= 1.45.0.1929)
- Microsoft.CSharp (>= 4.7.0)
- YoutubeExplode (>= 5.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.