Get all Youtube videos in a Youtube Playlist including the duration of it












0















So I need to get the duration of each Video in a Playlist, the problem is that there is no duration included, theoretically I could calculate it with the EndAt and StartAt values but they are no longer filled with data and always will be null (see documentation).



So all of this is done so far with the Google.Apis.YouTube.v3. The code I currently have:



        var PlaylistItemRequest = YouTubeService.PlaylistItems.List("snippet,contentDetails");
PlaylistItemRequest.PlaylistId = Find;
PlaylistItemRequest.MaxResults = 50;

List<Song> PlaylistItems = new List<Song>();

while (true)
{
var PlaylistItemResponse = await PlaylistItemRequest.ExecuteAsync();

foreach (var playlistitem in PlaylistItemResponse.Items)
PlaylistItems.Add(new Song(playlistitem.Snippet.Title, playlistitem.ContentDetails.EndAt, playlistitem.ContentDetails.StartAt, $"https://www.youtube.com/watch?v={playlistitem.Id}", playlistitem.Snippet.Thumbnails.Default__.Url, DateTime.UtcNow, null, user.Id));

if (PlaylistItemResponse.NextPageToken == null) break;

PlaylistItemRequest.PageToken = PlaylistItemResponse.NextPageToken;
}


Then I thought I could just do something like that, because this would give me the duration of the video:



var request = YouTubeService.Videos.List("snippet,contentDetails,statistics");



The problem is that I would need to send this for each song in the playlist and I do not want to risk to break the Google API ratelimits. Since 200 requests are a lot.



Any help is appreciated!



Note: I would need a solution with no manual delay if possible.










share|improve this question























  • You can do a Videos.List request up to 50 IDs at a time.

    – johnh10
    Nov 27 '18 at 23:43











  • Thanks a lot!@johnh10

    – Twenty
    Nov 28 '18 at 12:29
















0















So I need to get the duration of each Video in a Playlist, the problem is that there is no duration included, theoretically I could calculate it with the EndAt and StartAt values but they are no longer filled with data and always will be null (see documentation).



So all of this is done so far with the Google.Apis.YouTube.v3. The code I currently have:



        var PlaylistItemRequest = YouTubeService.PlaylistItems.List("snippet,contentDetails");
PlaylistItemRequest.PlaylistId = Find;
PlaylistItemRequest.MaxResults = 50;

List<Song> PlaylistItems = new List<Song>();

while (true)
{
var PlaylistItemResponse = await PlaylistItemRequest.ExecuteAsync();

foreach (var playlistitem in PlaylistItemResponse.Items)
PlaylistItems.Add(new Song(playlistitem.Snippet.Title, playlistitem.ContentDetails.EndAt, playlistitem.ContentDetails.StartAt, $"https://www.youtube.com/watch?v={playlistitem.Id}", playlistitem.Snippet.Thumbnails.Default__.Url, DateTime.UtcNow, null, user.Id));

if (PlaylistItemResponse.NextPageToken == null) break;

PlaylistItemRequest.PageToken = PlaylistItemResponse.NextPageToken;
}


Then I thought I could just do something like that, because this would give me the duration of the video:



var request = YouTubeService.Videos.List("snippet,contentDetails,statistics");



The problem is that I would need to send this for each song in the playlist and I do not want to risk to break the Google API ratelimits. Since 200 requests are a lot.



Any help is appreciated!



Note: I would need a solution with no manual delay if possible.










share|improve this question























  • You can do a Videos.List request up to 50 IDs at a time.

    – johnh10
    Nov 27 '18 at 23:43











  • Thanks a lot!@johnh10

    – Twenty
    Nov 28 '18 at 12:29














0












0








0








So I need to get the duration of each Video in a Playlist, the problem is that there is no duration included, theoretically I could calculate it with the EndAt and StartAt values but they are no longer filled with data and always will be null (see documentation).



So all of this is done so far with the Google.Apis.YouTube.v3. The code I currently have:



        var PlaylistItemRequest = YouTubeService.PlaylistItems.List("snippet,contentDetails");
