Creating a PHP page that shows an image via last.fm API - php

I'm trying to do a PHP page to shows an album cover via Last.FM API. However, the Artist Name and the Title of the music are provided by a XML file that a software updates via FTP.
Here is the code of Last.FM api:
<?php
$img = simplexml_load_file('http://ws.audioscrobbler.com/2.0/?method=track.getInfo&api_key=<APIKEY>&artist=cher&track=believe');
echo '<img src="';
echo $img->track[0]->album[0]->image[3];
echo '">';
?>
Now the link of my XML file is: http://summerblast.pt/avaplayer/rds.xml
The info I need to the Last.FM API is in 'OnAir/CurMusic'.
Well, what I am trying to do is change "Cher" and "Believe" (the artist's name and the Title's name) in the link of the "simplexml_load_file" (in the php code) with the info that my XML file provides.
Can you please help me doing this?
Thank you all in advance.

Sorry was confused to what you were asking from before. I have gone ahead and corrected to do what you wanted.
You can get the Artist and the Title from rds.xml and just pass it to the URL like the following listed below (note it is important to run urlencode on them since they can have spaces and other things to break the URL):
Updated to do error checking
$xml = simplexml_load_file('http://summerblast.pt/avaplayer/rds.xml');
$artist = urlencode($xml->OnAir->CurMusic->Artist);
$track = urlencode($xml->OnAir->CurMusic->Title);
$url = 'http://ws.audioscrobbler.com/2.0/?method=track.getInfo&api_key=XXXXXXXXXXXXXXXXXXXXXXXXXXX&artist='.$artist.'&track='.$track;
$xml2 = #simplexml_load_file($url);
if ($xml2 === false)
{
echo("Url failed"); // do whatever you want to do
}
else
{
if($xml2->track->album->image[3])
{
echo '<img src="';
echo((string) $xml2->track->album->image[3]);
echo '">';
}
else
{
echo("artist does not have a image"); // do whatever you want to do
}
}

Related

Cannot get description content using PHP Simple HTML DOM

I am trying to get all the description from this eBay url: https://www.ebay.com/itm/Front-strut-spacers-30mm-for-Ford-Focus2-C-Max-Focus3-Kuga-Escape-Lift-Kit/112460641185?epid=19025000547&hash=item1a2f2d33a1:g:0IYAAOSw1m9atFcz. Here is a screenshot:
The highlighted text is what I am trying to get using the div id: ds_div. However When I debug it it has no value. Here is my code:
$description = $html->find("div[id=ds_div]", 0);
var_dump($description);
if($description != null){
$item['description'] = $description->plaintext;
}else{
$item['description'] = '';
}
Try this May be this will helps to you,
foreach ( $html->find('td div#ds_div') as $element ) {
echo $element->plaintext . '<br>';
}
There actually is no element with id ds_div on that page, that's why your query returns nothing. There is however an iframe on that page that contains the element you're looking for. Get the URL of that iframe, parse/scrape the source of that and you should get your description.

How can i make this if else statement if the document uploaded it will check icon but if not it will have an x icon

I'm making my project and I have something that I don't understand. I want to make an if/else statement or anything that if all the document was uploaded in the database and no one missing it will have a check icon but if there were missing or no upload documents in the database it will have an x icon. The picture or link below is my database. The below code is the data I want to complete.
$vsoi = $row['soi'];
$vciv = $row['civ'];
$vpromo = $row['promo'];
$vassign = $row['assign'];
$vawards = $row['awards'];
$venlist = $row['enlist'];
$vlongpay = $row['longpay'];
$vfamily = $row['family'];
$vsaln = $row['saln'];
$vepem = $row['epem'];
This is the result I want to make.
If documents are complete.
and if not complete.
Thank you in advance!!!
I am not sure is this the solution that you are asking. Because you didn't post more information and the database structure. So I will post the answer as per my assumptions to give you an idea. I see in your database there are documents/ and also documents/CPLATEC.docx. So I assume documents/ as NOT UPLOADED and documents/CPLATEC.docx as UPLOADED and also the field type as VARCHAR. So based on that here is the answer,
I see a series of documents in the whole table but I will only get this soi as for the example.
<?php
$vsoi = $row['soi'];
$imageSrc = '';
if ($vsoi == 'documents/') {
$imageSrc = 'img_for_uploaded.png';
} else {
$imageSrc = 'img_for_not_uploaded.png';
}
?>
You have to place the following inside the table row right to the delete button.
<img src="<?php echo $imageSrc ; ?>" />
Or just place them inside the table row.
if ($vsoi == 'documents/') {
echo '<img src="img_for_uploaded.png" />'
} else {
echo '<img src="img_for_not_uploaded.png" />'
}
Hope this helps you.

Get and return media url (m3u8) using PHP

