Jump to content
php.lv forumi
ziedinjsh

soundcloud playeris

Recommended Posts

Besī.. esmu nogooglējies līks bet nevaru atrast ejošu preg_match funkciju kas souncloud linku pārvērš playerī.. varbūt kāds māk uztaisīt?

 

piem šāds ir links ko iepostē:http://soundcloud.co...kmylife/untrust

un šāds ir playera kods: <iframe width="100%" height="166" scrolling="no" frameborder="no" src="http://w.soundcloud.com/player/?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F55492490&show_artwork=true"></iframe>

 

Šitā neiet:

 

$matches = array(

'#(?:https?://).soundcloud\.com/([\-a-z0-9_]+/[\-a-z0-9_]+)#siU'

);

 

$replacements = array(

 

'<object height="81" width="100%"><param name="movie" value="http://player.soundcloud.com/player.swf?url=$1&g=bb"></param><param'>http://player.soundcloud.com/player.swf?url=$1&g=bb"></param><param name="allowscriptaccess" value="always"></param><embed allowscriptaccess="always" height="81" src="http://player.soundcloud.com/player.swf?url=$1&g=bb" type="application/x-shockwave-flash" width="100%"></embed></object> <a href="$1">$1</a>'

);

Edited by ziedinjsh

Share this post


Link to post
Share on other sites

tur ar regexp nav nekāds sakars.

no iekopētā linkasatura jāizparsē track id un tad tu vari to html uzģenerēt.

Share this post


Link to post
Share on other sites

nu pieņemsim, ka paņem nosaukumu, izpildītāju, bet kur tu to tālāk bāzīsi? embedojamajā kodā to nevajag (es par to iframe runāju).

 

jebkurā gadījumā regexp pārmudrīts

soundcloud\.com/(.+)

Share this post


Link to post
Share on other sites

tā, es neiebraucu, kā tad man jāizskatās ir šim:

<?php
$text = 'http://soundcloud.com/fuckmylife/untrust';
function media_check($status_text)
{
   	$matches = array(
'#(?:https?://).soundcloud\.com/([\-a-z0-9_]+/[\-a-z0-9_]+)#siU'
   	);

   	$replacements = array(
'<object height="81" width="100%"> <param name="movie" value="$1api.soundcloud.com%2Ftracks%2F55492490"></param> <param name="allowscriptaccess" value="always"></param> <embed allowscriptaccess="always" height="81" src="https://player.soundcloud.com/player.swf?url=$1api.soundcloud.com%2Ftracks%2F55492490" type="application/x-shockwave-flash" width="100%"></embed> </object>  <span><a href="$1">Untrust</a> by <a href="$1">fuckmylife</a></span> '
   	);

$status_text = preg_replace($matches, $replacements, $status_text);

 return $status_text;
}

echo media_check($text);
?>

Share this post


Link to post
Share on other sites

šādi:

%(?:https?://)(?:www\.)?soundcloud\.com/([\-a-z0-9_]+/[\-a-z0-9_]+)%im

<object height="81" width="100%"><param name="movie" value="http://player.soundcloud.com/player.swf?url=$1&g=bb"></param><param'>http://player.soundcloud.com/player.swf?url=$1&g=bb"></param><param name="allowscriptaccess" value="always"></param><embed allowscriptaccess="always" height="81" src="http://player.soundcloud.com/player.swf?url=$1&g=bb" type="application/x-shockwave-flash" width="100%"></embed></object>

 

man parādās plejeris, bet nav iekšā dziesma.. nav pilnīgs links :?

Share this post


Link to post
Share on other sites

Tu rakstīji, ka tev ir adrese uz dziesmu @sc. Droši vien, ka tu to vari realizēt izmantojot kādu ajax pieprasījumu ar jsonp. Parametros padod url un atpakaļ tev iedos to jsonu, kur viens no parametriem ir "iframe", kas arī ir tas kods, kuru tu gribi.

 

EDIT.

ņemu savus vārdus atpakaļ. Drusku muļķības sarakstīju. Viens no variantiem - tu vari izmantot http://oembed.com/ .

Edited by Pats Toms

Share this post


Link to post
Share on other sites

Šī būs gara diskusija.

Share this post


Link to post
Share on other sites

un kā es viņu varu inklūdot savā kodā?

varētu jau pateikt kko rupju tev.... vnk brutāli iespraud viņu sev.... ;)

Share this post


Link to post
Share on other sites

<?php

function cloud($link){
?>
<head>
<script type='text/javascript' src='http://code.jquery.com/jquery-1.8.0.min.js'></script>
<script type='text/javascript'>
$(window).load(function(){
var url="<?php echo $link; ?>";
$.ajax({
   	type: "GET"
   	,dataType: "json"
   	,data: {
       	jsonp : "output"
       	,url: url
       	,format: "json"
       	,iframe: "true"           
   	}
   	,url : "http://soundcloud.com/oembed"
   	,success:
       	function(data) {
          	$('#player').html(data.html);
       	}                               
});
});
</script>
</head>
<div id="player"></div>
<?php
}

function media_check($status_text){
$matches = array(
'/((https?|ftp).*(gif|png|jpg|jpeg))/i',
'%<a(.*)(?:href="https?://)?(?:www\.)?(?:youtu\.be/|youtube\.com(?:/embed/|/v/|/watch\?v= ))([\w\-]{10,12})(?:)([\w\-]{0})\b%x',
'%(?:https?://)(?:www\.)?soundcloud\.com/([\-a-z0-9_]+/[\-a-z0-9_]+)%im',
   	);

$replacements = array(
'<a href="$1" target="_blank"><img src="$1" style="width:400px;"/></a>',
'<iframe style="width:500px;height:300px;border:0;" src="http://www.youtube-nocookie.com/embed/$2"></iframe>',
cloud('http://soundcloud.com/$1')
);

$status_text = preg_replace($matches, $replacements, $status_text);

 return $status_text;
}
?>

Neiet, jo url parādās kā http://soundcloud.com/$1 iekš cloud('') nestrādā $1;

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...