Skip to content
This repository has been archived by the owner on Aug 27, 2022. It is now read-only.

Commit

Permalink
[MixcloudBridge] switch to using API (RSS-Bridge#2591)
Browse files Browse the repository at this point in the history
* switch to using public API

* switch to different API endpoints

* fix: urlencode username

Co-authored-by: Dag <me@dvikan.no>
  • Loading branch information
2 people authored and Kwbmm committed Jun 17, 2022
1 parent acf84b7 commit cca44c8
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions bridges/MixCloudBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class MixCloudBridge extends BridgeAbstract {
const MAINTAINER = 'Alexis CHEMEL';
const NAME = 'MixCloud';
const URI = 'https://www.mixcloud.com';
const API_URI = 'https://api.mixcloud.com/';
const CACHE_TIMEOUT = 3600; // 1h
const DESCRIPTION = 'Returns latest musics on user stream';

Expand All @@ -24,28 +25,37 @@ public function getName(){
return parent::getName();
}

public function collectData(){
$html = getSimpleHTMLDOM(self::URI . '/' . $this->getInput('u'));

foreach($html->find('section.card') as $element) {
private static function compareDate($stream1, $stream2) {
return (strtotime($stream1['timestamp']) < strtotime($stream2['timestamp']) ? 1 : -1);
}

$item = array();
public function collectData(){
$user = urlencode($this->getInput('u'));
// Get Cloudcasts
$mixcloudUri = self::API_URI . $user . '/cloudcasts/';
$content = getContents($mixcloudUri);
$casts = json_decode($content)->data;

$item['uri'] = self::URI . $element->find('hgroup.card-title h1 a', 0)->getAttribute('href');
$item['title'] = html_entity_decode(
$element->find('hgroup.card-title h1 a span', 0)->getAttribute('title'),
ENT_QUOTES
);
// Get Listens
$mixcloudUri = self::API_URI . $user . '/listens/';
$content = getContents($mixcloudUri);
$listens = json_decode($content)->data;

$image = $element->find('a.album-art img', 0);
$streams = array_merge($casts, $listens);

if($image) {
$item['content'] = '<img src="' . $image->getAttribute('src') . '" />';
}
foreach($streams as $stream) {
$item = array();

$item['author'] = trim($element->find('hgroup.card-title h2 a', 0)->innertext);
$item['uri'] = $stream->url;
$item['title'] = $stream->name;
$item['content'] = '<img src="' . $stream->pictures->thumbnail . '" />';
$item['author'] = $stream->user->name;
$item['timestamp'] = $stream->created_time;

$this->items[] = $item;
}

// Sort items by date
usort($this->items, array('MixCloudBridge', 'compareDate'));
}
}

0 comments on commit cca44c8

Please sign in to comment.