I have a website that hosts videos from a client. On the website the files load externally via m3u8 link.
The client would now like to have those videos on a Roku channel.
If I simply use the m3u8 link from the site it gives an error because the url generated is sent with a cookie and so a client must click and the link to generate a new code for them.
I would like if possible (and I have not seen this here) is to scrape the html page and just return the link via PHP script on the website from the Roku.
I know how to get titles and such using pure php but am having problems returning the m3u8 link..
I do have code to show I am not looking for handouts and actually am trying.
This is what I have used for getting the title name for example.
Note: I would like to know if it is possible to have one php that autofills the html page per url so I do not have to use a different php for each video with the url pretyped in.
<?php
$html = file_get_contents('http://example.com'); //get the html returned from the following url
$movie_doc = new DOMDocument();
libxml_use_internal_errors(TRUE); //disable libxml errors
if(!empty($html)){ //if any html is actually returned
$movie_doc->loadHTML($html);
libxml_clear_errors(); //remove errors for yucky html
$movie_xpath = new DOMXPath($movie_doc);
//get all the titles
$movie_row = $movie_xpath->query('//title');
if($movie_row->length > 0){
foreach($movie_row as $row){
echo $row->nodeValue . "<br/>";
}
}
}
?>
There is a simple approach for this, which involves using regex.
In this example let's say the video M3u8 file is located at: http://example.com/theVideoPage
You would point the video URL Source in your XML to your PHP file.
http://thisPhpFileLocation.com
<?php
$html = file_get_contents("http://example.com/theVideoPage");
preg_match_all(
'/(http.*m3u8)/',
$html,
$posts, // will contain the article data
PREG_SET_ORDER // formats data into an array of posts
);
foreach ($posts as $post) {
$link = $post[0];
header("Location: $link");
}
?>
Now if you want to use a URL that you can append a URL link at the end it could look something like this and you would use an address as such for a Video Url located at
http://thisPhpFileLocation.com?id=theVideoPage
<?php
$id = $_GET['id'];
$html = file_get_contents("http://example.com".$id);
preg_match_all(
'/(http.*m3u8)/',
$html,
$things, // will contain the article data
PREG_SET_ORDER // formats data into an array of posts
);
foreach ($things as $thing) {
$link = $thing[1];
// clear out the output buffer
while (ob_get_status())
{
ob_end_clean();
}
// no redirect
header("Location: $link");
}
?>

Open XML elements in PHP

Good, I created an XML document with the name and title of songs and artists within that document come also the corresponding cover. Now the link of my XML file is: http://inlivefm.96.lt/nw.xml .
I also have another XML document that gives me the name and artist title that this amounts to the moment (ADELE - HELLO) Now the link of my XML file is: http://inlivefm.96.lt/NowOnAir.xml .
Well, what I'm trying to make is that with document I created give me the cover of this song to give right now. I tried to make a code but to no avail in PHP, so I came to ask your help to get success.
Here I leave the code I am using to try to get what I want.
<?php
$xml = simplexml_load_file('http://inlivefm.6te.net/agora.xml');
$artist = urlencode($xml->Event->Song->Artist['name']);
$track = urlencode($xml->Event->Song['title']);
$url = simplexml_load_file("http://inlivefm.96.lt/nw.xml");
$largeImage = $url->xpath('/ilm/$artist- $track/image[#size="cover"]')[0];
echo '<img src="'.$largeImage.'" />';
?>
Can you please help me doing this?
Thank you all in advance.
correct xpath to take image is
(/ilm/artist/image[#size="cover"])[count(/ilm/artist/name[.="ADELE-HELLO"]/preceding-sibling::name)+1]
because you need to get image with the same position as artist's name.
In php code it should be something like this:
$XML = simplexml_load_file('http://inlivefm.6te.net/agora.xml');
$artist = $XML->Event->Song->Artist['name'];
$track = $XML->Event->Song['title'];
$URL = simplexml_load_file("http://inlivefm.96.lt/nw.xml");
$largeImage = $URL->xpath('(/ilm/artist/image[#size="cover"])[count(/ilm/artist/name[.="'. $artist .' - '. $track.'"]/preceding-sibling::name)+1]');
echo '<img src = "'. $largeImage[0]. '" />';

Get .mp4 source and poster image from Vine Id (PHP)

How to get video.mp4 from vine url?
Example:
from https://vine.co/v/hnVVW2uQ1Z9
I need http://.../*.mp4 and http://.../*.jpg
Script what I need use this page vinebed.com
(In PHP)
Thanks much.
It's very simple. if you check the source of a vine video from vine.co you'll see the meta tags. and you should see twitter:player:stream. By using php you can extract that information specifically and use it like a variable.
<?php
function vine( $id )
{
$vine = file_get_contents("http://vine.co/v/{$id}");
preg_match('/property="twitter:player:stream" content="(.*?)"/', $vine, $matches);
$url = $_SERVER['REQUEST_URI'];
return ($matches[1]) ? $matches[1] : false;
}
?>
And to set an $id you will need to create a function that will either A) Automatically read a vine video id by url and you can display it like this <?php echo vine('bv5ZeQjY35'); ?> or B) Just set a vine video id and display as is.
Hope this helps as it's worked for me just fine.

Categories