How to get url of video element of an iframe using php - php

Good afternoon friend,
I am trying to be able to take the video from the url of the iframe, from what I see I have to first click the video so that the video element is visible in html.
Isn't there a way to automate the process? Click automatically when entering the url and extract the url from the video
The url is: https://feurl.com/v/2625zf2pddy2ge
I'm supposed to get the following url from the video at the end.
https://fvs.io/redirector?token=aVVHRmZNVzZVdldkRXJUZXdrSWRQV2RxQ2RSSjdFNGphTVBVQTVBRTR4TlpFYXdMbzlXaktueW9ETW5ma2QvYjlOZG42Mzg2eGNWSDNjT3BHUC8wMmxyUTcrZyt4ZzRwV0s4UWVLcWQzZExzdUVBN1dIbUVmSVhrbnlIWENwWHhFR09LRVBHcXpLUmg4NFlCaW10SzBGeVU2VXVNL3FvMjpUMXRDKytHYng5S1RTTU1laG0vbFZRPT0
My code is:
<?php
$data = file_get_contents('https://feurl.com/v/2625zf2pddy2ge');
preg_match('/<video[^>]*src=[\'"]([^\'"]+)[\'"][^>]*>/i', $data, $matches);
$video = $matches[1];
echo $video;
?>

Both links dont work but assuming html looks something like this a.html:
<video width="320" height="240" src="https://fvs.io/redirector?token=aVVHRmZNVzZVdldkRXJUZXdrSWRQV2RxQ2RSSjdFNGphTVBVQTVBRTR4TlpFYXdMbzlXaktueW9ETW5ma2QvYjlOZG42Mzg2eGNWSDNjT3BHUC8wMmxyUTcrZyt4ZzRwV0s4UWVLcWQzZExzdUVBN1dIbUVmSVhrbnlIWENwWHhFR09LRVBHcXpLUmg4NFlCaW10SzBGeVU2VXVNL3FvMjpUMXRDKytHYng5S1RTTU1laG0vbFZRPT0"></video>
Try this:
<?php
$data = file_get_contents('a.html');
preg_match('/<video.*?src="(.*?)"/', $data, $matches);
var_dump($matches[1]);
Output:
string(279) "https://fvs.io/redirector?token=aVVHRmZNVzZVdldkRXJUZXdrSWRQV2RxQ2RSSjdFNGphTVBVQTVBRTR4TlpFYXdMbzlXaktueW9ETW5ma2QvYjlOZG42Mzg2eGNWSDNjT3BHUC8wMmxyUTcrZyt4ZzRwV0s4UWVLcWQzZExzdUVBN1dIbUVmSVhrbnlIWENwWHhFR09LRVBHcXpLUmg4NFlCaW10SzBGeVU2VXVNL3FvMjpUMXRDKytHYng5S1RTTU1laG0vbFZRPT0"
If it doesnt work dump your $data and make sure the video tag is even there. Sometimes this is loaded later via ajax, so it is not even available in initial response.

Related

How do I download this type of file using php?

So,I'm trying to automate downloading images from picjumbo.com site.So far most things worked like finding img src and find it's image etc.But when I try to download the image all I get is an html file(open those files with notepad++ to view it).How do I download the file after loading that page? I'm putting my code below.Everything works except getting that final image! :(
How do I download that image ?
file Download page : http://picjumbo.com/download/?d=IMG_3642.jpg
How do I save that image after the page load??
thanks!
<?php
include("simple_html_dom.php");
$file = "http://picjumbo.com/";
$files = file_get_contents($file);
$html = new simple_html_dom();
$html->load($files);
foreach($html->find('img[class=image]') as $element){
$img_src = explode('/',$element->src);
$img_src = explode('-',$img_src[5]);
$img = $img_src[0];
$url = 'http://picjumbo.com/download?d='.$img.'.jpg';
copy($url, 'images/'.$img);
}
The URL redirects to a page that uses Javascript to start a separate download. If you watch what happens in the Network tab of the browser's Developer Tools, you'll see that the actual URL of the image is:
http://picjumbo.com/wp-content/themes/picjumbofree/run.php?download&d=$img.jpg
The reason you're getting an HTML page when you try to download that link instead of the image is because that page is an HTML page, not an image. If you click on it, it takes you to an HTML page rather than to an image. Now once that page is loaded, it redirects you to downloading the image using this on line 12 of the HTML code:
<meta http-equiv="refresh" content="0; url=http://picjumbo.com/wp-content/themes/picjumbofree/run.php?download&d=IMG_3642.jpg">
So the URL image is this:
http://picjumbo.com/wp-content/themes/picjumbofree/run.php?download&d=IMG_3642.jpg
In order to download this image, you'd have to gather this HTML page into a variable, and parse through it in some way to grab the URL from this, and then use file_get_contents() to download the image. To parse through this, you could use something like SimpleHTMLDOM to read it in, or since you're just looking for the one tag, if it appears consistently in the document, you could just pull out line 12 then use some creative substr() action to get the URL.

