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();
Related
How do I get the data type from a file which is fetched from an URL string, e.g:
https://firebasestorage.googleapis.com/v0/b/MyApp.appspot.com/o/alertImgs%2Falert-1521356210850.jpg?alt=media&token=b6ad7e6e-1eb0-4e05-a11d-e59c8f1df365 (just an example)
When I fetch the URL with javascript from firebase firestore I need to know which data type have the file to put it on a video or image tag.
How can I acomplish this?
I'm working with ionic 3 and firebase.
You can parse url and get last part of url as file name from which you can get extension of file and decide.
function getFileNameFromUrl(url) {
var el = document.createElement('a');
el.href = url;
return decodeURIComponent(el.pathname).split("/").pop();
}
console.log(getFileNameFromUrl("https://firebasestorage.googleapis.com/v0/b/MyApp.appspot.com/o/alertImgs%2Falert-1521356210850.jpg?alt=media&token=b6ad7e6e-1eb0-4e05-a11d-e59c8f1df365"));
How can I upload a file in azure if I only have the URL of the file to upload. In this case, i 'm using Dropbox file chooser which selects file from dropbox and returns its url path.
eq
https://www.dropbox.com/s/o9myet72y19iaan/Getting%20Started.pdf
Now we need the file to be stored in Windows Azure blob. What is the easiest way to do this without downloading the file first.
I'm planning to use a asp.net web api for the uploading of file to azure blob.
At first, I thought it should be quite straight forward as Azure Blob Storage support copying blobs from external URL however I don't think this would work in case of Dropbox files. I just tried it and got an error even though.
The link you mentioned above is not the direct link to the file. It's a link to a page on Dropbox's website from where you can download a file. This is obviously you don't want. Here's an alternate solution which you can try:
Replace www.dropbox.com in your URL with dl.dropboxusercontent.com (based on #smarx's comments below) and use that URL in the following code:
First you would need to append dl=1 to your request URL as query string. So your Dropbox URL would be https://www.dropbox.com/s/o9myet72y19iaan/Getting%20Started.pdf?dl=1. dl query string parameter indicates the file needs to be downloaded.
Next, using HTTPWebRequest try accessing this URL. Dropbox will respond back with another link and 302 status code. This link would be something like https://dl.dropboxusercontent.com/s/o9myet72y19iaan/Getting%20Started.pdf?token_hash=<tokenhash>.
Use this link in the code below to copy file. This would work.
CloudStorageAccount acc = new CloudStorageAccount(new StorageCredentials("account", "key"), false);
var client = acc.CreateCloudBlobClient();
var container = client.GetContainerReference("container-name");
container.CreateIfNotExists();
var blob = container.GetBlockBlobReference("dropbox-file-name");
blob.StartCopyFromBlob(new Uri("dropbox URL with dl.dropboxusercontent.com"));
Console.WriteLine("Copy request accepted");
Console.WriteLine("Now checking for copy state");
bool continueLoop = true;
do
{
blob.FetchAttributes();
var copyState = blob.CopyState;
switch (copyState.Status)
{
case CopyStatus.Pending:
Console.WriteLine("Copy is still pending. Will check status again after 1 second.");
System.Threading.Thread.Sleep(1000);//Copy is still pending...check after 1 second
break;
default:
Console.WriteLine("Terminating process with copy state = " + copyState.Status);
continueLoop = false;
break;
}
}
while (continueLoop);
Console.WriteLine("Press any key to continue.");
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'm currently using Node to scrape a blog that stores selected data in a JSON file. When scraping a blog post that contains an embedded track from Soundcloud I seem to only be able to collect the iframe src and not that actual track link (either soundcloud link or stream link).
When I scrape the iframe src url I seem to only be able to get a link that's in the following format:
https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/120261008&color=000000&auto_play=false&show_artwork=false
If I'm not able to scrape the track URL is there a way I'm able to manipulate how the above link is stored into the array? In order for this link to be usable I need to only store the url=https%3A//api.soundcloud.com/tracks/120261008 (minus the url=).
But then the problem with this is that the %3A needs replacing to a :
What's the best way to manipulate the url to achieve the desired output url either when it's being stored or when it's being called?
I'm not exactly sure what you're planning on doing with the track URL once you have it, but to get the permalink URL for a track/playlist your going to need a two step approach. First you're going to need to parse the url parameter in the query string in the iframe src:
CLIENT_ID = 'client_id=b45b1aa10f1ac2941910a7f0d10f8e28';
var src = 'https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/120261008&color=000000&auto_play=false&show_artwork=false',
match = src.match(/url=([^&]*)/),
resource = match[0],
stream = decodeURIComponent(match[1])+'/stream/?'+CLIENT_ID;
Then you're going to need to make an HTTP request to SoundCloud's resolve API to actually convert that resource into the permalink URL:
var url = 'http://api.soundcloud.com/resolve.json?'+resource+'&'+CLIENT_ID;
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.onload = function(){
var data = JSON.parse(xhr.responseText);
// do something with the data
console.log(data.permalink_url);
};
xhr.send();
I have a website written in asp.net MVC2 that shows random images, each image has an ID and the first image is a random one, however the url the visitor sees when viewing this image does not have the imageid. i want to make it so that when the user visits www.mydomain.com the query string will be updated to be something like www.mydomain.com/?imageid=12.
this way they can forward on what they see to others.
I dont mind if i set this with javascript, on the server side, or as a response redirect.
Not sure if this is the best way, but it would work, I suppose
window.onload = function(){
var images = document.getElementsByTagName('img'); //get all images
var first = images[0]; //get the first of all images
var imgid = first.id; //get the id of the first one
window.location = "www.mydomain.com?imageid="+imgid;
}