So I've been using this simple method to determine whether or not a URL is from vimeo
if (preg_match("/vimeo/",$url)) {
$getvim = (parse_url($url));
$vimid = str_replace("/", "", $getvim['path']);
}
As you can see this simply determines if the url contains "vimeo" then grabs the video id by grabbing everything after the slash. Works fine if you're actually linking a vimeo video, however utterly messes everything up if the link just contains "vimeo" without actually being a vimeo link.
Does anyone have a better method of doing this? There are tons of YouTube solutions available but finding a good vimeo one has been nearly impossible. Any help with this is appreciated, thank you.
Try this code:
$urls = parse_url($url);
if ($urls['host'] == 'vimeo.com'){
$vimid = ltrim($urls['path'], '/');
if (is_numeric($vimid)) {
// do something with $vimid
}
}
We assume that all video IDs are numerical.
Read the source of the page via file_get_contents($url) and then check if it contains the string <meta property="og:video" content="http://vimeo.com/moogaloop.swf?clip_id=".$vimid." /> If if contains that string, then you know its a valid video.
Related
i want to make a social media audit tool and i want to get likes of a person's Fb page. Basically what i want is i want that person to enter his FB pages URL and then i want to fetch the likes of his page and echo it in my PHP page. Is there any way I can do that without using graph API or any API. I just want a simple piece of code.
I have searched many questions regarding my project on web and on StackOverflow as well but coudn't find what i wanted, at last, I am asking this question. Is there anyone who can help me regarding this?
Thanx in advance.
<?php
$file = "https://www.facebook.com/IntellectualIndies/?epa=SEARCH_BOX";
$data = file_get_contents($file);
preg_match_all ('~<div class=\'_4bl9\'>\s*(<div.*?</div>\s*)?(.*?)</div>~is', $data, $matches);
$content = $matches[1];
$total = count($content);
for($i=0; $i<$total; $i++){
echo $content[$i]."<br />";
}
?>
i tried this code.
Is there any way I can do that without using graph API or any API
No, scraping is not allowed on Facebook.
There is only one way to do this:
Apply for Page Public Content Access
Use the Graph API with the following endpoint/field: /page-id?fields=fan_count
API Reference with example code: https://developers.facebook.com/docs/graph-api/reference/page/
I'm struggling to make AJAX-based website SEO-friendly. As recommended in tutorials on the web, I've added "pretty" href attributes to links: контакт and, in a div where content is loaded with AJAX by default, a PHP script for crawlers:
$files = glob('./pages/*.php');
foreach ($files as &$file) {
$file = substr($file, 8, -4);
}
if (isset($_GET['site'])) {
if (in_array($_GET['site'], $files)) {
include ("./pages/".$_GET['site'].".php");
}
}
I have a feeling that at the beginning I need to additionaly cut the _escaped_fragment_= part from (...)/index.php?_escaped_fragment_=site=about because otherwise the script won't be able to GET the site value from URL , am I right?
but, anyway, how do I know that the crawler transforms pretty links (those with #!) to ugly links (containing ?_escaped_fragment_=)? I've been told that it happens automatically and I don't need to provide this mapping, but Fetch as Googlebot doesn't provide me with any information about what happens to URL.
Google bot will automatically query for ?_escaped_fragment_= urls.
So from www.example.com/index.php#!site=about
Google bot will query: www.example.com/index.php?_escaped_fragment_=site=about
On PHP site you will get it as $_GET['_escaped_fragment_'] = "site=about"
If you want to get the value of the "site" you need to do something like this:
if(isset($_GET['_escaped_fragment_'])){
$escaped = explode("=", $_GET['_escaped_fragment_']);
if(isset($escaped[1]) && in_array($escaped[1], $files)){
include ("./pages/".$escaped[1].".php");
}
}
Take a look at the documentation:
https://developers.google.com/webmasters/ajax-crawling/docs/specification
I am wondering if there is a way to get the name of a website from a URL. I know you can parse a URL to get a domain name, but since site names are not standardized as far as code is concerned, I am doubtful.
An example of how this could be used is say I am linking to a New York Times article. I can have the title of the article link to the article page. Then I might want to have the source, "The New York Times" displayed next to the title of the article. It would be exceedingly convenient if I could have this automatically generated.
Just getting the page title wouldn't work because that would usually give you the article title or, if you were to link to some other type of page, you might get some string like "How to retrieve website names? - Stack Overflow." I would only want to get the "Stack Overflow" part of that.
Any ideas?
You could try the application-name property:
<meta name="application-name" content="The New York Times" />
also
<meta name="application-name" content="CNN"/>
Not every site will have this but you can start here, check for open graph tags (http://ogp.me), etc.
You will need to parse the DOM tree using DOMDocument:
<?php
function GetTitle($url)
{
$dom = new DOMDocument;
#$dom->loadHTMLFile($url); // # supresses warnings
// try to get meta application-name
foreach ($dom->getElementsByTagName("meta") as $meta)
{
$metaName = $meta->attributes->getNamedItem("name");
if (strtolower($metaName->nodeValue) == "application-name")
{
$metaContent = $meta->attributes->getNamedItem("content");
if ($metaContent != NULL)
return $metaContent->nodeValue;
}
}
// title fallback:
foreach ($dom->getElementsByTagName("title") as $title)
return $title->nodeValue;
return NULL;
}
print(GetTitle("http://www.nytimes.com/"));
?>
First, GetTitle() looks for a <meta name="application-name"> tag. If not found, it will fallback and return the page title instead.
Additionally, you should pass the base url. F.e. if you have this url: http://stackoverflow.com/questions/16185145/how-to-retrieve-website-names/16185654#16185654, you should strip everything except http://stackoverflow.com using parse_url:
$parsedUrl = parse_url($url);
GetTitle($parsedUrl["scheme"] + "://" + $parsedUrl["host"]);
If you want to parse the url, you could try this function:
$parsedUrl = parse_url($url);
$host = $parsedUrl['host']
echo $host;
This will give you an associative array where the host key is what you are looking for.
See: http://php.net/manual/en/function.parse-url.php
What you call 'Site name' is not a part of the link, it is part of the HTML code returned by that link.
If you want to get the site title, you should retrieve the link content using CURL and then parse the returned HTML to get the content of the tag in the section.
Probably this will be expensier than the benefit you could get.
Recently youtube changed the way direct video download links work (found in url_encoded_fmt_stream_map), there is a signature now and links don't work unless the right signature is presented
the signature is there as a 'sig' argument so you can easy take it and construct the link and it will work, however ever since this signature appeared the link is also locked to the user's browser somehow
meaning if I probe "http://youtube.com/get_video_info" on the server side and construct the links with the signature and then print that as a link when the user clicks the link a black page will open, however if I try to download the video on the server side it will work.
This means that the link is somehow locked and belongs to the user who opened "http://youtube.com/get_video_info"
The problem with this situation is that in order to stream the videos you have to first download them on your server
Does anyone know how are the links locked to specific user and is there a way around it?
The idea is for example - you get the link on the server side and then you feed it to some flash player, instead of using the chromeless player
here is a code example with php:
<?
$video_id = $_GET['id']; //youtube video id
// geting the video info
$content = file_get_contents("http://youtube.com/get_video_info?video_id=".$video_id);
parse_str($content, $ytarr);
// getting the links
$links = explode(',',$ytarr['url_encoded_fmt_stream_map']);
// formats you would like to use
$formats = array(35,34,6,5);
//loop trough the links to find the one you need
foreach($links as $link){
parse_str($link, $args);
if(in_array($args['itag'],$formats)){
//right link found since the links are in hi-to-low quality order
//the match will be the one with highest quality
$video_url = $args['url'];
// add signature to the link
if($args['sig']){
$video_url .= '&signature='.$args['sig'];
}
/*
* What follows is three ways of proceeding with the link,
* note they are not supposed to work all together but one at a time
*/
//download the video and output to browser
#readfile($video_url); // this works fine
exit;
//show video as link
echo 'link for '.$args['itag'].''; //this won't work
exit;
//redirect to video
header("Location: $video_url"); // this won't work
exit;
}
}
?>
is any method to validate Youtube video link with Zend-framework ?
If user inputs not valid link, for example http://www.youtube.com/watch?00zzv=nel how can I check it before inserting into site ?
I'm pretty sure that there is no built in validator for this, but writing custom validators is super easy:
class My_Validate_Youtube extends Zend_Validate_Abstract{
public function isValid($value){
// check url here
if (no_good($value)){
$this->_error("Explain the error here");
return false;
}
return true;
}
}
Just put whatever checks you need in that class, and run the validator on any Youtube links to be checked.
edit:
From Laykes, you might want to consider using the validator to check if the video actually exists, instead of determining if it fits a pattern. Depends on your use cases though- eg how much latency do you want to introduce by making a call to the Youtube API?
I don't know if it is possible, however, I would take a different approach and try and see if the link has comments on it.
Take this for example. From here:
http://framework.zend.com/manual/en/zend.gdata.youtube.html
$yt = new Zend_Gdata_YouTube();
$commentFeed = $yt->getVideoCommentFeed('abc123813abc');
foreach ($commentFeed as $commentEntry) {
echo $commentEntry->title->text . "\n";
echo $commentEntry->content->text . "\n\n\n";
}
If you use the video id in the VideoCommentFeed argument, you will be able to get the value in $commentFeed. If you then get an error, you know that the video does not exist.
I am sure if you try other methods you will probably find example what you want.