Generate a url for youtube search
I'm not sure if I understand your problem well but you could use the search by GET.
Like this http://www.youtube.com/results?search_query=the+show+must+go+on&oq=the+show+must+go+on
The "search_query" part could come from the user from your website. You'd have to parse it to the GET-syntax and send it to youtube. Then you could get the source of the results and search for your string by using regex and maybe high view counts or something like that.
But I believe that learning the youtube api would save you more time and work!
Kasper DK
Updated on June 04, 2022Comments
-
Kasper DK almost 2 years
How can I use javascript or php to generate a url for youtube, that searches for videos on a specific user account with best title match on top?
I am using this code:
<!DOCTYPE html> <head> <meta charset="utf-8" /> </head> <script type="text/javascript"> function mysearch() { var elem=document.getElementById('inputsearchquery'); var url="http://www.youtube.com/user/QueenVEVO/videos?query="+encodeURIComponent(elem.value); var win=window.open(url, '_blank'); win.focus(); } </script> <body> <h2>Enter search string (user: Queen)</h2> <input id="inputsearchquery" type="text" value="the show must go on"> <button type="button" onclick="mysearch()">Search</button> </body>
The only problem is that youtube does not place the best title match at the top! The video "The show must go on" is on 13th place, and I expected it to be on top?
Can anyone tell me how to change the url so youtube places the best title match on top? Or do I really have to use the youtube api for this task?
-
Kasper DK about 11 yearsThe only thing I can not figure out is how the url should look like. Your link youtube.com/… shows the right video on top, but it is not specific to a user account.
-
Kingalione about 11 yearsThats why I wrote that you could "read" the source and search for the "best" video. Check the source of the youtubelink and search for dir="ltr" title That will show you the titles of the videos.
-
Kasper DK about 11 yearsI have edited my question in the hope that it is now more clearly
-
Kingalione about 11 yearsOk I think I got it. You think that, if you manipulate the search string it will give you better results. But I dont think that this is possible. If I search for "the show must go on" or anything else, the first video is mostly a advertise for example. And changing the filter settings will not help you much. Also there are differences between the countries. In Germany for example we cant watch most of the video cause the "Gema" is deleting it. I don't think that it is possible to get better result by changing the string.
-
Kasper DK about 11 yearsoh, then I probably need use the api... Can you or anyone else tell me how to make a solution for this with the youtube api for php?
-
Cal McLean about 11 yearsMight this help? developers.google.com/youtube/2.0/… Example search result: gdata.youtube.com/feeds/api/…