Video from channel not showing up with YouTube Data API - c#

According to this I'm supposed to ask this question here
I'm trying to get the most recent uploads for a channel (ExplosmEntertainment). I'm calling a PlaylistItemsResource.ListRequest (which has always worked) like this:
PlaylistItemsResource.ListRequest listRequest = service.PlaylistItems.List("snippet");
listRequest.PlaylistId = "UUWXCrItCF6ZgXrdozUS-Idw";
listRequest.MaxResults = 1;
PlaylistItemListResponse response = listRequest.Execute();
PlaylistItemSnippet newUploadDetails = response.Items.FirstOrDefault().Snippet;
The problem is that newUploadDetails lists this video: https://www.youtube.com/watch?v=PSHg-U4s-6c as the most recent upload whereas if you visit the actual uploads playlist, it is this video: https://www.youtube.com/watch?v=FHK4N8QLtBQ .
As this code has always worked for me thus far, this seems to be a problem with this video and the API, but is there something I'm doing wrong?
Edit:
This channel uploaded a new video last night (8/24/17) and I modified my code to this:
PlaylistItemsResource.ListRequest listRequest = service.PlaylistItems.List("snippet");
listRequest.PlaylistId = "UUWXCrItCF6ZgXrdozUS-Idw";
listRequest.MaxResults = 5;
PlaylistItemListResponse response = listRequest.Execute();
List<PlaylistItem> fiveRecent = response.Items.ToList();
#paolo suggested that maybe the results were getting cached and that's what I was seeing but in my fiveRecent list, the list is as follows:
https://www.youtube.com/watch?v=SxYyTOgWBDI (published 8/24/2017 21:30:00)
https://www.youtube.com/watch?v=PSHg-U4s-6c (published 8/21/2017 22:00:00)
https://www.youtube.com/watch?v=e-cbR0JwgsA (published 8/13/2017 22:00:00)
https://www.youtube.com/watch?v=FHK4N8QLtBQ (published 8/23/2017 22:00:00)
https://www.youtube.com/watch?v=fczItbbB-OA (published 8/16/2017 22:00:01)
So these results show that the response.Items are not ordered by published date. And, unfortunately, there doesn't seem to be an OrderBy parameter like there is with some of the other APIs and their list methods.
This is the same order that the API Explorer gives
It is very odd to me that this order doesn't match the order in the actual playlist on YouTube. Does anyone have any suggestions for a different way to get the most recently uploaded video?

It is very odd to me that this order doesn't match the order in the actual playlist on YouTube
Same here. One would definitively expect that.
Ok, when I do this:
GET https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&fields=items/snippet/publishedAt%2Citems/snippet/position%2Citems/snippet/title&maxResults=5&playlistId=UUWXCrItCF6ZgXrdozUS-Idw&key=API_KEY HTTP/1.2
I get this:
{
"items": [
{
"snippet": {
"publishedAt": "2017-08-25T04:30:00.000Z",
"title": "Ow, My Dick: The Aftermath - A Cyanide & Happiness True Story",
"position": 0
},
"contentDetails": {
"videoId": "SxYyTOgWBDI"
}
},
{
"snippet": {
"publishedAt": "2017-08-22T05:00:00.000Z",
"title": "X-Ray - Cyanide & Happiness Minis",
"position": 1
},
"contentDetails": {
"videoId": "PSHg-U4s-6c"
}
},
{
"snippet": {
"publishedAt": "2017-08-14T05:00:00.000Z",
"title": "Explosm Presents: Channelate - Drinkin' Alone",
"position": 2
},
"contentDetails": {
"videoId": "e-cbR0JwgsA"
}
},
{
"snippet": {
"publishedAt": "2017-08-24T05:00:00.000Z",
"title": "High Noon - Cyanide & Happiness Shorts",
"position": 3
},
"contentDetails": {
"videoId": "FHK4N8QLtBQ"
}
},
{
"snippet": {
"publishedAt": "2017-08-17T05:00:01.000Z",
"title": "Final Words - Cyanide & Happiness Shorts",
"position": 4
},
"contentDetails": {
"videoId": "fczItbbB-OA"
}
}
]
}
The order and times are the same as you provided, just GMT instead of PDT. But this also shows that the items are ordered by position - which in theory should of course be analogue to publishedAt.
Since it's not, I suggest fetching the first few, say 10 or 15, items of the playlist and ordering these by date. Then pray that the actual latest video is among those first X positions. I really can't think of anything else here.

Related