youtube embed code with PHP

I have created a blog in php. Users can write something and post it. If this includes a web address then a link automated is created using this :
<?php
//...code
$row['comment'] = preg_replace('#(https?://([-\w.]+[-\w])+(:\d+)?(/([\w-.~:/?#\[\]\#!$&\'()*+,;=%]*)?)?)#', '<font color="#69aa35">$1</font>', $row['comment']);
?>
Using this in posts, text posted successfuly and web address displayed in a link format inside text. Any idea how can I change this, so that if there is a link of youtube, then a youtube frame to be created. For example in facebook, when you post a youtube address, a youtube frame created and posted instead of a link.
I have improved my answer and tested this code:
<?php
// This is your comment string containing the youtube link
$string="Here is a link - https://www.youtube.com/watch?v=LJHFXenOPi4";
// This will remove all links from the input string
preg_match('/[a-zA-Z]+:\/\/[0-9a-zA-Z;.\/?:#=_#&%~,+$]+/', $string, $matches);
foreach($matches as $url){
// Parse each url within the comment data
$input = parse_url($url);
if ($input['host'] == 'youtube.com' || $input['host'] == 'www.youtube.com' ) {
// If it is a youtube link, then parse the get variables
parse_str(parse_url($url, PHP_URL_QUERY), $variables);
// Echo out the iframe with the relevant video ID
echo '<iframe width="560" height="315" src="//www.youtube.com/embed/'.$variables['v'].'" frameborder="0" allowfullscreen></iframe>';
}
}
?>
I hope this is what you were looking for, it has worked for me on a few tests
You know the solution don't you? :) If the snippet contains youtube.com URL, then using the same pattern matching you can replace it with a youtube embed tag :)
Basically it will be something like this in pseudo-code.
Check the comment pasted to see if youtube URL present (modify the same regex you are using for finding URL, just make it specific for youtube)
If yes, then replace it with:
<iframe type="text/html"
width="640"
height="385"
src="<youtube URL>"
frameborder="0">
</iframe>

playing videos on second page php

