how to get youtube video id in the url java/etc - javascript

how to get youtube video id via javascript can anyone help me
here is the youtube http://www.youtube.com/watch?v=mG6DRzIyhOo

For your simple case; use the = javascript String.substr function :
var url = "http://www.youtube.com/watch?v=mG6DRzIyhOo";
var video_id = url.substr(url.indexOf("=")+1);
But since youtube can have a variety of different video url formats, I would recommend using the following solution using regular expressions :
https://stackoverflow.com/a/8260383/3303171

Related

node.js url of video id

I'm working on new project.
and I'm trying to get the video id from the URL
the URL needs to be "localhost/MyVid/Watch/xSw23PzA"
xSw23PzA - is the id and I don't know how to get that.
I'm using socket.io to send data for the HTML file, and I have no idea how I can get the Video Id.
If you're always using the same schema
var url = "localhost/MyVid/Watch/xSw23PzA";
var videoId = url.split('/').pop();

Get youtube file URL from video ID using API

I want to reproduce all youtube files embedded on a site using SoundManager2 audio player. How can I get access to Youtube file URL from video ID?
Note: Soundcloud offers the possibility to get the direct streaming URL from the song URL. Here is a working example with Soundmanager2 and Angular. Now I want to do the same for Youtube.
Your title said using API. It's not possible to get access to YouTube file URL from video ID by that. By mean, with file URL you can also download it, distribute content etc while it's against YouTube Terms. So there is no such API for that.
Since you're tagged with Javascript, there is possibility to get direct access to the file URL. This probably is not as you wanted exactly but it worked flawlessly from the developer tools console available in any browser. For details Here you go
const videoUrls = ytplayer.config.args.url_encoded_fmt_stream_map
.split(',')
.map(item => item
.split('&')
.reduce((prev, curr) => (curr = curr.split('='),
Object.assign(prev, {[curr[0]]: decodeURIComponent(curr[1])})
), {})
)
.reduce((prev, curr) => Object.assign(prev, {
[curr.quality + ':' + curr.type.split(';')[0]]: curr
}), {});
console.log(videoUrls);
One slightly hacky way - You could use Youtube's OEmbed API, however you need to provide a URL, so you'd need to add the ID onto the end.
https://www.youtube.com/oembed?url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DiwGFalTRHDA
This will consistently return an embed iframe, which you could regex the URL out of.
var regex = /<iframe.*?src='(.*?)'/;
var src = regex.exec(str)[1];

Is it possible to get information from ID3 tag metadata embedded in HLS stream in Safari?

I have an HLS stream that streams a live feed with embedded ID3 PRIV Tag to mark a certain points in stream. Is it possible to get notified or somehow retrieved the data from these tags in Safari, ideally via Javascript?
Sure, this is possible using JavaScript functions, like:
video.textTracks.addEventListener('addtrack', function(addTrackEvent) {
var track = addTrackEvent.track;
track.mode = 'hidden';
track.addEventListener('cuechange', function(cueChangeEvent) {
// some processing here...
});
});
This is basically based on an answer from this question about ID3 tags on iOS.

parse youtube video id from string with javascript

hello I found lots of threads here which explains how to parse youtube id from url but nothing I found which can extract youtube video id from string.
I need a function which can return me youtube video id from url
For Example I have string
> Hello this is my string and this is my youtube video : http://youtube.com/w=abcdef and this is my blog http://stackoverflow.com etc etc.
and it should return
> Hello this is my string and this is my youtube video : abcdef and this is my blog http://stackoverflow.com etc etc.
Trying this function but not working properly
function linkifyYouTubeURLs(text) {
var re = /https?:\/\/(?:[0-9A-Z-]+\.)?(?:youtu\.be\/|youtube(?:-nocookie)?\.com\S*[^\w\s-])([\w-]{11})(?=[^\w-]|$)(?![?=&+%\w.-]*(?:['"][^<>]*>|<\/a>))[?=&+%\w.-]*/ig;
return text.replace(re,
'YouTube link: $1');
}
Try this:
var re = /(?:youtube\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^"&?\/ ]{11})/i;
REGEX DEMO

(Javascript) YouTube video ID from embed code - regex?

I've got a script that goes through the page and returns all selected elements - in this case, <embed...>
For example, when a YouTube video is found in a blog, it returns an iframe. I can take the iframe src, pass it through a function, and regex the video ID. However, when the YouTube video in within a YouTube page, its embedded differently and the video ID is found within the "flashvars" attribute.
Here's an example video embed : http://pastie.org/7155840
What would you guys recommend the best way of confirming the src as YouTube, and getting the video ID qlo5XHZ8-zI from it?
Here's a solution that doesn't use a regex.
First confirm it as youtube:
if (e.src.substr(0, 19) != "http://s.ytimg.com/") return false
Then extract the video id:
// get the flashvars
var flashvars = e.getAttribute("flashvars")
// convert flashvars string to key-value pairs
flashvars = flashvars.split("&").map(function(entry) {
return entry.split("=", 2)
})
// look up the value of the "video_id" key
var video_id = flashvars.filter(function(entry) {
return entry[0] == "video_id"
})[0]
video_id should now be the video's ID.

Categories