GitHost.io will be shut down on June 1, 2019. At that point this instance will be unreachable and all data will be irrevocably deleted. More details at https://about.gitlab.com/gitlab-hosted/#githost-is-shutting-down-on-june-1st-2019

Commit a9550917 authored by Rob Myers's avatar Rob Myers

Add simple user track rss 2.0.

parent e553cfaf
......@@ -2,7 +2,8 @@
"require": {
"adodb/adodb-php": "~5.19",
"smarty/smarty": "~3.1",
"smarty-gettext/smarty-gettext": "~1.1.1"
"smarty-gettext/smarty-gettext": "~1.1.1",
"suin/php-rss-writer": "^1.4"
},
"require-dev": {
"phpunit/phpunit": "~4.8"
......
......@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"hash": "d4b64c97f79aa2ab95e92b4cab22f0fc",
"hash": "d322038fc35e9d801a3651a209bf0cc1",
"packages": [
{
"name": "adodb/adodb-php",
......@@ -152,6 +152,50 @@
"templating"
],
"time": "2015-06-18 00:55:59"
},
{
"name": "suin/php-rss-writer",
"version": "1.4.0",
"source": {
"type": "git",
"url": "https://github.com/suin/php-rss-writer.git",
"reference": "a7dd2bbc287a05b266406d3afa298d44ebf115f3"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/suin/php-rss-writer/zipball/a7dd2bbc287a05b266406d3afa298d44ebf115f3",
"reference": "a7dd2bbc287a05b266406d3afa298d44ebf115f3",
"shasum": ""
},
"require": {
"php": ">=5.4.0"
},
"type": "library",
"autoload": {
"psr-0": {
"Suin\\RSSWriter": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Hidehito Nozawa aka Suin",
"email": "suinyeze@gmail.com"
}
],
"description": "Yet another simple RSS writer library for PHP 5.4 or later.",
"homepage": "https://github.com/suin/php-rss-writer",
"keywords": [
"feed",
"generator",
"php",
"rss",
"writer"
],
"time": "2016-03-19 06:15:37"
}
],
"packages-dev": [
......
<?php
/* GNU FM -- a free network service for sharing your music listening habits
Copyright (C) 2016 Free Software Foundation, Inc
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
require_once('../database.php');
require_once('../data/User.php');
require_once('../data/RemoteUser.php');
//require_once('../data/Server.php');
use Suin\RSSWriter\Channel;
use Suin\RSSWriter\Feed;
use Suin\RSSWriter\Item;
if (!isset($_GET['user'])) {
http_response_code(400);
echo "User not set.\n";
exit;
}
try {
if(strstr($_GET['user'], '@')) {
$user = new RemoteUser($_GET['user']);
} else {
$user = new User($_GET['user']);
}
} catch (Exception $e) {
http_response_code(400);
echo "User not found, shall I call in a missing persons report?\n";
exit;
}
if (isset($_GET['count'])) {
$scobbleCount = (int)$_GET['count'];
if ($scobbleCount >= 1200) {
$scrobbleCount = 1200;
}
} else {
$scrobbleCount = 100;
}
try {
$aUserScrobbles = $user->getScrobbles($scrobbleCount);
} catch (Exception $e) {
http_response_code(400);
echo "Couldn't get scrobbles.\n";
exit;
}
$feed = new Feed();
$channel = new Channel();
$channel
->title($user->name . '\'s recent tracks')
->description('RSS 2.0 Feed (Recent plays)')
->url($user->getURL())
->language('en')
->pubDate(time())
->ttl(60)
->appendTo($feed);
foreach ($aUserScrobbles as $scrobble) {
$item = new Item();
$item
->title($scrobble['track'])
->url($scrobble['trackurl'])
->pubDate($scrobble['time'])
->guid($scrobble['id'])
->description($scrobble['artisturl'])
->appendTo($channel);
}
echo $feed;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment