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
Related
I'm trying to implement amazon Polly in an application. It is an MVC application.
I
was able to retrieve the audio from the text and it works fine. And am trying to highlight the respective text in the webpage while playing that audio. like the rear speaker does.
My aim is to implement it without a third-party application. I went through the documentation but I can't find anything useful. I didn't find any options that automatically highlight the text in amazon Polly itself.
Can we do anything with Speech marks for this? is there any way to do this?
Thanks in Advance :)
Edit
I have the speech mark JSON result. Now am stuck on how to sync this result with an HTML audio tag.
{"time":6,"type":"word","start":0,"end":2,"value":"Hi"}
{"time":587,"type":"word","start":4,"end":6,"value":"my"}
{"time":754,"type":"word","start":7,"end":11,"value":"name"}
{"time":1147,"type":"word","start":12,"end":14,"value":"is"}
{"time":1305,"type":"word","start":15,"end":19,"value":"John"}
I have the speech mark JSON result. Now am stuck on how to sync this result with an HTML audio tag.
You can use the timeupdate event on and audio element and sync the audio.currentTime property with the best matching speech mark from Polly.
This assumes that audio references the JavaScript variable for the HTML audio element who has it's src set to the audio file returned from Polly that corresponds to the text's speech marks:
function getSpeechMarkAtTime(speechMarks, time) {
const length = speechMarks.length
let match = speechMarks[0]
let found = false
let i = 1
while (i < length && !found) {
if (speechMarks[i].time <= time) {
match = speechMarks[i]
} else {
found = true
}
i++
}
return match
}
function onTimeUpdate(speechMark) {
/**
* Update your HTML and CSS based on the attributes
* of the speech mark at the audio's current time.
*/
}
audio.addEventListener('timeupdate', () => {
// Polly Speech Marks use milliseconds
const currentTime = audio.currentTime * 1000
const speechMark = getSpeechMarkAtTime(speechMarksJSONResult, currentTime)
// Some custom callback
onTimeUpdate(speechMark)
})
Summary :
This API call allows a user to edit or change details about a video in the system.
Endpoint / url : /api/videos/{video}.xml
Formats XML
Arguments :-
method string :- Specifies to use the HTTP PUT method if submitting the call via HTTP POST.
title string :- Specifies the new title for the video.
description string :- Specifies the new description for the video.
private boolean (true|false) :- Marks the video as private or public.
seo_url string :- Specifies the SEO url for the video.
Parameters :videos is the vzaar video number for that video.
HTTP Methods :PUT
Authentication :Required
Example
Call
http://vzaar.com/api/videos/17069.xml
Note : 17069 is vzaar video id.
Here is syntax of authenticate you vzaar acount and send a request to update video by vzaar id
public string UpdateVideo(long id, FormCollection form)
{
string vToken = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath).AppSettings.Settings["vzaar.token"].Value;
string vSecret = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath).AppSettings.Settings["vzaar.secret"].Value;
com.vzaar.api.Vzaar api = new com.vzaar.api.Vzaar(vSecret, vToken);
com.vzaar.api.VideoEditQuery videoedit = new com.vzaar.api.VideoEditQuery();
videoedit.id = CurrentVideo.VzaarID;
videoedit.markAsPrivate = false;
videoedit.title = CurrentVideo.Title;
videoedit.description = CurrentVideo.Description;
videoedit.seoUrl = "";
bool apireply = api.editVideo(videoedit);
}
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.
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
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.