How do i remove unnecessary items ({object}, {Array}) in treeview C#

The bounty expires in 3 days. Answers to this question are eligible for a +50 reputation bounty.
DeLorean is looking for an answer from a reputable source.
I am trying to make changes to an C# based opensource json editor which has MIT license. I want to remove the items like ({object}, {Array}) from the Json tree view. here is the link to the Open source Json Editor and here is the link to a editor which i used as a reference for Expected output.
Test.json
{
"TEST JSON" : "JSON",
"JSON":{
"ANIMALS":[
{
"ID":0,
"TYPE":"DOG",
"DOG":{
"TYPE":"RETRIEVER",
"RETRIEVER":{
"NAME":"LEO",
"AGE":3,
"YEARS":[2019 , 2020, 2021],
"WEIGHTS": [2,10,13]
}
},
"REMARKS":{
"ID":1,
"STATUS":"GOOD",
"REFERENCE": {
"SOURCE": "XYZ",
"FIT": 1,
"BMI" : 1
}
}
},
{
"ID":1,
"TYPE":"DOG2",
"DOG2":{
"TYPE":"PUG",
"RETRIEVER":{
"NAME":"HUTCH",
"AGE":4,
"YEARS":[2019 , 2020, 2021, 2022],
"WEIGHTS": [2,3,4,4]
}
},
"REMARKS":{
"ID":1,
"TYPE" : "REFERENCE",
"STATUS":"OK",
"REFERENCE": {
"SOURCE": "XYZ",
"FIT": 1,
"BMI" : 1
}
}
},
{
"ID": 2,
"TYPE": "DIAGNOSTICS",
"STATUS": "ENABLED"
},
{
"ID": 3,
"TYPE": "ORGANISATION",
"ORGANISATION":{
"NAME":"RED CROSS",
"YEAR": 2023
}
}
]
}
}
Current Output
Like shown in the images below i want to remove elements marked with red to make it look like the image on the right
Expected Output
There are 2 projects inside in the solution JsonEditor and JsonTreeview. There is a function called AfterExpand() in all these files
I'm sure that function is responsible for displaying those unwanted items. so i made the Text string empty in all the files this function is present so the items will be gone.
/// <inheritdoc />
public override void AfterExpand()
{
base.AfterExpand();
Text = $#"[{JArrayTag.Type}]";
// change i made
Text = "";
}
but it seems there are empty spaces being displayed now. Any help would be really appreciated. Thanks in advance.

Azure Search why OCRed text is not merged in correct order in merged_content field?

