Created
December 29, 2016 21:07
-
-
Save JKamsker/f182a88d60628d2021dff3ab5b362530 to your computer and use it in GitHub Desktop.
Obtains all video idst+titles from a playlist by the playlist id
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class YTitleIDCollection | |
{ | |
public string videoId { get; set; } | |
public string title { get; set; } | |
} | |
class JSON_PlaylistItems | |
{ | |
public string nextPageToken; | |
public Item[] items; | |
public class Item | |
{ | |
public ContentDetails contentDetails; | |
public Snippet snippet; | |
public class ContentDetails | |
{ | |
public string videoId; | |
} | |
public class Snippet | |
{ | |
public string title; | |
} | |
} | |
} | |
class YTPlaylistLinkFactory | |
{ | |
public static string apiKey = "APIKEY"; | |
public static YTitleIDCollection[] getLinks(string playlistID) | |
{ | |
List<YTitleIDCollection> retval = new List<YTitleIDCollection>(); | |
WebClient wc = new WebClient(); | |
wc.Proxy = null; | |
string nextToken = null; | |
var ytlist = new List<JSON_PlaylistItems.Item>(); | |
do | |
{ | |
var queryString = new Uri("https://www.googleapis.com/youtube/v3/playlistItems" | |
+ "?part=contentDetails,snippet" | |
+ "&maxResults=50" | |
+ "&playlistId=" + playlistID | |
+ "&fields=" + Uri.EscapeDataString("items(contentDetails/videoId,snippet/title),nextPageToken") | |
+ (nextToken != null ? ("&pageToken=" + nextToken) : string.Empty) | |
+ "&key=" + apiKey); | |
string todes = wc.DownloadString(queryString); | |
var lel = JsonConvert.DeserializeObject<JSON_PlaylistItems>(todes); | |
nextToken = lel.nextPageToken; | |
ytlist.AddRange(lel.items); | |
} while (nextToken != null); | |
foreach (var it in ytlist) | |
{ | |
retval.Add(new YTitleIDCollection() { title = it.snippet.title, videoId = it.contentDetails.videoId }); | |
} | |
return retval.ToArray(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment