How to get Vine video url - php

I love vinepeek and want to make something better.
I have the Vine link e.g. http://vine.co/v/bJqWrOHjMmU, however this is a link to a page, not the video URL.
I know it's new, but does Vine have an API, or how else would I be able to get the url of the video? I'm still puzzled as to how Vinepeek gets the video url?

It is in the page source; you could parse it with a JavaScript bookmarklet
function qry(sr) {
var qa = [];
for (var prs of sr.split('&')) {
var pra = prs.split('=');
qa[pra[0]] = pra[1];
}
return qa;
}
var alpha = document.querySelector('[name=flashvars]').getAttribute('value');
var bravo = qry(alpha);
bravo.src;
Result
https://vines.s3.amazonaws.com/videos/08C49094-DFB4-46DF-8110-EEEC7D4D6115-1133-000000B8AD9BE72C_1.0.1.mp4?versionId=TQGtC5O7G7H34TleFA2LF0Er9tI8VZUe
Source

The JSON API has the following URL: http://vinepeek.com/video
You can use a web inspector / console / developer tool to check the source code.
<video id="post_html5_api" class="vjs-tech" loop="" preload="auto" src="https://vines.s3.amazonaws.com/videos/08C49094-DFB4-46DF-8110-EEEC7D4D6115-1133-000000B8AD9BE72C_1.0.1.mp4?versionId=TQGtC5O7G7H34TleFA2LF0Er9tI8VZUe"></video>
The URL is:
https://vines.s3.amazonaws.com/videos/08C49094-DFB4-46DF-8110-EEEC7D4D6115-1133-000000B8AD9BE72C_1.0.1.mp4?versionId=TQGtC5O7G7H34TleFA2LF0Er9tI8VZUe

This is a simple function which i use to get video src from curl result.
http://vine.co/v/bJqWrOHjMmU
function getVineVideoFromUrl($url) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$res = curl_exec($ch);
preg_match('/twitter:player:stream.*content="(.*)"/', $res, $output);
return $output[1];
}
result
https://vines.s3.amazonaws.com/v/videos/08C49094-DFB4-46DF-8110-EEEC7D4D6115-1133-000000B8AD9BE72C_1.0.1.mp4?versionId=ms6ePoPeFm6NQZkeNHegV3k_ZLV4bz9x

Related

screenshot using googlepagespeed api

Below is my code to capture the screenshot of of webpage. But i get the output of the same as how in the image below. Kindly suggest on what is the mistake i am committing. Also kindly suggest the method to save this screenshot to the server?
<?php
$url='https://www.google.com';
$stratedy = 'mobile' ;
$apiReqUrl = 'https://www.googleapis.com/pagespeedonline/v2/runPagespeed';
$apiKey = 'my_api_key' ;
$curl = curl_init();
curl_setopt($curl, CURL_OPTURL, $apiReqUrl.'?url='.$reqUrl.'
&key='.$apiKey.'&screenshot=true&strategy='.$stratedy);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
$result=curl_exec($curl);
$data = json_decode($result, true);
$img = str_replace(array('_','-'), array('/','+'), $data['screenshot']
['data']);
echo '<img src="data:image/jpeg;base64,'.$img.'">';
?>
If you can, try using the HTML version from Generating Screenshots of URLs using Google's secret magic API. All you need to do is to call the API and it's free (I guess).
For example in PHP:
<?php
$url = "https://praveen.science/";
// Hit the Google PageSpeed Insights API.
// Catch: Your server needs to allow file_get_contents() to make this run. Or you need to use cURL.
$response = file_get_contents('https://www.googleapis.com/pagespeedonline/v2/runPagespeed?screenshot=true&url='.urlencode($url));
// Convert the JSON response into an array.
$googlePagespeedObject = json_decode($response, true);
// Grab the Screenshot data.
$screenshot = $googlePagespeedObject['screenshot']['data'];
// Fix url encoded base64
$screenshot = str_replace(array('_','-'), array('/','+'), $screenshot);
// Build the Data URI scheme and spit out an <img /> Tag.
echo "<img src=\"data:image/jpeg;base64,{$screenshot}\" alt=\"Screenshot\" />";
// Or.. base64 decode and store
file_put_contents('...', base64_decode($screenshot));
Or in JavaScript:
$(function() {
// Get the URL.
var url = "https://praveen.science/";
// Prepare the URL.
url = encodeURIComponent(url);
// Hit the Google Page Speed API.
$.get("https://www.googleapis.com/pagespeedonline/v1/runPagespeed?screenshot=true&strategy=mobile&url=" + url, function(data) {
// Get the screenshot data.
var screenshot = data.screenshot;
// Convert the Google's Data to Data URI scheme.
var imageData = screenshot.data.replace(/_/g, "/").replace(/-/g, "+");
// Build the Data URI.
var dataURI = "data:" + screenshot.mime_type + ";base64," + imageData;
// Set the image's source.
$("img").attr("src", dataURI);
});
});
<script src="https://code.jquery.com/jquery-2.2.4.js"></script>
<h1>Hard Coded Screenshot of my Website:</h1>
<img src="//placehold.it/300x50?text=Loading+Screenshot..." alt="Screenshot" />
There are a lot of APIs available on the internet to take screenshots. Something like https://www.purplescreenshots.com/ has example of integrating screenshots too.

Get vine image with cURL

Im trying to get vine image using cURL but its returning empty.
I want to extract the image from vine meta tags
<meta property="twitter:image:src" content="https://v.cdn.vine.co/r/thumbs/C40D8A18E21388329752896937984_58406422053.35.0.D4119957-7F82-4C6F-94EC-4732C58E79E1.mp4.jpg?versionId=lWIZyat1QyiI8rjnz3KFsbWtuOoUmGFn">`
This is my code
$ch1eckUrl = "https://vine.co/v/51wPzgnEHLb";
function getVineVideoFromImage($ch1eckUrl) {
$ch1 = curl_init($ch1eckUrl);
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 1);
$res1 = curl_exec($ch1);
preg_match('/twitter:image:src.*content="(.*)"/', $res1, $opimage);
$VineImage = $opimage[1];
}
Applicate if someone can point me what im doing wrong here
The Answer is already posted here:How to get Vine video url
You've even copied an answer. Just replace twitter:player:stream. with twitter:image:src.
My bad, didn't read Image
On that note, there's an even easier way:
<?php
$ch1eckUrl = 'https://vine.co/oembed/51wPzgnEHLb.json';
function getVineVideoFromImage($ch1eckUrl) {
$json = json_decode(file_get_contents($ch1eckUrl), true);
return $json['thumbnail_url'];
}
$VineImage = getVineVideoFromImage($ch1eckUrl);
echo($VineImage);
?>
Vine servers JSON, so just fetch that and decode it and you got the url.

fetch all youtube videos using curl

I'm a beginner at PHP. I have one task in my project, which is to fetch all videos from a YouTube link using curl in PHP. Is it possible to show all videos from YouTube?
I found this code with a Google search:
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.youtube.com');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$contents = curl_exec ($ch);
echo $contents;
curl_close ($ch);
?>
It shows the YouTube site, but when I click any video it will not play.
You can get data from youtube oemebed interface in two formats Xml and Json which returns metadata about a video:
http://www.youtube.com/oembed?url={videoUrlHere}&format=json
Using your example, a call to:
http://www.youtube.com/oembed?url=http://www.youtube.com/watch?v=B4CRkpBGQzU&format=json
So, You can do like this:
$url = "Your_Youtube_video_link";
Example :
$url = "http://www.youtube.com/watch?v=m7svJHmgJqs"
$youtube = "http://www.youtube.com/oembed?url=" . $url. "&format=json";
$curl = curl_init($youtube);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$return = curl_exec($curl);
curl_close($curl);
$result = json_decode($return, true);
echo $result['html'];
Try it...Hope it will help you.
You could use curl to retrieve the Google main page (or an alternative page) and parse the returned html using a library such as html5lib. If you wanted to try this approach the first step could be to 'view source' on the relevant page and look at how the links are structured.
A more elegant way to approach the problem could be to use the Youtube API (a way to interact with the Youtube system), which may allow you to retrieve the links directly. e.g it may be possible to just ask the Youtube API to send you the links. Try this.
You can also get all youtube's channel videos using file_get_contents
bellow is sample and working code
<?php
$Youtube_API_Key = ""; // you can obtain api key : https://developers.google.com/youtube/registering_an_application
$Youtube_channel_id = "";
$TotalVideso = 50; // 50 is max , if you want more video you need Youtube secret key.
$order= "date"; ////allowed order : date,rating,relevance,title,videocount,viewcount
$url = "https://www.googleapis.com/youtube/v3/search?key=".$Youtube_API_Key."&channelId=".$Youtube_channel_id."&part=id&order=".$order."&maxResults=".$TotalVideso."&format=json";
$data = file_get_contents($url);
$JsonDecodeData=json_decode($data, true);
print_r($data);
?>

Easy way to get Vimeo id from a vimeo url

I'm trying to get just the id from a vimeo URL. Is there a simpler way than this? All the vimeo video urls I see are always:
https://vimeo.com/29474908
https://vimeo.com/38648446
// VIMEO
$vimeo = $_POST['vimeo'];
function getVimeoInfo($vimeo)
{
$url = parse_url($vimeo);
if($url['host'] !== 'vimeo.com' &&
$url['host'] !== 'www.vimeo.com')
return false;
if (preg_match('~^http://(?:www\.)?vimeo\.com/(?:clip:)?(\d+)~', $vimeo, $match))
{
$id = $match[1];
}
else
{
$id = substr($link,10,strlen($link));
}
if (!function_exists('curl_init')) die('CURL is not installed!');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://vimeo.com/api/v2/video/$id.php");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$output = unserialize(curl_exec($ch));
$output = $output[0];
curl_close($ch);
return $output['id'];
}
$vimeo_id = getVimeoInfo($vimeo);
There are lot many vimeo URLs that are valid. Few examples are
All valid URLs:
http://vimeo.com/6701902
http://vimeo.com/670190233
http://player.vimeo.com/video/67019023
http://player.vimeo.com/video/6701902
http://player.vimeo.com/video/67019022?title=0&byline=0&portrait=0
http://player.vimeo.com/video/6719022?title=0&byline=0&portrait=0
http://vimeo.com/channels/vimeogirls/6701902
http://vimeo.com/channels/vimeogirls/67019023
http://vimeo.com/channels/staffpicks/67019026
http://vimeo.com/15414122
http://vimeo.com/channels/vimeogirls/66882931
All invalid URLs:
http://vimeo.com/videoschool
http://vimeo.com/videoschool/archive/behind_the_scenes
http://vimeo.com/forums/screening_room
http://vimeo.com/forums/screening_room/topic:42708
I wrote this java regex that catches all the above valid URLs and rejects the invalid ones. I m not sure though if they vimeo has more valid URLs.
(https?://)?(www.)?(player.)?vimeo.com/([a-z]*/)*([0-9]{6,11})[?]?.*
Hope this helps...
I think using parse_url() is the best option:
$vimeo = 'https://vimeo.com/29474908';
echo (int) substr(parse_url($vimeo, PHP_URL_PATH), 1);
For those of you who want to see the code fully implemented using PHP, I am using the regex provided by user2200660 and formatted for PHP by Morgan Delaney, here it is:
$vimeo = 'http://player.vimeo.com/video/67019023';
if(preg_match("/(https?:\/\/)?(www\.)?(player\.)?vimeo\.com\/([a-z]*\/)*([0-9]{6,11})[?]?.*/", $vimeo, $output_array)) {
echo "Vimeo ID: $output_array[5]";
}
//outputs: Vimeo ID: 67019023
[Edit] You can now do this all via the API!
If you provide a comma separated list of your Vimeo urls via the "links" parameter to the search endpoint (https://developer.vimeo.com/api/endpoints/videos#GET/videos) we will return those videos as API responses.
e.g.
GET https://api.vimeo.com/videos?links=https://vimeo.com/74648232,https://vimeo.com/232323497
[Original]
Vimeo provides many different type of video urls, some of which do not include the id. To ensure support across all of Vimeo's urls you should ask vimeo directly for the ID.
You can ask vimeo via the oEmbed endpoint.
There are many options, but the easiest option is to make an HTTP GET request to the url https://vimeo.com/api/oembed.json?url={vimeo_url}, replacing {vimeo_url} with the appropriate url.
For example, to get the ID of the url you provided above (https://vimeo.com/29474908) make an HTTP GET request to
https://vimeo.com/api/oembed.json?url=https://vimeo.com/29474908
Parse the JSON response, and grab the video_id parameter.
This should retrieve the ID from all kinds of vimeo urls.
$url = 'https://vimeo.com/cool/29474908?title=0&byline=0&portrait=0';
$urlParts = explode("/", parse_url($url, PHP_URL_PATH));
$videoId = (int)$urlParts[count($urlParts)-1];
A current, working regex:
function getIdFromVimeoURL(url) {
return /(vimeo(pro)?\.com)\/(?:[^\d]+)?(\d+)\??(.*)?$/.exec(url)[3];
}
console.log(getIdFromVimeoURL("https://vimeo.com/channels/staffpicks/272053388"))
console.log(getIdFromVimeoURL("https://vimeo.com/272053388"))
console.log(getIdFromVimeoURL("https://player.vimeo.com/video/272053388"))
// ...etc.
If someone need it in JavaScript based on #user2200660 answer:
function getVimeoVideoId(url){
var regex = new RegExp(/(https?:\/\/)?(www.)?(player.)?vimeo.com\/([a-z]*\/)*([0-9]{6,11})[?]?.*/);
if ( regex.test(url) ) {
return regex.exec(url)[5];
}
}
If you only need the Vimeo ID, you can use the RegExp non-capturing groups:
(?:https?:\/\/)?(?:www\.)?vimeo\.com\/(?:(?:[a-z0-9]*\/)*\/?)?([0-9]+)
A lot of good answers here, specifically #user2200660.
https://stackoverflow.com/a/16841070/3850405
However a use case that has not been supported in the previous answers is this:
https://vimeo.com/showcase/7008490/video/407943692
Regex that can handle it and the other examples:
(https?:\/\/)?(www\.)?(player\.)?vimeo\.com\/?(showcase\/)*([0-9))([a-z]*\/)*([0-9]{6,11})[?]?.*
https://regex101.com/r/p2Kldc/1/
$vimeo = 'http://player.vimeo.com/video/67019023';
if(preg_match("/(https?:\/\/)?(www\.)?(player\.)?vimeo\.com\/?(showcase\/)*([0-9))([a-z]*\/)*([0-9]{6,11})[?]?.*/", $vimeo, $output_array)) {
echo "Vimeo ID: $output_array[6]";
}
Credits to #zeckdude for the original example code in PHP.
https://stackoverflow.com/a/29860052/3850405
In 2022, this is still the one to go with for Vimeo videos:
https://gist.github.com/anjan011/1fcecdc236594e6d700f
(Tested on all the faulty url's given in the comments as well.)

Using file_get_contents to different URLs in a loop seems to break the rest of the code

I am currently trying to fetch some facebook data, which I then want to access in Javascript. Specifically, I am trying to access some characteristics of the user's friends.
So I am getting the user's friend list using file_get_contents to his graph API URL.
This provides me with an array of friend ids.
As I need a characteristic from each friend, I am doing:
foreach($dataarray as $friend) {
$friendurl = "https://graph.facebook.com/".$friend->id."?access_token=".$token."";
$fdata = json_decode(file_get_contents($friendurl));
if($fdata->gender == "male") {
array_push($fulldata, $fdata->name);
}
}
Having this code piece seems to break the javascript code, as none of my alert instructions are ran.
Also, inserting a break after the if, so that only one file_get_contents is done, seems to make the code runnable (but I obviously need to go through all of the friends).
How can I solve this?
I would use jQuery or xmlHttpRequest to do the HTTP GET, but somehow I always seem to get back a status code of 0, with an empty response.
Edit:
Here is the JS code:
<script type="text/javascript">
function initialize() {
alert('Test1');
<?php
$fulldata = array();
$data = $result->data;
foreach($data as $friend) {
$friendurl = "https://graph.facebook.com/".$friend->id."?access_token=".$token."";
//echo("alert(\"".$friendurl."\");");
$fdata = json_decode(file_get_contents($friendurl));
if($fdata->hometown->name) {
array_push($fulldata, $fdata->hometown->name);
}
}
echo ("alert(\"".count($fulldata)."\")");
?>
}
</script>
I should've also added that this is being done on a page embedded into facebook using the canvas feature.
Try...
function curl($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
return curl_exec($ch);
curl_close ($ch);
}
foreach($dataarray as $friend){
$friendurl = "https://graph.facebook.com/".$friend->id."?access_token=".$token."";
$fdata = json_decode(curl($friendurl));
if($fdata->gender == "male"){
array_push($fulldata, $fdata->name);
}
}
Maybe FGC is disabled but you don't get any notifications/warnings.
Code from comment:
error_reporting(E_ALL); ini_set("display_errors", 1);
Note that you are doing cross-domain AJAX call which is prohibited for security reasons.
You can do the api call on the server and echo the data to the client side JS, or you can build a php proxy return the result of the Graph API call(As the proxy is at your own server, they are in the same domain).

Categories