PlaylistItemRequest.PlaylistId = Find;
PlaylistItemRequest.MaxResults = 50;

List<Song> PlaylistItems = new List<Song>();

while (true)
{
var PlaylistItemResponse = await PlaylistItemRequest.ExecuteAsync();

foreach (var playlistitem in PlaylistItemResponse.Items)
PlaylistItems.Add(new Song(playlistitem.Snippet.Title, playlistitem.ContentDetails.EndAt, playlistitem.ContentDetails.StartAt, $"https://www.youtube.com/watch?v={playlistitem.Id}", playlistitem.Snippet.Thumbnails.Default__.Url, DateTime.UtcNow, null, user.Id));

if (PlaylistItemResponse.NextPageToken == null) break;

PlaylistItemRequest.PageToken = PlaylistItemResponse.NextPageToken;
}


Then I thought I could just do something like that, because this would give me the duration of the video:



var request = YouTubeService.Videos.List("snippet,contentDetails,statistics");



The problem is that I would need to send this for each song in the playlist and I do not want to risk to break the Google API ratelimits. Since 200 requests are a lot.



Any help is appreciated!



Note: I would need a solution with no manual delay if possible.










share|improve this question














So I need to get the duration of each Video in a Playlist, the problem is that there is no duration included, theoretically I could calculate it with the EndAt and StartAt values but they are no longer filled with data and always will be null (see documentation).



So all of this is done so far with the Google.Apis.YouTube.v3. The code I currently have:



        var PlaylistItemRequest = YouTubeService.PlaylistItems.List("snippet,contentDetails");
PlaylistItemRequest.PlaylistId = Find;
PlaylistItemRequest.MaxResults = 50;

List<Song> PlaylistItems = new List<Song>();

while (true)
{
var PlaylistItemResponse = await PlaylistItemRequest.ExecuteAsync();

foreach (var playlistitem in PlaylistItemResponse.Items)
PlaylistItems.Add(new Song(playlistitem.Snippet.Title, playlistitem.ContentDetails.EndAt, playlistitem.ContentDetails.StartAt, $"https://www.youtube.com/watch?v={playlistitem.Id}", playlistitem.Snippet.Thumbnails.Default__.Url, DateTime.UtcNow, null, user.Id));

if (PlaylistItemResponse.NextPageToken == null) break;

PlaylistItemRequest.PageToken = PlaylistItemResponse.NextPageToken;
}


Then I thought I could just do something like that, because this would give me the duration of the video:



var request = YouTubeService.Videos.List("snippet,contentDetails,statistics");



The problem is that I would need to send this for each song in the playlist and I do not want to risk to break the Google API ratelimits. Since 200 requests are a lot.



Any help is appreciated!



Note: I would need a solution with no manual delay if possible.







c# asynchronous youtube-api youtube-api-v3






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 24 '18 at 12:31









TwentyTwenty

39615




39615













  • You can do a Videos.List request up to 50 IDs at a time.

    – johnh10
    Nov 27 '18 at 23:43











  • Thanks a lot!@johnh10

    – Twenty
    Nov 28 '18 at 12:29



















  • You can do a Videos.List request up to 50 IDs at a time.

    – johnh10
    Nov 27 '18 at 23:43











  • Thanks a lot!@johnh10

    – Twenty
    Nov 28 '18 at 12:29

















You can do a Videos.List request up to 50 IDs at a time.

– johnh10
Nov 27 '18 at 23:43





You can do a Videos.List request up to 50 IDs at a time.

– johnh10
Nov 27 '18 at 23:43













Thanks a lot!@johnh10

– Twenty
Nov 28 '18 at 12:29





Thanks a lot!@johnh10

– Twenty
Nov 28 '18 at 12:29












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53458164%2fget-all-youtube-videos-in-a-youtube-playlist-including-the-duration-of-it%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53458164%2fget-all-youtube-videos-in-a-youtube-playlist-including-the-duration-of-it%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Ottavio Pratesi

Tricia Helfer

15 giugno