Youtube Search for Videos in given Channel only - search

How can (a user) SEARCH FOR OUR VIDEOS BY KEYWORDS (Public Videos -- OUR Channel Only..)..
We were basing our approach in https://developers.google.com/youtube/v3/code_samples/javascript#search_by_keyword
We want to use API KEY for Authorization.. and Access is via browser.. (JS)
So when the user enters KEYWORDS in a Search box the CONTEXT (where to search) should already be the given Channel XXXX (its Public Videos)..
What would be the API/methods to use and with what params..??

The search endpoint is the correct one to use, passing the keywords as the 'q' parameter and the channel as the 'channelId' parameter. So, using the sample function you linked to, you might try something like this:
function search() {
var q = $('#query').val();
var request = gapi.client.youtube.search.list({
q: q,
part: 'snippet',
channelId: {whatever your ID is}
});

Related

How do I query the vimeo api for a specific video title?

Hi I'm querying for a specific video by title - and at the moment I get mixed results.
my videos are all named with a consecutive number at the end ie ANDNOW2022_00112, ANDNOW2022_00113 etc
When I search /videos/?fields=uri,name&query=ANDNOW2022_00112 I get all of the videos returned
I've also tried the query_fields using
/me/videos?query_fields=title&sort=alphabetical&query=ANDNOW2022_00112
I just want the one I've searched for - or a no results returned.
At the moment I get all of the videos with AN2022 in the title/name. Now 'usually' the one I searched for is at the top of the list but not everytime.
Any tips appreciated.
Okay I'm not going mad :)
This is from Vimeo and is here for those with the same issue - basically to get t to work you need to understand that:
After speaking with our engineers, the current search capability are not "Exact" search.
When adding numbers or underscores the search is split into parts so "ANDNOW2022_00112" is transforming the query into the parts "andnow2022", "andnow", "2022", and "00112". So this is why your seeing these results. Our engineering team are in the process of improving the search capabilities and hope to provide a release in the near future.
Which means for now I'll have to rename my files.
Preface:
Vimeo does not currently offer an API endpoint for exact title search — but even if it did — it's possible to upload multiple videos and assign them identical titles. There's no way to use the API to positively identify a video by title — this is why every uploaded video is assigned a unique ID.
Solution:
Because the API returns data which includes an array of video objects, you can solve this problem in the same way you'd solve any similar problem in JavaScript where you have to find an element in an array: Array.prototype.find()
Here's how you can apply it to your problem:
Query the API using the parameters you described in your question.
You might also be interested in using the sort and direction parameters for greater control over a deterministic sort order.
Find the first item in the returned array of video objects that match your expected text exactly, and return it (or undefined if it doesn't exist)
Here's a code example with some static data from the API that was used to search for the video Mercedes Benz from the user egarage — note that I've omitted quite a few (irrelevant) fields from the response in order to keep the example small:
// Mocking fetch for this example:
function fetch (_requestInfo, _init) {
const staticJson = `{"total":2,"page":1,"per_page":25,"paging":{"next":null,"previous":null,"first":"/users/egarage/videos?query_fields=title&query=Mercedes%20Benz&sort=alphabetical&direction=asc&page=1","last":"/users/egarage/videos?query_fields=title&query=Mercedes%20Benz&sort=alphabetical&direction=asc&page=1"},"data":[{"uri":"/videos/61310450","name":"50th Anniversary of the Pagoda SL -- Mercedes-Benz Classic Vehicles","description":"Penned by designer Paul Bracq, the W113 SL had big shoes to fill: it had the incredible task of succeeding the original and instantly iconic 300 SL Gullwing. But you can't copy a legend, so Bracq designed one of his own. Straight lines replaced curves and a low-slung roof was replaced by a high top design that gave the car its nickname: the Pagoda.\\n\\nMUSIC: Developer Over Time","type":"video","link":"https://vimeo.com/61310450"},{"uri":"/videos/55837293","name":"Mercedes Benz","description":"To celebrate Mercedes Benz 125th birthday, the 2011 Pebble Beach Concours d’Elegance showcased the models that trace the lineage to Benz and Daimler —particularly Mercedes-Benz. This tribute chronicled early racing greats, coachbuilt classics, and preservation cars. Produced in association with DriveCulture.","type":"video","link":"https://vimeo.com/55837293"}]}`;
return Promise.resolve(new Response(staticJson));
}
async function fetchVideoByTitle (token, userId, videoTitle) {
const url = new URL(`https://api.vimeo.com/users/${userId}/videos`);
url.searchParams.set("query_fields", "title");
url.searchParams.set("query", videoTitle);
url.searchParams.set("sort", "alphabetical");
url.searchParams.set("direction", "asc");
const headers = new Headers([
["Authorization", `Bearer ${token}`],
]);
const response = await fetch(url.href, {headers});
const parsedJson = await response.json();
// Find the video that matches (if it exists):
const maybeFirstVideoObj = parsedJson.data.find(video => video.name === videoTitle);
return maybeFirstVideoObj;
}
async function main () {
const video = await fetchVideoByTitle(
"YOU_ACTUAL_TOKEN",
"egarage",
"Mercedes Benz",
);
console.log(video); // {name: "Mercedes Benz", link: "https://vimeo.com/55837293", ...}
}
main();

How to pass one more parameter other than option from the intent showing the carousel to the intent handling the carousel?

I am using an intent to first present the carousel to the user.
When the user clicks on one of the options in the carousel, in the handler intent I get the key of the carousel item that the user selected.
Example of carousel intent,
app.intent('search', async (conv,params) => {
conv.ask(`Choose one item`,new Carousel({
title :`Search results`,
items : carouselItems,
}));
});
Example of the handler intent,
app.intent('handle_carousel', async (conv,params,option) => {
const key = parseInt(option);
});
However, along with the key of the option selected I also want to pass another integer from the carousel intent to the handler intent.
This other integer is different for each option. You can think of the other integer as an ID, it's unique for each option.
How can I achieve that?
You have a few approaches for passing additional data that should be associated with each key.
The first is, as you note in your answer, storing that mapping in a table that is stored as part of session data (either using conv.data or a Dialogflow context).
Another is to encode that data as part of the key that you include with each option, and then decode the key when you get it back.
So, for example, you could make the key a result of an encode function like
function encodeOptionKey( key, otherValue ){
return `${key}:${otherValue}`
}
and then decode it with a function such as
function decodeOptionKey( option ){
const [key,otherValue] = option.split(':');
return {
key,
otherValue
}
}
and call this from your handler with something like
app.intent('handle_carousel', async (conv,params,option) => {
const {key, otherValue} = decodeOptionKey( option );
// ...
});
I created a map of the keys of various carousel options and the corresponding parameter I wanted to pass, saved that map in conv.data.store, which is the conversation storage provided by actions-on-google. Then I used that map to get the parameter from the carousel key that was being passed to the handler intent.
For example in the carousel intent :
let map = {
keyofcarousel : option,
other_parameter : otherparam,
};
conv.data.store = map;
Then call conv.data.store in the handler intent.

Alexa voice with Jovo Framework: Is this possible to get IntentName by utterance? How can I decide which intent to jump to based on user utterance?

I have built an Alexa skill with the following flow:
LAUNCH -> AccountLinkingIntent -> CampaignIntent
In AccountLinkingIntent, presently I am routing to CampaignIntent if Account is already linked.
Up to this everything is working fine. Now I have to add another Intent ActiveContactIntent so that the flow becomes:
LAUNCH -> AccountLinkingIntent -> CampaignIntent / ActiveContactIntent
i.e, From AccountLinking I need to decide which Intent to route to.
The invocation goes like this (CampaignIntent):
Alexa, ask <invocation_name> to get my latest campaign result
OR (ActiveContactIntent)
Alexa, ask <invocation_name> who is my most active contact
Based on the utterance, I need to tell Alexa where to go. So far I have the following in AccountLinkingIntent
...
return this.toIntent("CampaignIntent");
...
But now I need to decide the same as this:
...
if( ... ) {
return this.toIntent("CampaignIntent");
} else {
return this.toIntent("ActiveContactIntent");
}
...
Is there any way to get the IntentName by the utterance so that I can check by the same such as:
...
if( intent_name_by_utterance === "CampaignIntent" ) {
return this.toIntent("CampaignIntent");
} else {
return this.toIntent("ActiveContactIntent");
}
...
Or probably, if it is possible to get intent_name_by_utterance I may also pass the value as the argument of toIntent method if it is allowed to pass a variable!
return this.toIntent(intent_name_by_utterance);
UPDATE:
I have tried the following to see whether the intent name is being returned:
LAUNCH() {
return this.toIntent("LinkAccountIntent");
},
async LinkAccountIntent() {
const intent_name = this.$request.getIntentName();
this.tell(Current intent is: ${intent_name});
},
Invoked the skill in following two fashions:
Alexa, ask <invocation-name> to give me my latest campaign results
Alexa, ask <invocation-name> who is my most active contact
give me my latest campaign results AND who is my most active contact are the utterances for respective intents.
I am using Alexa Test console for testing. In both cases, I was expecting the name of the intent (this.$request.getIntentName()), ending up with
Hmm, I don't know that one.
My intention is to call an intent by its utterance directly by waking up the skill using its invocation name.
Any suggestion?
I think you should treat both intends separately and not through the launch, because for example in the case
"Alexa, ask who is my most active contact"
Alexa skips the launch and jumps directly to resolve the intend ActiveContactIntent.
So just as you have the LAUNCH(){} function you must also have CampaignIntent(){} and ActiveContactIntent(){}.
That way you will avoid Alexa answering
Hmm, I don't know that one.
To verify that the user has already linked his account, you would have to enter a code like the one below:
if (!this.$request.getAccessToken()) {
this.$alexaSkill.showAccountLinkingCard();
this.tell('Please link you Account');
} else {
//code for your respective action
}
I recommend you to check the documentation about "routing with jovo" to have a little more clarity about this topic. You can review it at the following link:
https://www.jovo.tech/docs/routing

How to insert a link to user profile or chat in message using telethon?

Composing new message in telethon I'm trying to make something like 'User (link) in chat (link) posted something', but failed.
According to https://github.com/LonamiWebs/Telethon/wiki/Special-links, I've tried links like tg://user?id=123 and tg://openmessage?chat_id=123, but that gives links in text that are not working.
Here's the example:
#client.on(events.NewMessage)
async def handler(event):
sender = await event.get_sender()
sender_id = event.sender_id
sender_link = 'tg://user?id=' + str(sender_id)
payload = '[%s] (%s) said something' % (sender.first_name, sender_link)
I'm expecting a message with hyperlinked username, but getting [Alex] (tg://user?id=123), and that link leads to nowhere.
You need to remove the space between [...] and (...). You should have [%s](%s).
Twit is right, but there are several alternatives. You can manually insert a MessageEntityMention to the parser, or you can use HTML parse_mode and the format. Note that both of these are better, consider for example a user named hello](tg://user?id=321)[. This user would not get a link, so you should avoid markdown as it's not possible to escape this.

Searching in JavaMail - how to make it happen server side?

I think I'm missing something about how to search in JavaMail.
Download empty messages from a folder
Create a new SearchTerm that matches your results
Filter (yourFolder.search) the results using your search term.
This works. But - why do it this way? If I'm using javamail to connect to something like gmail, the search isn't being executed server-side, and it doesn't seem like there is any advantage to using the whole javax.mail.search.SearchTerm constructs in terms of efficiency or reducing the amount of data that needs to be sent over the network...
I don't see any way that executes a search on the server side and returns a list of matches. Any ideas?
EDIT: Including pseudocode of what I'm doing now, which doesn't execute any search on the server-side. Even if I converted this to use SearchTerm it still wouldn't be doing anything server-side, right?
Properties props = System.getProperties();
props.setProperty("mail.store.protocol", "gimaps");
final Session session = Session.getDefaultInstance(props, null);
final GmailSSLStore store = (GmailSSLStore) session.getStore("gimaps");
store.connect(ADDRESS, PASSWORD);
final GmailFolder allMailFolder = (GmailFolder) store.getFolder("[Gmail]/All Mail");
allMailFolder.open(Folder.READ_ONLY);
final Message[] allMessages = allMailFolder.getMessages();
System.out.println("Messages:" + allMessages.length);
FetchProfile fp = new FetchProfile();
fp.add(FetchProfile.Item.ENVELOPE);
allMailFolder.fetch(allMessages, fp);
for (final Message message : allMessages) {
final Address[] addrs = message.getFrom();
if (addrs != null) {
for (final Address addr : addrs) {
if (addr.toString().toLowerCase().contains("george")) {
System.out.println(addr.toString());
}
}
}
}
You're doing something wrong, but you haven't provided enough details about what you're doing for us to know what you're doing wrong.
Are you using IMAP?
Show us some code and the debug output.
If you're searching in an IMAP folder using the predefined SearchTerm implementations, it will try to perform the search on the server. Look at the implementation of SearchSequence.generateSequence. In your example you would probably want to use FromStringTerm.
If you're using the gimap provider, you can also use Google's IMAP extensions, which include the X-GM-RAW search attribute, allowing you to search exactly like in the Gmail web interface. The java implementation is in GmailRawSearchTerm and only works server-side.

Resources