Playlist downloader test
unknown
csharp
3 years ago
1.6 kB
11
Indexable
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RestSharp;
using Newtonsoft.Json;
namespace TESTPLAYTUBE
{
public class YoutubeApi
{
static void Main(string[] args)
{
getPlaylistItems("PLGqipRSVAvkZnDtwO4qDARIwOxHf68VQT");
}
public class apiResult
{
public items[] result { get; set; }
}
public class items
{
public contentDetails contentDetails { get; set; }
}
public class contentDetails
{
public string videoId { get; set; }
}
public static void getPlaylistItems(string playlistId)
{
var json = sendApiRequest($"playlistItems?part=contentDetails&key=AIzaSyA0yLJfONIyMlVFgX7HN_egnVqSP_rq7kE&maxResults=50&playlistId={playlistId}");
var apiResult = JsonConvert.DeserializeObject<apiResult>(json);
Console.WriteLine(apiResult.result);
foreach (var song in apiResult.result)
{
Console.WriteLine(song.contentDetails.videoId);
}
}
public static String sendApiRequest(String API_METHOD)
{
RestClient RC = new RestClient();
var URL = "https://www.googleapis.com/youtube/v3/" + API_METHOD;
var request = new RestRequest(URL);
var response = RC.Get(request);
return response.Content;
}
}
}
Editor is loading...