This is kind of stupid question but is there any way to play videos just by using two pages, I mean like instead of creating an html page for every video I upload to my website, can I have only two php pages and then pass the video from the first page and play on the second one?
I know about passing variables in url but I am kinda confused on how to do this.
I actually embedded my videos from google drive and have a format like
<iframe src="https://docs.google.com/file/d/0B5ZMsnZoUVNSWHhxeGc/preview" width="640" height="385"></iframe>
would it be possible to do like
<a href="play.php?video='test.mp4'>Click to play</a>
or like
$video= 'test.mp4';
<a href="play.php?vid='$video'>Click to play</a>
play.php
$video = $_GET['vid']
if(!empty(($video)){
//then play the video here.
}
I'm expecting you're usnig HTML5.
Let's say there's a list of videos on the first page, and you click on a name of video and it redirects you to second page. Pass the video url (or any identifier for server to know which video) in the link. You can do it like
Cats!!
This will send vid_url as a GET variable on second page. page2.php is, as you can imagine, very simple
<?php
$vid = $_GET['vid'];
//echo $vid;
echo "<video width='320' height='240' controls>
<source src=".$vid." type='video/mp4'>
Your browser does not support the video tag.
</video>"
?>
Of course, you'll do something more elaborate than simply using "echo" for formatted HTML output.
Yes. Instead of empty use isset:
if (isset($_GET["vid"])){
$video = $_GET['vid'];
//play video
}
Play This Video
And On Play.php page add this code
if(isset($_GET['video'])&&!empty($_GET['video']))
{
$Video = $_GET['video'];
// Use the Source of your video anyway you like to play the video
}else
{
echo 'No video selected to play';
}

Instagram photo get path and save into database

Hi I am currently doing my website to pull all instagram photo into my web.
this is my code:
<div id="instafeed"></div>
<script type="text/javascript">
new Instafeed({
get: 'tagged',
tagName: 'awesome',
clientId: 'xxx',
image_size: 'standard_resolution',
}).run();
</script>
How do I get the url/path of the photo that i pulled inside my site?
Is it something about JSON? but i dont know what is it anyone can give me a hint?
Thanks!
You could use a webcrawler to pull the information you need from website.
Here is a nice tutorial. You need to specify the url and the desired html tag.
<?php
include_once('simple_html_dom.php');
$html = new simple_html_dom();
$html->load_file($target_url);
foreach($html->find('img') as $link)
{
echo $link->href."<br />";
}
Moreover you should look over cURL to improve you webcrawler.
EDIT:
#youaremysunshine
the code above is from the tutorial i suggested you look at. 'simple_html_dom.php' is a file that you need to download (you can find it in the tutorial) in order to use its functions.
So, after you include the file, you simply create a new simple_html_dom object and call the function load_file() with the desired url as a parameter. $html->find('img') looks for the <img> tag from the given page. Try to read the tutorial a few times and you may need to look up for part 2. Go to the website with the desired image and inspect element to see wich element you need to use for the find() function (the parameter may also contain the class/id of the searched element).

Shadowbox PHP Facebook Graph Api Error

i'm using shadowbox for my website to open the big images with clicking thumbnails as you know. My Problem is, i'm fetching the users' facebook profile photo like :
$large = "https://graph.facebook.com/{$id2}/picture?type=large";
$small = "https://graph.facebook.com/{$id2}/picture?type=square";
And it's working perfect, but in shadowbox i have problem with large image..
I'm calling this in shadowbox like :
<a href="<?php echo $large; ?>" rel="shadowbox">
<img style="max-width:50px; max-height:50p;" src="<?php echo $small; ?>" />
</a>
As you can imagine, small image is showing perfect, but when i click on the small image which has href, it fails to show the large image.
I've tried to change large image variable to this :
$large = "https://graph.facebook.com/{$id2}/picture?type=large&redirect=false";
but also it has failed to show the large image..
Hope you can help, thank you
I haven't worked with Shadowbox before, so I don't know how it works behind the scenes. It may be that it can't deal with a url that returns another url for the large image.
Try making the API call with php and then passing this result to shadowbox.
$large = file_get_contents("https://graph.facebook.com/{$id2}/picture?type=large&redirect=false");
Of course, using file_get_contents() like this is a quick and dirty method. If it works, before you roll this out to a production site, you'll want to use cURL or better yet the Facebook PHP SDK to do this.
Assuming you're using shadowbox to show multiple users' photos on a page, you'll probably end up bumping into the API limits at some point. To prevent this, redo your API calls to grab multiple photos in one shot:
$large_photos = $fb->api('/picture?type=large&redirect=false&ids=' .
implode($ids_array, ','));
https://graph.facebook.com/{$id2}/picture?type=large&redirect=false basically returns you a text content the URL of the image. That's why it's not showing.
Eg.
https://graph.facebook.com/yungsenriady.budiman.3/picture?type=large&redirect=false
returns
"https://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash3/157348_100001167523294_1569184886_n.jpg"
Try just use
https://graph.facebook.com/{$id2}/picture?type=large

Categories