[cc-commits] [CC SVN] r14284 - in cchost/trunk: cchost_lib mixter-lib
webmaster at creativecommons.org
webmaster at creativecommons.org
Tue Mar 30 16:24:46 EDT 2010
Author: fourstones
Date: 2010-03-30 20:24:46 +0000 (Tue, 30 Mar 2010)
New Revision: 14284
Added:
cchost/trunk/mixter-lib/mixter-jamendo.inc
Modified:
cchost/trunk/cchost_lib/cc-feedreader.php
cchost/trunk/cchost_lib/cc-pools.php
Log:
we parse xspf for remote sample (hack!)
jamendo pool wrapper
Modified: cchost/trunk/cchost_lib/cc-feedreader.php
===================================================================
--- cchost/trunk/cchost_lib/cc-feedreader.php 2010-03-30 20:16:23 UTC (rev 14283)
+++ cchost/trunk/cchost_lib/cc-feedreader.php 2010-03-30 20:24:46 UTC (rev 14284)
@@ -319,6 +319,7 @@
'description' => '' );
$ccFR->is_atom = false;
$ccFR->is_rss = false;
+ $ccFR->is_xspf = false;
$ccFR->waiting_for = null;
$ccFR->wait_for_special = null;
@@ -338,7 +339,11 @@
$I['category'] = join(', ',$I['tags']);
unset($I['tags']);
+ if( !empty($ccFR->search_title) )
+ $I['search_title'] = 1;
+
if( !isset($I['artist']) ) $I['artist'] = '';
+ if( !isset($I['enclosure']) ) $I['enclosure'] = array();
if( !isset($I['enclosure']['url']) ) $I['enclosure']['url'] = '';
if( !isset($I['enclosure']['length']) ) $I['enclosure']['length'] = '';
if( !isset($I['enclosure']['type']) ) $I['enclosure']['type'] = '';
@@ -358,7 +363,7 @@
global $ccFR;
$name = strtolower($name);
-
+
/* ATOM:
author category content
entry feed id
@@ -373,6 +378,12 @@
pubDate rss title
*/
+ /* XSPF
+ track location creator
+ album title duration
+ image info meta (rel=license)
+ */
+
switch($name)
{
case 'feed':
@@ -383,12 +394,19 @@
$ccFR->is_rss = true;
break;
+ case 'playlist':
+ $ccFR->is_xspf = true;
+ $ccFR->search_title = true;
+ break;
+
case 'item':
case 'entry':
+ case 'track':
$ccFR->current_item = array();
break;
case 'name':
+ case 'creator':
case 'dc:creator':
case 'dc:author': // early ccHosts spit this
$ccFR->waiting_for = 'artist';
@@ -399,6 +417,10 @@
$ccFR->waiting_for = 'guid';
break;
+ case 'location':
+ $ccFR->waiting_for_special = 'location';
+ break;
+
case 'category':
if( $ccFR->is_atom )
$ccFR->current_item['tags'][] = $attribs['term'];
@@ -415,6 +437,8 @@
$ccFR->waiting_for = 'encoded_description';
break;
+ case 'meta':
+ case 'info':
case 'link':
$this->wait_for_link($attribs);
break;
@@ -458,6 +482,9 @@
{
switch( $attribs['rel'] )
{
+ case 'http://web.resource.org/cc/license':
+ $ccFR->waiting_for = 'license_url';
+ break;
case 'license':
$ccFR->current_item['license_url'] = $attribs['href'];
break;
@@ -488,6 +515,7 @@
{
case 'item':
case 'entry':
+ case 'track':
$ccFR->items[] = $ccFR->current_item;
unset($ccFR->current_item);
break;
@@ -521,6 +549,12 @@
case 'tag':
$ccFR->current_item['tags'][] = $data;
return;
+
+ case 'location':
+ preg_match('/=([a-f0-9]+)$/',$data,$m);
+ $ccFR->current_item['guid'] = $m[1];
+ $ccFR->current_item['enclosure'] = array( 'url' => $data );
+ return;
}
}
Modified: cchost/trunk/cchost_lib/cc-pools.php
===================================================================
--- cchost/trunk/cchost_lib/cc-pools.php 2010-03-30 20:16:23 UTC (rev 14283)
+++ cchost/trunk/cchost_lib/cc-pools.php 2010-03-30 20:24:46 UTC (rev 14284)
@@ -172,6 +172,8 @@
// table even if the use doesn't pick them just to have them
// around.
+ //d($pool_results);
+
$pools =& CCPools::GetTable();
$pool = $pools->QueryKeyRow($pool_id);
@@ -214,20 +216,9 @@
{
require_once('cchost_lib/cc-api.php');
$query_url = CCRestAPI::MakeUrl( $api_url, 'search', 'query=' . $query );
- $fr = new CCFeedReader();
- $rss = $fr->cc_parse_url( $query_url );
- if( !empty($rss->ERROR) )
- {
- CCDebug::Log("Feed read error on $query_url: " . $rss->ERROR);
- return(false);
- }
-
- if( empty($rss->channel) )
- {
- CCDebug::Log("Feed read error on $query_url: Can't find channel info");
- return(false);
- }
- $retval = array( 'rss', $rss->items );
+ $retval = $this->_dig_out_rssitems($query_url,null);
+ if( $retval === false )
+ return false;
}
else
{
@@ -236,12 +227,49 @@
require_once($parts[1]);
$api_url = $parts[0];
$obj = new $api_url();
- $retval = array( 'pool_items', $obj->LocalSearch($pool_id,$query,$type) );
+ $data = $obj->LocalSearch($pool_id,$query,$type);
+ if( is_string($data) )
+ {
+ $retval = $this->_dig_out_rssitems(null,$data);
+ if( $retval === false )
+ return false;
+ }
+ else
+ {
+ $retval = array( 'pool_items', $data );
+ }
}
return( $retval );
}
+ function _dig_out_rssitems($url,$data)
+ {
+
+ $fr = new CCFeedReader();
+ if( empty($url) )
+ {
+ $rss = $fr->parse($data);
+ }
+ else
+ {
+ $rss = $fr->cc_parse_url( $url );
+ }
+ if( !empty($rss->ERROR) )
+ {
+ CCDebug::Log("Feed read error on $url: " . $rss->ERROR);
+ return(false);
+ }
+
+ if( empty($rss->channel) )
+ {
+ CCDebug::Log("Feed read error on $url: Can't find channel info");
+ return(false);
+ }
+ $retval = array( 'rss', $rss->items );
+ return $retval;
+ }
+
function NotifyPoolsOfRemix($pool_items, $remixguid)
{
// todo: test and enable this code
@@ -372,6 +400,8 @@
$link = $item['link'];
$where['pool_item_url'] = $link;
$where['pool_item_timestamp'] = $item['date_timestamp'];
+ if( !empty($item['search_title']) )
+ $where['pool_item_name'] = $item['title'];
$row = $pool_items->QueryRow($where);
if( !empty($row) )
@@ -396,7 +426,7 @@
$args['pool_item_id'] = $pool_items->NextID();
$args['pool_item_pool'] = $pool['pool_id'];
$args['pool_item_url'] = $link;
- $args['pool_item_download_url'] = empty($item['enclosure']) ? '' : $item['enclosure']['url'];
+ $args['pool_item_download_url'] = empty($item['enclosure']['url']) ? '' : $item['enclosure']['url'];
$args['pool_item_license'] = $license;
$args['pool_item_name'] = $item['title'];
$args['pool_item_artist'] = $item['artist'];
@@ -405,8 +435,8 @@
$args['pool_item_timestamp'] = $item['date_timestamp'];
$extra = array( 'guid' => $item['guid'],
- 'length' => empty($item['enclosure']) ? '' : $item['enclosure']['length'],
- 'type' => empty($item['enclosure']) ? '' : $item['enclosure']['type'],
+ 'length' => empty($item['enclosure']['length']) ? '' : $item['enclosure']['length'],
+ 'type' => empty($item['enclosure']['type']) ? '' : $item['enclosure']['type'],
'tags' => empty($item['category']) ? '' : $item['category'] );
$args['pool_item_extra'] = serialize($extra);
Added: cchost/trunk/mixter-lib/mixter-jamendo.inc
===================================================================
--- cchost/trunk/mixter-lib/mixter-jamendo.inc (rev 0)
+++ cchost/trunk/mixter-lib/mixter-jamendo.inc 2010-03-30 20:24:46 UTC (rev 14284)
@@ -0,0 +1,46 @@
+<?
+/*
+* Creative Commons has made the contents of this file
+* available under a CC-GNU-GPL license:
+*
+* http://creativecommons.org/licenses/GPL/2.0/
+*
+* A copy of the full license can be found as part of this
+* distribution in the file LICENSE.TXT.
+*
+* You may use the ccHost software in accordance with the
+* terms of that license. You agree that you are solely
+* responsible for your use of the ccHost software and you
+* represent and warrant to Creative Commons that your use
+* of the ccHost software will comply with the CC-GNU-GPL.
+*
+* $Id$
+*
+*/
+
+if( !defined('IN_CC_HOST') )
+ die('Welcome to CC Host');
+
+require_once('cchost_lib/cc-pool-generic.php');
+
+class CCJamendoPool extends CCPoolGeneric
+{
+ function LocalSearch($pool_id,$text,$type)
+ {
+ global $CC_GLOBALS;
+
+ $text = CCUtil::StripText( urldecode($text) );
+ if( empty($text) )
+ return( array() );
+
+ $url = "http://api.jamendo.com/get2/id+stream/track/xspf/?searchquery=" . urlencode($text);
+
+ require_once('cchost_lib/snoopy/Snoopy.class.php');
+ $snoopy = new Snoopy();
+ $ok = @$snoopy->fetch($url);
+ return $ok ? str_replace('><',">\n<",$snoopy->results) : array();
+ }
+
+}
+
+?>
\ No newline at end of file
More information about the cc-commits
mailing list