I need to develop my own webapi custom skill that make us of Read API. I will use it in my custom skillset. I can't use built-in OCR skill from Azure Cognitive Search (t
Output of my webapi skill looks like this:
// logic to get result...
// now creating output to custom skill
var textUrlFileResults = results.AnalyzeResult.ReadResults;
foreach (ReadResult page in textUrlFileResults)
{
var newValue = new
{
RecordId = value.RecordId,
Data = new
{
text = string.Join(" ", page.Lines?.Select(x => x.Text))
}
};
output.Values.Add(newValue);
}
}
return new OkObjectResult(output);
And here is my skillset definition:
"skills": [
{
"#odata.type": "#Microsoft.Skills.Text.MergeSkill",
"name": "#1",
"context": "/document",
"insertPreTag": " ",
"insertPostTag": " ",
"inputs": [
{
"name": "text",
"source": "/document/content"
},
{
"name": "itemsToInsert",
"source": "/document/normalized_images/*/text"
},
{
"name": "offsets",
"source": "/document/normalized_images/*/contentOffset"
}
],
"outputs": [
{
"name": "mergedText",
"targetName": "merged_content"
}
]
},
{
"#odata.type": "#Microsoft.Skills.Custom.WebApiSkill",
"name": "#2",
"description": null,
"context": "/document/normalized_images/*",
// i cut some info
"inputs": [
{
"name": "image",
"source": "/document/normalized_images/*"
}
],
"outputs": [
{
"name": "text",
"targetName": "text"
}
]
}
],
I am trying to OCR pdf document that look like this:
And in Index i get this document that looks like this:
{
"#odata.context": " cutted ",
"value": [
{
"#search.score": 1,
"content": "\nText before shell\n\nText after shell\n\nText after bw\n\n\n\n\n\n\n\nAnd here second page\n\n\n",
"merged_content": "\nText before shell\n\nText after shell\n\nText after bw\n\n SHELL 1900 1904 1909 1930 1948 SHELL SHELL Shell Shell 1955 1961 1971 1995 1999 \n\n B+W BLACK+WHITE PHOTOGRAPHY \n\n\n\nAnd here second page\n\n\n",
"text": [
"SHELL 1900 1904 1909 1930 1948 SHELL SHELL Shell Shell 1955 1961 1971 1995 1999",
"B+W BLACK+WHITE PHOTOGRAPHY"
],
"layoutText": [],
"textFromOcr": "[\"SHELL 1900 1904 1909 1930 1948 SHELL SHELL Shell Shell 1955 1961 1971 1995 1999\",\"B+W BLACK+WHITE PHOTOGRAPHY\"]"
}
]
}
My question is, why OCRed text is not placed in correct order with standard text when i am using /document/normalized_images/*/contentOffset" in MergeSkill? To be honest my skillset is copy-pasted from ms docs and it is not working as expected. I dont really understand, what special comes from OCR skill. I need to develop my own OCR skill, i can't use OCR from Search out of the box, i need to write it on my own.
Unfortunately, that is the behavior of the skill by design. It gets the text first and leave the image translation at the bottom. This is not something that can be changed at this time with code within the skill due to an implementation limitation. Changes to OCR skill documentation have been made to reflect this, and it will be published hopefully this week, to clarify and avoid confusion.

Unusual JSON format (equal signs for key value pairs) and parsing it

After updating the pusher.com libraries for one of my VS WinForms projects, I've noticed that the JSON I'm receiving from pusher.com is not in the correct format anymore (nothing was changed on the server end of things, just the library update in the desktop app / VS project).
Instead of getting this (after the desktop application I'm making receives it, and displays it via MessageBox.Show(...)):
{
"event": "myevent",
"data": {
"message": {
"header": {
"type": "type1",
"printer": "myprinter"
},
"items": {
"1": "Item 1#03#Kg#1#1782.00#1782.00#6002#03"
},
"info": {
"type": "stuff",
"other": "yes"
}
}
},
"channel": "mychannel"
}
I am now getting this
{
event = cashregister,
data = {
"message": {
"header": {
"type":"type1",
"printer":"myprinter"
},
"items": {
"1":"Item 1#03#Kg#1#1782.00#1782.00#6002#03"
},
"info": {
"type":"stuff",
"other":"yes"
}
}
},
channel = mychannel,
user_id =
}
I've never seen this kind of JSON formatting before, and have not been able to find anything by searching on Google or visiting json.org and going through examples.
The usual JsonConvert.DeserializeObject(myJson.event.ToString()); is not working, and it's throwing an exception - Invalid character after parsing property name. Expected ':' but got: =.
How do I parse this? More importantly, is this even a proper JSON format?

MS Chat Bot --How to access custom adaptive card properties from my C# code

How to dynamically change my custom adaptive card's text property value from within my C# code?
Here is my C# code
public static Attachment CreateMySearchCardAttachment()
{
// combine path for cross platform support
string[] paths = { ".", "Resources", "MySearchCard.json" };
var MySearchCardJson = File.ReadAllText(Path.Combine(paths));
var adaptiveCardAttachment = new Attachment()
{
ContentType = "application/vnd.microsoft.card.adaptive",
Content = JsonConvert.DeserializeObject(MySearchCardJson),
};
return adaptiveCardAttachment;
}
And my MySearchCard.json file goes below
{
"type": "AdaptiveCard",
"body": [
{
"type": "ColumnSet",
"columns": [
{
"type": "Column",
"items": [
{
"type": "Image",
"horizontalAlignment": "Right",
"spacing": "None",
"url": "",
"size": "Medium",
"width": "2px",
"height": "2px"
},
{
"type": "TextBlock",
"size": "Medium",
"weight": "Bolder",
"text": "Knowledgebase Search"
},
{
"type": "Input.Text",
"id": "searchText",
"placeholder": "Type your search text and click Search"
}
],
"width": 2
}
]
}
],
"actions": [
{
"type": "Action.Submit",
"title": "Search"
}
],
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.0"
}
I am able to get this adaptive card to display inside my chat bot.But not sure how to dynamically change the text labels or their values. We want to dynamically change some of the text labels before displaying, then after displaying,dynamically show or hide based on user response.At a later point we want to integrate chat BoT with MS Teams.But prior to that I need to show the same from my emulator
If you look at my json, there is a text property with "text": "Knowledgebase Search". My question is how to change this text value dynamically from within my C# code?
Dynamically Changing Before Being Displayed
There's a few different ways to do this. The first option is probably the best, but they should all work.
1. Use the AdaptiveCards Package
Note: This package is different from, and newer than, Microsoft.AdaptiveCards -- Don't use this one
Since you know the exact part of the card that you'd like to change, you can:
string[] paths = { ".", "AdaptiveCard.json" };
var cardJson = File.ReadAllText(Path.Combine(paths));
var card = AdaptiveCard.FromJson(cardJson).Card;
var columnSet = (card.Body[0] as AdaptiveColumnSet);
var column = (columnSet.Columns[0] as AdaptiveColumn);
var knowledgeBlock = (column.Items[1] as AdaptiveTextBlock);
knowledgeBlock.Text = "Whatever You Want";
var attachment = new Attachment()
{
Content = card,
ContentType = "application/vnd.microsoft.card.adaptive"
};
var reply = stepContext.Context.Activity.CreateReply();
reply.Attachments = new List<Attachment>();
reply.Attachments.Add(attachment);
await stepContext.Context.SendActivityAsync(reply);
Result:
2. Use Data Binding (in Preview)
This is in preview and you still need to use the NuGet package from #1, but makes it easier to modify particular fields.
3. Edit the JSON with Newtonsoft.JSON
This is probably a little simpler, but less flexible. Something like this works and produces the same result as #1:
string[] paths = { ".", "AdaptiveCard.json" };
var cardJsonObject = JObject.Parse(File.ReadAllText(Path.Combine(paths)));
var knowledgeToken = cardJsonObject.SelectToken("body[0].columns[0].items[1]");
knowledgeToken["text"] = "Whatever You Want";
var attachment = new Attachment()
{
Content = cardJsonObject,
ContentType = "application/vnd.microsoft.card.adaptive"
};
var reply = stepContext.Context.Activity.CreateReply();
reply.Attachments = new List<Attachment>();
reply.Attachments.Add(attachment);
await stepContext.Context.SendActivityAsync(reply);
return await stepContext.NextAsync();
Dynamically Changing After Being Displayed
Changing the card after being displayed is a little more difficult. You first have to change the card in the code, as done above. You then have to use UpdateActivityAsync(). Basically, you send an activity with the same id, but a new card and it overwrites the previous card completely.
Note: You can only use this in channels that support updating activities. It's usually pretty easy to tell, because even without bots, the channel either will or won't let you edit messages. It sounds like you want to use Teams, so this will work fine.
You can use my answer here for how to update card activities with Teams. Note that this one is in Node, but you can still do it in C# the same way.
You can also use this other StackOverflow Answer from one of the guys on the MS Teams team.

Get comment or likes count for YouTube video using API 3.0

I want to get number of comments and/or likes for video with specific YouTube ID.
I am using YouTube API v3.0.
I was searching through API documentation and can't find appropriate method.
After having better look at Google API documentation here, I have found that I can use "statistics" part parameter of Videos.List API in order to get what I want.
Exact HTTP post request should be (notice part=statistics parameter):
GET https://www.googleapis.com/youtube/v3/videos?part=statistics&id=sTPtBvcYkO8&key={YOUR_API_KEY}
And response is:
{
"kind": "youtube#videoListResponse",
"etag": "\"kjEFmP90GvrCl8BObMQtGoRfgaQ/XN5YXMZGQaruwTWTekZu7fQthdY\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#video",
"etag": "\"kjEFmP90GvrCl8BObMQtGoRfgaQ/QbzZs_aBNpzkZJxTVM7YgQeEY3g\"",
"id": "sTPtBvcYkO8",
"statistics": {
"viewCount": "3215321",
"likeCount": "17003",
"dislikeCount": "263",
"favoriteCount": "0",
"commentCount": "621"
}
}
]
}
If you want number of comments and/or likes for video with specific YouTube ID, you need to use the YouTube API V3 with youtube.videos.list
with the parameters :
part=id, statistics
id=VIDEO_ID
This is the output :
"items": [
{
"kind": "youtube#video",
"etag": "\"kjEFmP90GvrCl8BObMQtGoRfgaQ/-hharrXKffaZ3z4sIleW9K-Nf2Q\"",
"id": "_RtGuUAQOC4",
"statistics": {
"viewCount": "484851",
"likeCount": "3993",
"dislikeCount": "72",
"favoriteCount": "0",
"commentCount": "262"
}
}
]
LIVE DEMO
You can find all informations about video list in the doc :https://developers.google.com/youtube/v3/docs/videos/list?hl=fr :

Categories