├── .gitattributes ├── .gitignore ├── LICENSE ├── README.md ├── YoutubeSharpApi.ConsoleTest ├── Program.cs └── YoutubeSharpApi.ConsoleTest.csproj ├── YoutubeSharpApi.sln └── YoutubeSharpApi ├── Extensions.cs ├── GeneralExceptions.cs ├── Models ├── EntryPoints.cs ├── GeneralEnums.cs ├── Playlist │ ├── PlaylistEnums.cs │ ├── PlaylistInput.cs │ └── PlaylistOutput.cs ├── StatusEnum.cs ├── Thumbnails.cs └── Trending │ ├── TrendingEnums.cs │ ├── TrendingInput.cs │ └── TrendingOutput.cs ├── YoutubeClient.cs └── YoutubeSharpApi.csproj /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | bld/ 21 | [Bb]in/ 22 | [Oo]bj/ 23 | [Ll]og/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | # MSTest test Results 31 | [Tt]est[Rr]esult*/ 32 | [Bb]uild[Ll]og.* 33 | 34 | # NUNIT 35 | *.VisualState.xml 36 | TestResult.xml 37 | 38 | # Build Results of an ATL Project 39 | [Dd]ebugPS/ 40 | [Rr]eleasePS/ 41 | dlldata.c 42 | 43 | # DNX 44 | project.lock.json 45 | project.fragment.lock.json 46 | artifacts/ 47 | 48 | *_i.c 49 | *_p.c 50 | *_i.h 51 | *.ilk 52 | *.meta 53 | *.obj 54 | *.pch 55 | *.pdb 56 | *.pgc 57 | *.pgd 58 | *.rsp 59 | *.sbr 60 | *.tlb 61 | *.tli 62 | *.tlh 63 | *.tmp 64 | *.tmp_proj 65 | *.log 66 | *.vspscc 67 | *.vssscc 68 | .builds 69 | *.pidb 70 | *.svclog 71 | *.scc 72 | 73 | # Chutzpah Test files 74 | _Chutzpah* 75 | 76 | # Visual C++ cache files 77 | ipch/ 78 | *.aps 79 | *.ncb 80 | *.opendb 81 | *.opensdf 82 | *.sdf 83 | *.cachefile 84 | *.VC.db 85 | *.VC.VC.opendb 86 | 87 | # Visual Studio profiler 88 | *.psess 89 | *.vsp 90 | *.vspx 91 | *.sap 92 | 93 | # TFS 2012 Local Workspace 94 | $tf/ 95 | 96 | # Guidance Automation Toolkit 97 | *.gpState 98 | 99 | # ReSharper is a .NET coding add-in 100 | _ReSharper*/ 101 | *.[Rr]e[Ss]harper 102 | *.DotSettings.user 103 | 104 | # JustCode is a .NET coding add-in 105 | .JustCode 106 | 107 | # TeamCity is a build add-in 108 | _TeamCity* 109 | 110 | # DotCover is a Code Coverage Tool 111 | *.dotCover 112 | 113 | # NCrunch 114 | _NCrunch_* 115 | .*crunch*.local.xml 116 | nCrunchTemp_* 117 | 118 | # MightyMoose 119 | *.mm.* 120 | AutoTest.Net/ 121 | 122 | # Web workbench (sass) 123 | .sass-cache/ 124 | 125 | # Installshield output folder 126 | [Ee]xpress/ 127 | 128 | # DocProject is a documentation generator add-in 129 | DocProject/buildhelp/ 130 | DocProject/Help/*.HxT 131 | DocProject/Help/*.HxC 132 | DocProject/Help/*.hhc 133 | DocProject/Help/*.hhk 134 | DocProject/Help/*.hhp 135 | DocProject/Help/Html2 136 | DocProject/Help/html 137 | 138 | # Click-Once directory 139 | publish/ 140 | 141 | # Publish Web Output 142 | *.[Pp]ublish.xml 143 | *.azurePubxml 144 | # TODO: Comment the next line if you want to checkin your web deploy settings 145 | # but database connection strings (with potential passwords) will be unencrypted 146 | #*.pubxml 147 | *.publishproj 148 | 149 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 150 | # checkin your Azure Web App publish settings, but sensitive information contained 151 | # in these scripts will be unencrypted 152 | PublishScripts/ 153 | 154 | # NuGet Packages 155 | *.nupkg 156 | # The packages folder can be ignored because of Package Restore 157 | **/packages/* 158 | # except build/, which is used as an MSBuild target. 159 | !**/packages/build/ 160 | # Uncomment if necessary however generally it will be regenerated when needed 161 | #!**/packages/repositories.config 162 | # NuGet v3's project.json files produces more ignoreable files 163 | *.nuget.props 164 | *.nuget.targets 165 | 166 | # Microsoft Azure Build Output 167 | csx/ 168 | *.build.csdef 169 | 170 | # Microsoft Azure Emulator 171 | ecf/ 172 | rcf/ 173 | 174 | # Windows Store app package directories and files 175 | AppPackages/ 176 | BundleArtifacts/ 177 | Package.StoreAssociation.xml 178 | _pkginfo.txt 179 | 180 | # Visual Studio cache files 181 | # files ending in .cache can be ignored 182 | *.[Cc]ache 183 | # but keep track of directories ending in .cache 184 | !*.[Cc]ache/ 185 | 186 | # Others 187 | ClientBin/ 188 | ~$* 189 | *~ 190 | *.dbmdl 191 | *.dbproj.schemaview 192 | *.jfm 193 | *.pfx 194 | *.publishsettings 195 | node_modules/ 196 | orleans.codegen.cs 197 | 198 | # Since there are multiple workflows, uncomment next line to ignore bower_components 199 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 200 | #bower_components/ 201 | 202 | # RIA/Silverlight projects 203 | Generated_Code/ 204 | 205 | # Backup & report files from converting an old project file 206 | # to a newer Visual Studio version. Backup files are not needed, 207 | # because we have git ;-) 208 | _UpgradeReport_Files/ 209 | Backup*/ 210 | UpgradeLog*.XML 211 | UpgradeLog*.htm 212 | 213 | # SQL Server files 214 | *.mdf 215 | *.ldf 216 | 217 | # Business Intelligence projects 218 | *.rdl.data 219 | *.bim.layout 220 | *.bim_*.settings 221 | 222 | # Microsoft Fakes 223 | FakesAssemblies/ 224 | 225 | # GhostDoc plugin setting file 226 | *.GhostDoc.xml 227 | 228 | # Node.js Tools for Visual Studio 229 | .ntvs_analysis.dat 230 | 231 | # Visual Studio 6 build log 232 | *.plg 233 | 234 | # Visual Studio 6 workspace options file 235 | *.opt 236 | 237 | # Visual Studio LightSwitch build output 238 | **/*.HTMLClient/GeneratedArtifacts 239 | **/*.DesktopClient/GeneratedArtifacts 240 | **/*.DesktopClient/ModelManifest.xml 241 | **/*.Server/GeneratedArtifacts 242 | **/*.Server/ModelManifest.xml 243 | _Pvt_Extensions 244 | 245 | # Paket dependency manager 246 | .paket/paket.exe 247 | paket-files/ 248 | 249 | # FAKE - F# Make 250 | .fake/ 251 | 252 | # JetBrains Rider 253 | .idea/ 254 | *.sln.iml 255 | 256 | # CodeRush 257 | .cr/ 258 | 259 | # Python Tools for Visual Studio (PTVS) 260 | __pycache__/ 261 | *.pyc -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 2-Clause License 2 | 3 | Copyright (c) 2021, OMANSAK 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | * Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Youtube Sharp Api 2 | =============== 3 | 4 | [![NuGet](https://img.shields.io/nuget/dt/YoutubeSharpApi.svg)](https://www.nuget.org/packages/YoutubeSharpApi) 5 | [![NuGet](https://img.shields.io/nuget/v/YoutubeSharpApi.svg)](https://www.nuget.org/packages/YoutubeSharpApi) 6 | [![license](https://img.shields.io/github/license/omansak/YoutubeSharpApi.svg)](LICENSE) 7 | [![Join the chat at https://discord.gg/SERVhPp](https://user-images.githubusercontent.com/7288322/34429152-141689f8-ecb9-11e7-8003-b5a10a5fcb29.png)](https://discord.gg/SERVhPp) 8 | 9 | A minimal .NET STANDART wrapper for the Youtube Data API v3. Designed to let devs easily 10 | fetch public data (Playlists info,Trending) from Youtube. 11 | The reason of returning the decoded JSON response directly is that you only need to read the Google API doc 12 | to use this library. 13 | 14 | ## Supported Platforms 15 | - NET ve .NET Core | 2.0, 2.1, 2.2, 3.0, 3.1, 5.0, 6.0 16 | - .NET Framework | 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8 17 | - Mono | 5.4, 6.4 18 | - Xamarin.iOS | 10.14, 12.16 19 | - Xamarin.Mac | 3.8, 5.16 20 | - Xamarin.Android | 8.0, 10.0 21 | - Universal Windows Platform | 10.0.16299, TBD 22 | - Unity | 2018, 23 | 24 | ## Features 25 | * Get Playlist Info All or Pagination 26 | * Get Trending Info All or Pagination 27 | * 90 Regions / 31 Youtube Category 28 | 29 | ## Requirements 30 | * Newtonsoft Json Library 31 | 32 | ## Usage 33 | ```c# 34 | var youtubeClient = new YoutubeClient("-- your api key --"); 35 | 36 | var response = await youtubeClient.GetPlayListAsync( 37 | new PlaylistInput{ 38 | PlaylistId = "-- playlist url --"}, CancellationToken.None)); 39 | var response = await youtubeClient.GetTrendingAsync( 40 | new TrendingInput{ 41 | Category = TrendingEnums.Categories.Music, 42 | Region = TrendingEnums.Regions.Turkey}), CancellationToken.None); 43 | ``` 44 | With Paging 45 | ```c# 46 | var youtubeClient = new YoutubeClient("-- your api key --"); 47 | 48 | var trendingInput = new TrendingInput() 49 | { 50 | MaxResultPerPage = 20, 51 | Category = TrendingEnums.Categories.Music, 52 | Region = TrendingEnums.Regions.Turkey 53 | }; 54 | 55 | var response = await youtubeClient.GetTrendingWithPagingAsync(trendingInput, token: new CancellationToken()); 56 | playlistInput.PageToken = responsePlaylistPaging.NextPage; // important to next page 57 | 58 | ``` 59 | Output 60 | ```c# 61 | public string Kind { get; set; } 62 | public string NextPage { get; set; } 63 | public int TotalResults { get; set; } 64 | public List VideosData { get; set; } 65 | public class Videos 66 | { 67 | public string Title { get; set; } 68 | public string VideoId { get; set; } 69 | public int Position { get; set; } 70 | public string Description { get; set; } 71 | public DateTime PublishedAt { get; set; } 72 | public string ChannelId { get; set; } 73 | public string ChannelTitle { get; set; } 74 | public string Kind { get; set; } 75 | public List ThumbnailsData { get; set; } 76 | } 77 | 78 | public PlaylistOutput() 79 | { 80 | this.VideosData = new List(); 81 | } 82 | ``` 83 | 84 | ## Youtube Data API v3 85 | - [Youtube Data API v3 Doc](https://developers.google.com/youtube/v3/) 86 | - [Obtain API key from Google API Console](http://code.google.com/apis/console) 87 | 88 | ## Contact 89 | 90 | For bugs, complain and suggestions please [file an Issue here](https://github.com/omansak/YoutubeSharpApi/issues) 91 | -------------------------------------------------------------------------------- /YoutubeSharpApi.ConsoleTest/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading; 3 | using System.Threading.Tasks; 4 | using YoutubeSharpApi.Models.Playlist; 5 | using YoutubeSharpApi.Models.Trending; 6 | 7 | namespace YoutubeSharpApi.ConsoleTest 8 | { 9 | class Program 10 | { 11 | private static string _apiKey = "--- YOUR API KEY ---"; // https://developers.google.com/youtube/v3/getting-started 12 | private static string _playlistId = "PLzByySESNL7GKiOXOs7ew5vEFBxuJvf0D"; // https://www.youtube.com/playlist?list=PLzByySESNL7GKiOXOs7ew5vEFBxuJvf0D 13 | static void Main(string[] args) 14 | { 15 | Console.WriteLine($"--- --- --- --- Playlist --- --- --- ---"); 16 | var youtubeClient = new YoutubeClient(_apiKey); 17 | var response = Task.Run(() => youtubeClient.GetPlayListAsync(new PlaylistInput 18 | { 19 | PlaylistId = _playlistId 20 | }, CancellationToken.None)).Result; 21 | 22 | foreach (var item in response.VideosData) 23 | { 24 | Console.WriteLine($"{item.Position} - {item.Title} (Video Id : {item.VideoId})"); 25 | } 26 | 27 | 28 | 29 | Console.WriteLine($"--- --- --- --- Trendings --- --- --- ---"); 30 | var responseTrending = Task.Run(() => youtubeClient.GetTrendingAsync(new TrendingInput 31 | { 32 | Category = TrendingEnums.Categories.Music, 33 | Region = TrendingEnums.Regions.Turkey 34 | }), CancellationToken.None).Result; 35 | 36 | int i = 0; 37 | foreach (var item in responseTrending.VideosData) 38 | { 39 | Console.WriteLine($"{++i} - {item.Title} (Video Id : {item.VideoId}) ({item.CategoryId} | {item.Category.ToString()})"); 40 | } 41 | 42 | 43 | 44 | 45 | Console.WriteLine($"--- --- --- --- Playlist With Pagging --- --- --- ---"); 46 | var playlistInput = new PlaylistInput 47 | { 48 | MaxResultPerPage = 20, 49 | PlaylistId = _playlistId 50 | }; 51 | 52 | for (int j = 0; j < 3; j++) 53 | { 54 | Console.WriteLine("Page : " + j); 55 | var responsePlaylistPaging = Task.Run(() => youtubeClient.GetPlaylistWithPagingAsync(playlistInput, token: new CancellationToken())).Result; 56 | playlistInput.PageToken = responsePlaylistPaging.NextPage; 57 | foreach (var item in responsePlaylistPaging.VideosData) 58 | { 59 | Console.WriteLine($"{item.Position} - {item.Title} (Video Id : {item.VideoId})"); 60 | } 61 | } 62 | 63 | 64 | 65 | Console.WriteLine($"--- --- --- --- Trending With Pagging --- --- --- ---"); 66 | var trendingInput = new TrendingInput() 67 | { 68 | MaxResultPerPage = 20, 69 | Category = TrendingEnums.Categories.Music, 70 | Region = TrendingEnums.Regions.Turkey 71 | }; 72 | int k = 0; 73 | for (int j = 0; j < 3; j++) 74 | { 75 | Console.WriteLine("Page : " + j); 76 | var responsePlaylistPaging = Task.Run(() => youtubeClient.GetTrendingWithPagingAsync(trendingInput, token: new CancellationToken())).Result; 77 | playlistInput.PageToken = responsePlaylistPaging.NextPage; 78 | foreach (var item in responsePlaylistPaging.VideosData) 79 | { 80 | Console.WriteLine($"{++k} - {item.Title} (Video Id : {item.VideoId})"); 81 | } 82 | } 83 | Console.ReadKey(); 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /YoutubeSharpApi.ConsoleTest/YoutubeSharpApi.ConsoleTest.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net6.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /YoutubeSharpApi.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28010.2046 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "YoutubeSharpApi", "YoutubeSharpApi\YoutubeSharpApi.csproj", "{606CA416-0E01-40D7-8495-E77A3AB8A759}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "YoutubeSharpApi.ConsoleTest", "YoutubeSharpApi.ConsoleTest\YoutubeSharpApi.ConsoleTest.csproj", "{759F58EE-D3C9-47A3-842B-1CAA098D4E48}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {606CA416-0E01-40D7-8495-E77A3AB8A759}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {606CA416-0E01-40D7-8495-E77A3AB8A759}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {606CA416-0E01-40D7-8495-E77A3AB8A759}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {606CA416-0E01-40D7-8495-E77A3AB8A759}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {759F58EE-D3C9-47A3-842B-1CAA098D4E48}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {759F58EE-D3C9-47A3-842B-1CAA098D4E48}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {759F58EE-D3C9-47A3-842B-1CAA098D4E48}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {759F58EE-D3C9-47A3-842B-1CAA098D4E48}.Release|Any CPU.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {2ED7AB2A-78B1-4AC0-A52B-6F02E83E70EA} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /YoutubeSharpApi/Extensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using Newtonsoft.Json.Linq; 5 | using YoutubeSharpApi.Models.Playlist; 6 | 7 | namespace YoutubeSharpApi 8 | { 9 | public static class Extensions 10 | { 11 | public static int SetMaxResultPerPage(this int maxResults) 12 | { 13 | if (maxResults > 50) 14 | return 50; 15 | if (maxResults < 0) 16 | return 5; 17 | return maxResults; 18 | } 19 | public static bool IsNullOrEmpty(this JToken token) 20 | { 21 | return (token == null) || 22 | (token.Type == JTokenType.Array && !token.HasValues) || 23 | (token.Type == JTokenType.Object && !token.HasValues) || 24 | (token.Type == JTokenType.String && token.ToString() == System.String.Empty) || 25 | (token.Type == JTokenType.Null); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /YoutubeSharpApi/GeneralExceptions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using Newtonsoft.Json.Linq; 5 | 6 | namespace YoutubeSharpApi 7 | { 8 | public class GeneralExceptions 9 | { 10 | public Exception HandlePlaylistExceptions(int code, string content) 11 | { 12 | JObject obj = JObject.Parse(content); 13 | string exceptionMessage = string.Empty; 14 | int errorCode = int.Parse(obj["error"]["code"].ToString()); 15 | foreach (var e in obj["error"]["errors"]) 16 | { 17 | exceptionMessage += $"({e["reason"]}) {e["reason"]} : {e["message"]})"; 18 | } 19 | switch (errorCode) 20 | { 21 | case 400: 22 | return new BadRequest(exceptionMessage); 23 | case 403: 24 | return new ForbiddenException(exceptionMessage); 25 | case 404: 26 | return new NotFoundException(exceptionMessage); 27 | default: 28 | return new Exception(exceptionMessage); 29 | } 30 | } 31 | 32 | private class NotFoundException : Exception 33 | { 34 | public NotFoundException(string message) : base(message) { } 35 | } 36 | private class ForbiddenException : Exception 37 | { 38 | public ForbiddenException(string message) : base(message) { } 39 | } 40 | private class BadRequest : Exception 41 | { 42 | public BadRequest(string message) : base(message) { } 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /YoutubeSharpApi/Models/EntryPoints.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace YoutubeSharpApi.Models 6 | { 7 | public static class EntryPoints 8 | { 9 | public static string Playlist = "playlistItems"; 10 | public static string Videos = "videos"; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /YoutubeSharpApi/Models/GeneralEnums.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace YoutubeSharpApi.Models 6 | { 7 | public class GeneralEnums 8 | { 9 | public enum ImageThumbnails 10 | { 11 | Default, 12 | Medium, 13 | High, 14 | Standard, 15 | MaxResolution 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /YoutubeSharpApi/Models/Playlist/PlaylistEnums.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace YoutubeSharpApi.Models.Playlist 6 | { 7 | public class PlaylistEnums 8 | { 9 | 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /YoutubeSharpApi/Models/Playlist/PlaylistInput.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace YoutubeSharpApi.Models.Playlist 6 | { 7 | public class PlaylistInput 8 | { 9 | // * : Required 10 | public string PlaylistId { get; set; } // * 11 | public string PageToken { get; set; } 12 | public int MaxResultPerPage { get; set; } 13 | 14 | public PlaylistInput() 15 | { 16 | PageToken = null; 17 | this.MaxResultPerPage = 25; 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /YoutubeSharpApi/Models/Playlist/PlaylistOutput.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace YoutubeSharpApi.Models.Playlist 6 | { 7 | public class PlaylistOutput 8 | { 9 | public string Kind { get; set; } 10 | public string NextPage { get; set; } 11 | public int TotalResults { get; set; } 12 | public List VideosData { get; set; } 13 | public class Videos 14 | { 15 | public string Title { get; set; } 16 | public string VideoId { get; set; } 17 | public int Position { get; set; } 18 | public string Description { get; set; } 19 | public DateTime PublishedAt { get; set; } 20 | public string ChannelId { get; set; } 21 | public string ChannelTitle { get; set; } 22 | public string Kind { get; set; } 23 | public List ThumbnailsData { get; set; } 24 | } 25 | 26 | public PlaylistOutput() 27 | { 28 | this.VideosData = new List(); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /YoutubeSharpApi/Models/StatusEnum.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace YoutubeSharpApi.Models 6 | { 7 | public class StatusEnum 8 | { 9 | public enum HttpCodes 10 | { 11 | Success, 12 | NotFound, 13 | Forbidden, 14 | Error 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /YoutubeSharpApi/Models/Thumbnails.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace YoutubeSharpApi.Models 6 | { 7 | public class Thumbnails 8 | { 9 | public GeneralEnums.ImageThumbnails Kind { get; set; } 10 | public Uri ImageUri { get; set; } 11 | public int Width { get; set; } 12 | public int Height { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /YoutubeSharpApi/Models/Trending/TrendingEnums.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace YoutubeSharpApi.Models.Trending 7 | { 8 | public class TrendingEnums 9 | { 10 | public string GetCodeOfRegion(Regions region) 11 | { 12 | string code; 13 | if (!_mapRegions.TryGetValue(region, out code)) 14 | { 15 | throw new NullReferenceException($"Code of {nameof(region)} not found."); 16 | } 17 | return code; 18 | } 19 | 20 | public Regions GetRegionOfCode(string code) 21 | { 22 | if (_mapRegions.Any(i => i.Value == code)) 23 | { 24 | return _mapRegions.First(i => i.Value == code).Key; 25 | } 26 | else 27 | { 28 | throw new NullReferenceException($"Region of {code} not found."); 29 | } 30 | 31 | } 32 | private static Dictionary _mapRegions = new Dictionary 33 | { 34 | { Regions.Algeria,"DZ"}, 35 | { Regions.Argentina,"AR"}, 36 | { Regions.Australia,"AU"}, 37 | { Regions.Austria,"AT"}, 38 | { Regions.Azerbaijan,"AZ"}, 39 | { Regions.Bahrain,"BH"}, 40 | { Regions.Belarus,"BY"}, 41 | { Regions.Belgium,"BE"}, 42 | { Regions.BosniaAndHerzegovina,"BA"}, 43 | { Regions.Brazil,"BR"}, 44 | { Regions.Bulgaria,"BG"}, 45 | { Regions.Canada,"CA"}, 46 | { Regions.Chile,"CL"}, 47 | { Regions.Colombia,"CO"}, 48 | { Regions.Croatia,"HR"}, 49 | { Regions.Czechia,"CZ"}, 50 | { Regions.Denmark,"DK"}, 51 | { Regions.Egypt,"EG"}, 52 | { Regions.Estonia,"EE"}, 53 | { Regions.Finland,"FI"}, 54 | { Regions.France,"FR"}, 55 | { Regions.Georgia,"GE"}, 56 | { Regions.Germany,"DE"}, 57 | { Regions.Ghana,"GH"}, 58 | { Regions.Greece,"GR"}, 59 | { Regions.HongKong,"HK"}, 60 | { Regions.Hungary,"HU"}, 61 | { Regions.Iceland,"IS"}, 62 | { Regions.India,"IN"}, 63 | { Regions.Indonesia,"ID"}, 64 | { Regions.Iraq,"IQ"}, 65 | { Regions.Ireland,"IE"}, 66 | { Regions.Israel,"IL"}, 67 | { Regions.Italy,"IT"}, 68 | { Regions.Jamaica,"JM"}, 69 | { Regions.Japan,"JP"}, 70 | { Regions.Jordan,"JO"}, 71 | { Regions.Kazakhstan,"KZ"}, 72 | { Regions.Kenya,"KE"}, 73 | { Regions.Kuwait,"KW"}, 74 | { Regions.Latvia,"LV"}, 75 | { Regions.Lebanon,"LB"}, 76 | { Regions.Libya,"LY"}, 77 | { Regions.Lithuania,"LT"}, 78 | { Regions.Luxembourg,"LU"}, 79 | { Regions.Macedonia,"MK"}, 80 | { Regions.Malaysia,"MY"}, 81 | { Regions.Malta,"MT"}, 82 | { Regions.Mexico,"MX"}, 83 | { Regions.Montenegro,"ME"}, 84 | { Regions.Morocco,"MA"}, 85 | { Regions.Nepal,"NP"}, 86 | { Regions.Netherlands,"NL"}, 87 | { Regions.NewZealand,"NZ"}, 88 | { Regions.Nigeria,"NG"}, 89 | { Regions.Norway,"NO"}, 90 | { Regions.Oman,"OM"}, 91 | { Regions.Pakistan,"PK"}, 92 | { Regions.Peru,"PE"}, 93 | { Regions.Philippines,"PH"}, 94 | { Regions.Poland,"PL"}, 95 | { Regions.Portugal,"PT"}, 96 | { Regions.PuertoRico,"PR"}, 97 | { Regions.Qatar,"QA"}, 98 | { Regions.Romania,"RO"}, 99 | { Regions.Russia,"RU"}, 100 | { Regions.SaudiArabia,"SA"}, 101 | { Regions.Senegal,"SN"}, 102 | { Regions.Serbia,"RS"}, 103 | { Regions.Singapore,"SG"}, 104 | { Regions.Slovakia,"SK"}, 105 | { Regions.Slovenia,"SI"}, 106 | { Regions.SouthAfrica,"ZA"}, 107 | { Regions.SouthKorea,"KR"}, 108 | { Regions.Spain,"ES"}, 109 | { Regions.SriLanka,"LK"}, 110 | { Regions.Sweden,"SE"}, 111 | { Regions.Switzerland,"CH"}, 112 | { Regions.Taiwan,"TW"}, 113 | { Regions.Tanzania,"TZ"}, 114 | { Regions.Thailand,"TH"}, 115 | { Regions.Tunisia,"TN"}, 116 | { Regions.Turkey,"TR"}, 117 | { Regions.Uganda,"UG"}, 118 | { Regions.Ukraine,"UA"}, 119 | { Regions.UnitedArabEmirates,"AE"}, 120 | { Regions.UnitedKingdom,"GB"}, 121 | { Regions.UnitedStates,"US"}, 122 | { Regions.Vietnam,"VN"}, 123 | { Regions.Yemen,"YE"}, 124 | { Regions.Zimbabwe,"ZW"}, 125 | }; 126 | public enum Regions 127 | { 128 | Algeria, 129 | Argentina, 130 | Australia, 131 | Austria, 132 | Azerbaijan, 133 | Bahrain, 134 | Belarus, 135 | Belgium, 136 | BosniaAndHerzegovina, 137 | Brazil, 138 | Bulgaria, 139 | Canada, 140 | Chile, 141 | Colombia, 142 | Croatia, 143 | Czechia, 144 | Denmark, 145 | Egypt, 146 | Estonia, 147 | Finland, 148 | France, 149 | Georgia, 150 | Germany, 151 | Ghana, 152 | Greece, 153 | HongKong, 154 | Hungary, 155 | Iceland, 156 | India, 157 | Indonesia, 158 | Iraq, 159 | Ireland, 160 | Israel, 161 | Italy, 162 | Jamaica, 163 | Japan, 164 | Jordan, 165 | Kazakhstan, 166 | Kenya, 167 | Kuwait, 168 | Latvia, 169 | Lebanon, 170 | Libya, 171 | Lithuania, 172 | Luxembourg, 173 | Macedonia, 174 | Malaysia, 175 | Malta, 176 | Mexico, 177 | Montenegro, 178 | Morocco, 179 | Nepal, 180 | Netherlands, 181 | NewZealand, 182 | Nigeria, 183 | Norway, 184 | Oman, 185 | Pakistan, 186 | Peru, 187 | Philippines, 188 | Poland, 189 | Portugal, 190 | PuertoRico, 191 | Qatar, 192 | Romania, 193 | Russia, 194 | SaudiArabia, 195 | Senegal, 196 | Serbia, 197 | Singapore, 198 | Slovakia, 199 | Slovenia, 200 | SouthAfrica, 201 | SouthKorea, 202 | Spain, 203 | SriLanka, 204 | Sweden, 205 | Switzerland, 206 | Taiwan, 207 | Tanzania, 208 | Thailand, 209 | Tunisia, 210 | Turkey, 211 | Uganda, 212 | Ukraine, 213 | UnitedArabEmirates, 214 | UnitedKingdom, 215 | UnitedStates, 216 | Vietnam, 217 | Yemen, 218 | Zimbabwe, 219 | 220 | } 221 | public enum Categories 222 | { 223 | FilmAnimation = 1, 224 | AutosVehicles = 2, 225 | Music = 10, 226 | PetsAnimals = 15, 227 | Sports = 17, 228 | ShortMovies = 18, 229 | TravelEvents = 19, 230 | Gaming = 20, 231 | Videoblogging = 21, 232 | PeopleBlogs = 22, 233 | Comedy_23 = 23, 234 | Entertainment = 24, 235 | NewsPolitics = 25, 236 | HowtoStyle = 26, 237 | Education = 27, 238 | ScienceTechnology = 28, 239 | NonprofitsActivism = 29, 240 | Movies = 30, 241 | AnimeAnimation = 31, 242 | ActionAdventure = 32, 243 | Classics = 33, 244 | Comedy_34 = 34, 245 | Documentary = 35, 246 | Drama = 36, 247 | Family = 37, 248 | Foreign = 38, 249 | Horror = 39, 250 | SciFiFantasy = 40, 251 | Thriller = 41, 252 | Shorts = 42, 253 | Shows = 43, 254 | Trailers = 44, 255 | 256 | 257 | 258 | } 259 | } 260 | } 261 | -------------------------------------------------------------------------------- /YoutubeSharpApi/Models/Trending/TrendingInput.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace YoutubeSharpApi.Models.Trending 6 | { 7 | public class TrendingInput 8 | { 9 | public TrendingEnums.Regions Region { get; set; } 10 | public TrendingEnums.Categories Category { get; set; } 11 | public string PageToken { get; set; } 12 | public int MaxResultPerPage { get; set; } 13 | 14 | public TrendingInput() 15 | { 16 | this.PageToken = null; 17 | this.MaxResultPerPage = 25; 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /YoutubeSharpApi/Models/Trending/TrendingOutput.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace YoutubeSharpApi.Models.Trending 6 | { 7 | public class TrendingOutput 8 | { 9 | public string Kind { get; set; } 10 | public string NextPage { get; set; } 11 | public int TotalResults { get; set; } 12 | public List VideosData { get; set; } 13 | public class Videos 14 | { 15 | public string Title { get; set; } 16 | public string VideoId { get; set; } 17 | public string Description { get; set; } 18 | public DateTime PublishedAt { get; set; } 19 | public string ChannelId { get; set; } 20 | public string ChannelTitle { get; set; } 21 | public string Kind { get; set; } 22 | public int CategoryId { get; set; } 23 | public TrendingEnums.Categories Category { get; set; } 24 | public List ThumbnailsData { get; set; } 25 | 26 | } 27 | 28 | public TrendingOutput() 29 | { 30 | this.VideosData = new List(); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /YoutubeSharpApi/YoutubeClient.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json.Linq; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Net.Http; 5 | using System.Net.Http.Headers; 6 | using System.Threading; 7 | using System.Threading.Tasks; 8 | using YoutubeSharpApi.Models; 9 | using YoutubeSharpApi.Models.Playlist; 10 | using YoutubeSharpApi.Models.Trending; 11 | 12 | namespace YoutubeSharpApi 13 | { 14 | 15 | public class YoutubeClient 16 | { 17 | private static HttpClient _httpClient; 18 | private static readonly string _baseUri = "https://www.googleapis.com/youtube/v3/"; 19 | private static string _apiKey; 20 | public YoutubeClient(string apiKey) 21 | { 22 | _apiKey = apiKey; 23 | } 24 | public async Task GetPlayListAsync(PlaylistInput input, CancellationToken token = new CancellationToken()) 25 | { 26 | return await this.GetPlayListItemsAsync(input, token, false); 27 | } 28 | public async Task GetPlaylistWithPagingAsync(PlaylistInput input, CancellationToken token = new CancellationToken()) 29 | { 30 | return await this.GetPlayListItemsAsync(input, token, true); 31 | } 32 | public async Task GetTrendingAsync(TrendingInput input, CancellationToken token = new CancellationToken()) 33 | { 34 | return await this.GetTrendingItemsAsync(input, token, false); 35 | } 36 | public async Task GetTrendingWithPagingAsync(TrendingInput input, CancellationToken token = new CancellationToken()) 37 | { 38 | return await this.GetTrendingItemsAsync(input, token, true); 39 | } 40 | private async Task GetPlayListItemsAsync(PlaylistInput input, CancellationToken token, bool paging) 41 | { 42 | JObject listJson; 43 | PlaylistOutput output = new PlaylistOutput(); 44 | do 45 | { 46 | listJson = JObject.Parse(await GetJsonAsync(input, InputType.Playlist, token)); 47 | output.TotalResults = int.Parse(listJson["pageInfo"]["totalResults"].ToString()); 48 | input.PageToken = listJson["nextPageToken"].IsNullOrEmpty() != true ? listJson["nextPageToken"].ToString() : null; 49 | output.NextPage = input.PageToken; 50 | foreach (var item in listJson["items"]) 51 | { 52 | output.VideosData.Add(SetPlaylistContainsDetails(item["snippet"])); 53 | output.TotalResults++; 54 | } 55 | } while (!listJson["nextPageToken"].IsNullOrEmpty() && !paging); 56 | return output; 57 | } 58 | private async Task GetTrendingItemsAsync(TrendingInput input, CancellationToken token, bool paging) 59 | { 60 | JObject listJson; 61 | TrendingOutput output = new TrendingOutput(); 62 | do 63 | { 64 | listJson = JObject.Parse(await GetJsonAsync(input, InputType.Trending, token)); 65 | output.TotalResults = int.Parse(listJson["pageInfo"]["totalResults"].ToString()); 66 | input.PageToken = listJson["nextPageToken"].IsNullOrEmpty() != true ? listJson["nextPageToken"].ToString() : null; 67 | output.NextPage = input.PageToken; 68 | foreach (var item in listJson["items"]) 69 | { 70 | output.VideosData.Add(SetTrendingContainsDetails(item)); 71 | output.TotalResults++; 72 | } 73 | } while (!listJson["nextPageToken"].IsNullOrEmpty() && !paging); 74 | 75 | return output; 76 | } 77 | private async Task GetJsonAsync(object input, InputType type, CancellationToken token) 78 | { 79 | using (_httpClient = new HttpClient()) 80 | { 81 | _httpClient.BaseAddress = new Uri(_baseUri); 82 | _httpClient.DefaultRequestHeaders.Accept.Clear(); 83 | _httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); 84 | Uri requrestUri; 85 | switch (type) 86 | { 87 | case InputType.Playlist: 88 | { 89 | requrestUri = CreatePlaylistClientUri((PlaylistInput)input); 90 | break; 91 | } 92 | case InputType.Trending: 93 | { 94 | requrestUri = CreateTredingClientUri((TrendingInput)input); 95 | break; 96 | } 97 | default: 98 | throw new ArgumentOutOfRangeException(nameof(type), type, null); 99 | } 100 | using (var response = await _httpClient.GetAsync(requrestUri, token)) 101 | { 102 | using (var content = response.Content) 103 | { 104 | if (response.IsSuccessStatusCode) 105 | { 106 | return await content.ReadAsStringAsync(); 107 | } 108 | throw new GeneralExceptions().HandlePlaylistExceptions((int)response.StatusCode, await response.Content.ReadAsStringAsync()); 109 | } 110 | } 111 | } 112 | } 113 | private Uri CreatePlaylistClientUri(PlaylistInput input) 114 | { 115 | if (string.IsNullOrEmpty(_apiKey)) throw new ArgumentNullException(nameof(_apiKey), "Api Key can not be null"); 116 | if (string.IsNullOrEmpty(input.PlaylistId)) throw new ArgumentNullException(nameof(input.PlaylistId), "PlaylistId can not be null"); 117 | UriBuilder builder = new UriBuilder(_baseUri + EntryPoints.Playlist) 118 | { 119 | Query = $"key={_apiKey}&" + 120 | "part=snippet&" + 121 | $"playlistId={input.PlaylistId}&" + 122 | $"maxResults={input.MaxResultPerPage.SetMaxResultPerPage()}&" + 123 | $"pageToken={input.PageToken}" 124 | }; 125 | return builder.Uri; 126 | } 127 | private Uri CreateTredingClientUri(TrendingInput input) 128 | { 129 | if (string.IsNullOrEmpty(_apiKey)) throw new ArgumentNullException(nameof(_apiKey), "Api Key can not be null"); 130 | if (input.Category == default(int)) throw new ArgumentNullException(nameof(input.Category), "Category can not be null"); 131 | UriBuilder builder = new UriBuilder(_baseUri + EntryPoints.Videos) 132 | { 133 | Query = $"key={_apiKey}&" + 134 | "part=snippet&" + 135 | "chart=mostPopular&" + 136 | $"maxResults={input.MaxResultPerPage.SetMaxResultPerPage()}&" + 137 | $"pageToken={input.PageToken}&" + 138 | $"regionCode={new TrendingEnums().GetCodeOfRegion(input.Region)}&" + 139 | $"videoCategoryId={(int)input.Category}" 140 | }; 141 | return builder.Uri; 142 | } 143 | private List SetThumbnails(JToken jsonData) 144 | { 145 | if (jsonData["thumbnails"].IsNullOrEmpty() != true) 146 | { 147 | List videoImages = new List(); 148 | if (!jsonData["thumbnails"]["default"].IsNullOrEmpty()) 149 | { 150 | videoImages.Add(new Thumbnails 151 | { 152 | Kind = GeneralEnums.ImageThumbnails.Default, 153 | ImageUri = new Uri(jsonData["thumbnails"]["default"]["url"].ToString()), 154 | Height = int.Parse(jsonData["thumbnails"]["default"]["height"].ToString()), 155 | Width = int.Parse(jsonData["thumbnails"]["default"]["width"].ToString()) 156 | }); 157 | } 158 | if (!jsonData["thumbnails"]["medium"].IsNullOrEmpty()) 159 | { 160 | videoImages.Add(new Thumbnails 161 | { 162 | Kind = GeneralEnums.ImageThumbnails.Medium, 163 | ImageUri = new Uri(jsonData["thumbnails"]["medium"]["url"].ToString()), 164 | Height = int.Parse(jsonData["thumbnails"]["medium"]["height"].ToString()), 165 | Width = int.Parse(jsonData["thumbnails"]["medium"]["width"].ToString()) 166 | }); 167 | } 168 | if (!jsonData["thumbnails"]["high"].IsNullOrEmpty()) 169 | { 170 | videoImages.Add(new Thumbnails 171 | { 172 | Kind = GeneralEnums.ImageThumbnails.High, 173 | ImageUri = new Uri(jsonData["thumbnails"]["high"]["url"].ToString()), 174 | Height = int.Parse(jsonData["thumbnails"]["high"]["height"].ToString()), 175 | Width = int.Parse(jsonData["thumbnails"]["high"]["width"].ToString()) 176 | }); 177 | } 178 | if (!jsonData["thumbnails"]["standard"].IsNullOrEmpty()) 179 | { 180 | videoImages.Add(new Thumbnails 181 | { 182 | Kind = GeneralEnums.ImageThumbnails.Standard, 183 | ImageUri = new Uri(jsonData["thumbnails"]["standard"]["url"].ToString()), 184 | Height = int.Parse(jsonData["thumbnails"]["standard"]["height"].ToString()), 185 | Width = int.Parse(jsonData["thumbnails"]["standard"]["width"].ToString()) 186 | }); 187 | } 188 | if (!jsonData["thumbnails"]["maxres"].IsNullOrEmpty()) 189 | { 190 | videoImages.Add(new Thumbnails 191 | { 192 | Kind = GeneralEnums.ImageThumbnails.MaxResolution, 193 | ImageUri = new Uri(jsonData["thumbnails"]["maxres"]["url"].ToString()), 194 | Height = int.Parse(jsonData["thumbnails"]["maxres"]["height"].ToString()), 195 | Width = int.Parse(jsonData["thumbnails"]["maxres"]["width"].ToString()) 196 | }); 197 | } 198 | return videoImages; 199 | } 200 | return null; 201 | } 202 | private PlaylistOutput.Videos SetPlaylistContainsDetails(JToken item) 203 | { 204 | PlaylistOutput.Videos videoData = new PlaylistOutput.Videos(); 205 | videoData.Kind = item["resourceId"]["kind"].ToString().Split('#')[1]; 206 | videoData.VideoId = item["resourceId"]["videoId"].ToString(); 207 | videoData.Title = item["title"].ToString(); 208 | videoData.Description = item["description"].ToString(); 209 | videoData.Position = int.Parse(item["position"].ToString()) + 1; 210 | videoData.ChannelId = item["channelId"].ToString(); 211 | videoData.ChannelTitle = item["channelTitle"].ToString(); 212 | videoData.PublishedAt = DateTime.Parse(item["publishedAt"].ToString()); 213 | videoData.ThumbnailsData = SetThumbnails(item); 214 | return videoData; 215 | } 216 | private TrendingOutput.Videos SetTrendingContainsDetails(JToken item) 217 | { 218 | TrendingOutput.Videos videoData = new TrendingOutput.Videos(); 219 | videoData.Kind = item["kind"].ToString().Split('#')[1]; 220 | videoData.VideoId = item["id"].ToString(); 221 | videoData.Title = item["snippet"]["title"].ToString(); 222 | videoData.Description = item["snippet"]["description"].ToString(); 223 | videoData.ChannelId = item["snippet"]["channelId"].ToString(); 224 | videoData.ChannelTitle = item["snippet"]["channelTitle"].ToString(); 225 | videoData.PublishedAt = DateTime.Parse(item["snippet"]["publishedAt"].ToString()); 226 | videoData.CategoryId = (int)item["snippet"]["categoryId"]; 227 | videoData.Category = (TrendingEnums.Categories)videoData.CategoryId; 228 | videoData.ThumbnailsData = SetThumbnails(item["snippet"]); 229 | return videoData; 230 | } 231 | private enum InputType 232 | { 233 | Playlist, Trending 234 | } 235 | } 236 | } 237 | -------------------------------------------------------------------------------- /YoutubeSharpApi/YoutubeSharpApi.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | YoutubeSharpApi 6 | A minimal .NET STANDART wrapper for the Youtube Data API v3. Designed to let devs easily fetch public data (Playlists info,Trending) from Youtube. The reason of returning the decoded JSON response directly is that you only need to read the Google API doc to use this library. 7 | OMANSAK 8 | https://github.com/omansak/YoutubeSharpApi 9 | https://github.com/omansak/YoutubeSharpApi 10 | git 11 | README.md 12 | youtube,youtube .net,youtube cshapar, youtube playlist, youtube video info library winrt wp windows phone pcl portable class library .net framework core compat compatibility api apis layer layers emulator emulators emulation emulations xamarin mono monotouch xamarin.ios ios xamarin.android android 13 | LICENSE 14 | 15 | 16 | 17 | 18 | True 19 | \ 20 | 21 | 22 | True 23 | \ 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | --------------------------------------------------------------------------------