So, i would like to download youtube videos using a php script. I have googled a lot for now and there where more solutions but the one was using the http://youtube.com/get_video?data url but that is not possible now for a long time. I have found a greasemonkey script which works fine but i don't have a clue how could it work with php.
I have read that i must do something with the info which gives me for example this link:
http://www.youtube.com/get_video_info?video_id=g1SADcP5g1o
The question is what would be the best approach for this?
I would try to get some curl requests going on any of these resources and try to automate it that way.
I have it written in C++, not PHP. But it's not very simple yet not very complicated either. get_video_info output is URL encoded. Decode it and look for the stream_map set of streams. You'll notice a pattern in it. That's your starting point. Contains resolutions and download locations plus extras.
I wouldn't paste the PHP code here even if I had it :) They tend to change it...
Related
I use file_get_contents to find out if there is an URL of the search I look at:
http://www.google.com/search?q=*a*+site:www.reddit.com/r/+-inurl:(/shirt/|/related/|/domain/|/new/|/top/|/controversial/|/widget/|/buttons/|/about/|/duplicates/|dest=|/i18n)&num=1&sort=date-sdate
If I go to this URL in my browser, a different file is displayed then what I see when I echo file_get_contents
$url = "http://www.google.com/search?q=*a*+site:www.reddit.com/r/+-inurl:(/shirt/|/related/|/domain/|/new/|/top/|/controversial/|/widget/|/buttons/|/about/|/duplicates/|dest=|/i18n)&num=1&sort=date-sdate";
$google_search = file_get_contents($url);
What's wrong with my code?
Nothing really. The problem is that the page uses javascript and ajax to get contents. So, in order to get a "snapshot" of the page, you need to "run it". That is, you need to parse the javascript code, which php doesn't do.
Your best bet is to use an headless browser such as phantomjs. If you search, you find some tutorials explaining how to do it
NOTE
If all you're looking for is a way to retrieve raw data from the search, you might want to try to use google's search api.
I assume Google is definitely checking the user agent to avoid any kind of automated searches.
So you should at least use CURL and define a proper user agent string (i.e. the same as a common browser) to "trick" Google.
Somehow I fear it will not be so easy to trick Google, but maybe I'm just paranoic and at least you may learn something about CURL.
I'm fairly new to PHP because i'm an Android programmer but i need to convert a pdf file to html. I don't want to use any external API's because they are way to pricey. Now I would like to use http://www.convertpdftohtml.com to convert my pdf to html. However that site does not have any API and only works manually. According to Tomer W. it is possible to simulate a POST action for the website and doing it automatically. https://stackoverflow.com/questions/9592926/online-pdf-to-html-conversion-api
Now i'm wondering how i would be able to do this. (I don't have a lot of knowledge about PHP) but i know people who might help me to get it working (if i have some kind of pseudo code)
This may soon be unnecessary. Mozilla have incorporated pdf.js into Firefox 19
I have made a crazy (?) thought right now...
Is there any script written in PHP that gets a given keyword and returns a url of a relative image? (from google, yahoo, etc)
If so, may I have an example? And if not, hwo can this be made?
Thanks!!
You can use the Flicker API. phpFlickr seems to be an existing PHP library.
You can try the PHP's CURL functions to do that, just google it and read the PHP manual.
Try this one
Demo : http://www.scriptbaba.com/demos/get_images/
http://www.scriptbaba.com/details-php-image-search-api-25.html
I'm attempting to put together a little mashup with some twitter APIs. However, the whole area is new to me (I'm more of an embedded developer dabbling). And frustratingly, every tutorial I am trying in Php is either out of date, not doing what it claims to do, it or is broken.
Essentially, I just want a nice bit of example code - say, an HTML file, a connection.js for the JQuery magic, and a php file - 'getsearch' which contains the relevant Curl calls to the API to just return the results for a given search term.
Followed the tutorial to the letter at
http://www.reynoldsftw.com/2009/02/using-jquery-php-ajax-with-the-twitter-api/
and even downloaded the guy's code and chucked it on my webserver, but it just seems to sit there.
I'm relatively competent at php and html, but it's the Curl and the JQuery side of things which is new to me, and would appreciate any thoughts, links, or code suggestions. I've attempted reading the API - but even that seems sparse - and several links are broken to their own tutorials, so that's put me off a bit for now.
Finally found a working one.
http://papermashup.com/using-the-twitter-api/
This tutorial (or just the php file at http://greenservr.com/projects/twittersearch/TwitterSearch.phps) has the basics including php, jquery and curl to get something back from the twitter API). Finally have something going, so now can expand and extend :)
check the link http://webhkp.wordpress.com/2010/04/13/twitter-api-search-follow-tweet/. this is a great post i found and really helpful for me. hope you fined something helpful here.
Pse forgive what is most likely a stupid question. I've successfully managed to follow the simplehtmldom examples and get data that I want off one webpage.
I want to be able to set the function to go through all html pages in a directory and extract the data. I've googled and googled but now I'm confused as I had in my ignorant state thought I could (in some way) use PHP to form an array of the filenames in the directory but I'm struggling with this.
Also it seems that a lot of the examples I've seen are using curl. Please can someone tell me how it should be done. THere are a significant number of files. I've tried concatenating them but this only works with doing this through an html editor - using cat -> doesn't work.
You probably want to use glob('some/directory/*.html'); (manual page) to get a list of all the files as an array. Then iterate over that and use the DOM stuff for each filename.
You only need curl if you're pulling the HTML from another web server, if these are stored on your web server you want glob().
Assuming the parser you talk about is working ok, you should build a simple www-spider. Look at all the links in a webpage and build a list of "links-to-scan". And scan each of those pages...
You should take care of circular references though.