ExtendedYouTubeAPI 1.0.3
.NET Standard 2.1
.NET Framework 4.6.1
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 |
---|---|
.NET | net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows |
.NET Core | netcoreapp3.0 netcoreapp3.1 |
.NET Standard | netstandard2.1 |
.NET Framework | net461 net462 net463 net47 net471 net472 net48 net481 |
MonoAndroid | monoandroid |
MonoMac | monomac |
MonoTouch | monotouch |
Tizen | tizen60 |
Xamarin.iOS | xamarinios |
Xamarin.Mac | xamarinmac |
Xamarin.TVOS | xamarintvos |
Xamarin.WatchOS | xamarinwatchos |
Compatible target framework(s)
Additional computed target framework(s)
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.