i'm embedding youtube videos with subtitles in specific language (Hebrew, in my case).
im using:
hl=He&cc_load_policy=1
to show the hebrew subtitles and that works fine.
However, if there are no subs in my language, i would like to see the English one (if there are any) as a default. is there a way to force that?
You can force the captions and language using cc_load_policy & cc_lang_pref options via
URL:
http://www.youtube.com/embed/M7lc1UVf-VE?cc_load_policy=1&cc_lang_pref=en
API:
var ytPlayer = new YT.Player(
...
playerVars: {
cc_load_policy: 1,
cc_lang_pref: 'en'
},
....
});
Credits: https://webapps.stackexchange.com/questions/27669/is-there-any-way-to-force-subtitles-in-a-youtube-video
I have not found this anywhere in their api docs, but with your youtube player object you should be able to do the following to change it to english captions:
player.setOption("captions", "track", {"languageCode": "en"}); //Works for html5 ignored by AS3
player.setOption("cc", "track", {"languageCode": "en"}); //Works for AS3 ignored by html5
You can also do:
var module;
if (testplayer.getOptions().indexOf("cc") !== -1) {
module = "cc";
} else if (testplayer.getOptions().indexOf("captions") != -1) {{
module = "captions";
}
var tracklist = testplayer.getOption(module, "tracklist");
// then iterate through the tracklist to see if "he" or "en" is there.
You have cc_load_policy=1 but you can also turn it on via js by:
player.loadModule("captions"); //Works for html5 ignored by AS3
player.loadModule("cc"); //Works for AS3 ignored by html5
to turn it off:
player.unloadModule("captions"); //Works for html5 ignored by AS3
player.unloadModule("cc"); //Works for AS3 ignored by html5
I believe it would be better to just leave out the hl= entirely. (It's not actually one of our officially supported Player parameters.) The subtitles will default to the language preference of the viewer of the video, and my assumption is that it will fall back on English if there are no subtitles in the viewer's preferred language.
The only way I found is changing the URI from
https://www.youtube.com/watch?v=2s3aJfRr9gE
to this pattern
"https://www.youtube-nocookie.com/embed/" + video_id + "?hl=" lang_code
On bash/Linux you can just copy the URI with that structure and then run this command (Spanish code hardcoded) to transform clipboard content (you can make an alias):
xclip -selection c -o | echo "$(cat -)?&hl=es-419" | sed "s|youtube.com/watch?v=|youtube-nocookie.com/embed/|1" | xclip -selection c
You can list the available subtitles ISO 639-1 language codes with youtube-dl:
youtube-dl --list-subs "{video_id or url}"
The only drawback is that the video will cover the complete screen... which might be good thing to stop procrastinating with related videos :)
Related
I am using advanced custom filed wordpress plugin to create a meta tag called youtube URL...
When some one put the video url in shorter format like this https://youtu.be/H-30B0cqh88
Then the iframe I put to show the video doesn't work cause iframe doesn't work with shorter version of url
rather it needs real url as a source.. My iframe code is as below
">
How can I achive this.. Let me show you how I want to achieve this..
I am not that expert on php so please give me the full working code..
<?php
the_field("listing_video_1") == $got_url_from_user_input
if $got_url_from_user_input == https://youtu.be/H-30B0cqh88 in this format
$actual_URL= replace above url to https://youtube.com/embed/H-30B0cqh88
?>
How can I achieve this please.
Thanks in advance
Here's a simple way to use preg_replace to accomplish what you are trying to do:
<?php
// SET OUR DEFAULT URL
$got_url_from_user_input = 'https://youtu.be/H-30B0cqh88';
print "\nSTARTING URL: ".$got_url_from_user_input;
// DO THE REPLACE AND PRINT OUT THE FINAL RESULT
$actual_URL = preg_replace('~https://youtu\.be/([-A-Z0-9]+)~i', 'https://youtube.com/embed/$1', $got_url_from_user_input);
print "\nFINAL URL: ".$actual_URL;
There's not much magic here, so let me run down it quickly:
https://youtu\.be/ - Look for this pattern exactly. We escape the dot with a backslash so it finds a literal dot and not any character.
([-A-Z0-9]+) - This is just your basic character class matching any dash, letter or number, occurring at least one time. We put it in parenthesis so that we it will be saved in $1 and we can plug it into our final url.
Here is the above code in a working demo you can take a look at:
http://ideone.com/zECA2e
You can just use php str_replace() function as in following code :
<?php
$actual_url = str_replace('https://youtu.be/', 'https://www.youtube.com/embed/', $got_url_from_user_input);
echo $actual_url;
?>
str_replace() will replace youtubes short url with embade url.
I have a script that uses the YouTube API (v3) to find a video of a music from the name of the artist and the name of the music.
This works, however, in some cases, the first choice (sorted by relevance) is not the official video VEVO.
I tried adding VEVO in my query (after name of the artist and name of the music), but when there is no video VEVO, the API returns no results.
Is it possible to force to choose VEVO videos, if they exist?
Thank you.
Vincent
var request = gapi.client.youtube.search.list
({
q: artiste+' '+track,
part: 'snippet',
order: 'relevance'
});
request.execute(function(response)
{
idVideo=response.result.items[0].id.videoId;
});
This is the part that allows to select the id of a video based on the artist's name and the name of the music
UPDATE: I don't think the syndicated video suggesting I put below would work well but I'll leave it there just in case you want to explore it. What might work better, again not guaranteed but should be more accurate just hoping for the best would be to simply sort it by viewCount instead of relevance... Generally speaking, the VEVO videos have the most views.
Example: https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.search.list?part=snippet&order=viewCount&q=nicki+minaj+anaconda&type=video&_h=3&
GET https://www.googleapis.com/youtube/v3/search?part=snippet&order=viewCount&q=nicki+minaj+anaconda&type=video&key={YOUR_API_KEY}
--
ORIGINAL ANSWER
I haven't been able to test it yet and it won't necessarily restrict it to ONLY vevo videos but you can try the syndicated option https://developers.google.com/youtube/v3/docs/search/list#videoSyndicated
string
The videoSyndicated parameter lets you to restrict a search to only videos that can be played outside youtube.com. If you specify a value for this parameter, you must also set the type parameter's value to video.
Acceptable values are:
any – Return all videos, syndicated or not.
true – Only retrieve syndicated videos.
If that returns nothing, than do the same search without syndicated and use the first option from that.
It is actually pretty easy. What you need to do is add 'VEVO' to you search query. This will make sure that anything from a VEVO channel will be the first result. It should look something like this.
var request = gapi.client.youtube.search.list
({
q: artiste+' '+track + 'VEVO',
part: 'snippet',
order: 'relevance'
});
If you wan't to make sure you are getting a VEVO video the easiest thing to do is parse the channel title to make sure it contains the word "VEVO". The Code would then look something like this
var request = gapi.client.youtube.search.list
({
q: artiste+' '+track + 'VEVO',
part: 'snippet',
order: 'relevance'
});
var obj = JSON.parse(result.content);
var findChannelTitle = obj.items[0].snippet.channelTitle;
var isVevo = findChannelTitle.match(/VEVO/g); //checks to see if this is VEVO content. We only wan't to use Vevo videos.
if (isVevo){ //returns true if VEVO is found in the channel title
var youtubeVideoId = obj.items[0].id.videoId; //finds the video ID
return youtubeVideoId;
}else{
return null;
}
I'm using the Tropo MVC classes and have a problem with changing the voice in the say. Setting the voice property of the say object does not seem to change the voice for example:
Say say1 = new Say("This is first voice");
say1.Voice = "susan";
Say say2 = new Say("This is the male voice");
say2.Voice = "dave";
List<Say> sayList = new List<Say>();
sayList.Add(say1);
sayList.Add(say2);
Script.Ask(null, null, new Choices("[1 DIGIT]", "dtmf", "#"), null, strArgs, true, sayList, Convert.ToSingle(action.Timeout));
The voice does not change. In fact it appears that the only way to change the voice is to set Script.Voice = "voice" which doesn't work for me as I have to handle language select in the first Ask which requires English voice followed by French voice.
Tropo also supports SSML, which is a super powerful markup language for mixing voices and adjusting voice tempo/cadence.
You can mix voices in a single Say command by doing something like:
new Say("<?xml version='1.0'?><speak>For English please press 1.<voice name='Carlos' xml:lang='es'>para el español por favor pulse 2</voice></speak>")
The inline XML is kinda yukkie but it gets the job done and learning SSML will allow you to create some really professional-sounding apps.
i was developed and launched an app for Samsung Smart TV
on(2011 TV) (SDK 2.5) and everything is ok.
and made it by YouTube JavaScript Player API v2
Now i'm trying to convert it to (2012 TV) (SDK 3.5)by use YouTube JavaScript Player API v3
im just change the version value from [apiplayer?version=2&enablejsapi=1 ] to==>[apiplayer?version=3&enablejsapi=1 ]
but nothing shown on tv or emulator just show a youtube word but no video
this is my youtube create function
function createYoutube() {
if (Main.onLine && !youtubeCreated)
{
youtubeCreated = true;
var html = "<object type='application/x-shockwave-flash' id='playerObject' style='width:507px; height:285.1px;'> "+
"<param name='movie' value='http://youtube.googleapis.com/apiplayer?version=3&enablejsapi=1'></param>"+
"<param name='allowScriptAccess' value='always'></param>"+
"<param name='wmode' value='transparent'></param> "+
"</object>";
var player = document.getElementById("player")
widgetAPI.putInnerHTML(player,html);
}
function onYouTubePlayerReady()
{
YouTubePlayer = document.getElementById('playerObject');
YouTubePlayer.addEventListener('onStateChange','onPlayerStateChange');
YouTubePlayer.addEventListener('onError', 'onPlayerError');
refreshPlayer();
}
i tried use http://www.youtube.com/apiplayer?enablejsapi=1&version=3
but nothing changed .
i think you are using the wrong param use this
<param name="movie" value="http://www.youtube.com/apiplayer?&enablejsapi=1&version=3&controls=1&fs=1"></param>
insted of
<param name='movie' value='http://youtube.googleapis.com/apiplayer?version=3&enablejsapi=1'></param>
version=2 implies that the ActionScript 2 runtime will be used. (This version has been deprecated for a few years now and will be shut down soon.) version=3 implies that the ActionScript 3 runtime will be used. It might be that your platform doesn't support the ActionScript 3 runtime, in which case you'd need to follow up with Samsung.
I am trying to get the video URL of any YouTube video like this:
Open
http://youtube.com/get_video_info?video_id=VIDEOID
then take the account_playback_token token value and open this URL:
http://www.youtube.com/get_video?video_id=VIDEOID&t=TOKEN&fmt=18&asv=2
This should open a page with just the video or start a download of the video. But nothing happens, Safari's activity window says 'Not found', so there is something wrong with the URL. I want to integrate this into a iPad app, and the javascript method to get the video URL I use in the iPhone version of the app isn't working, so I need another solution.
YouTube changes all the time, and I think the URL is just outdated. Please help :)
Edit: It seems like the get_video method doesn't work anymore. I'd really appreciate if anybody could tell me another way to find the video URL.
Thank you, I really need help.
Sorry, that is not possible anymore. They limit the token to the IP that got it.
Here's a workaround by using the get_headers() function, which gives you an array with the link to the video. I don't know anything about ios, so hopefully you can rewrite this PHP code yourself.
<?php
if(empty($_GET['id'])) {
echo "No id found!";
}
else {
function url_exists($url) {
if(file_get_contents($url, FALSE, NULL, 0, 0) === false) return false;
return true;
}
$id = $_GET['id'];
$page = #file_get_contents('http://www.youtube.com/get_video_info?&video_id='.$id);
preg_match('/token=(.*?)&thumbnail_url=/', $page, $token);
$token = urldecode($token[1]);
$get = $title->video_details;
$url_array = array ("http://youtube.com/get_video?video_id=".$id."&t=".$token,
"http://youtube.com/get_video?video_id=".$id."&t=".$token."&fmt=18");
if(url_exists($url_array[1]) === true) {
$file = get_headers($url_array[1]);
}
elseif(url_exists($url_array[0]) === true) {
$file = get_headers($url_array[0]);
}
$url = trim($file[19],"Location: ");
echo 'Download video';
}
?>
I use this and it rocks: http://rg3.github.com/youtube-dl/
Just copy a YouTube URL from your browser and execute this command with the YouTube URL as the only argument. It will figure out how to find the best quality video and download it for you.
Great! I needed a way to grab a whole playlist of videos.
In Linux, this is what I used:
y=http://www.youtube.com;
f="http://gdata.youtube.com/feeds/api/playlists/PLeHqhPDNAZY_3377_DpzRSMh9MA9UbIEN?start-index=26";
for i in $(curl -s $f |grep -o "url='$y/watch?v=[^']'");do d=$(echo
$i|sed "s|url\='$y/watch?v=(.)&.*'|\1|"); youtube-dl
--restrict-filenames "$y/watch?v=$d"; done
You have to find the playlist ID from a common Youtube URL like:
https://www.youtube.com/playlist?list=PLeHqhPDNAZY_3377_DpzRSMh9MA9UbIEN
Also, this technique uses gdata API, limiting 25 records per page.
Hence the ?start-index=26 parameter (to get page 2 in my example)
This could use some cleaning, and extra logic to iterate thru all sets of 25, too.
Credits:
https://stackoverflow.com/a/8761493/1069375
http://www.commandlinefu.com/commands/view/3154/download-youtube-playlist (which itself didn't quite work)