We are no longer offering accounts on this server. Consider https://gitlab.freedesktop.org/ as a place to host projects.

Commit e253711c authored by Mike Sheldon's avatar Mike Sheldon

Add basic ability to add new tracks to albums, link them to archive.org files...

Add basic ability to add new tracks to albums, link them to archive.org files and pull in license details from archive.org
parent 09d4379f
......@@ -9,6 +9,7 @@ RewriteRule ^user/([^/]+)/stats/?$ user-stats.php?u
RewriteRule ^user/([^/]+)/station/?$ user-station.php?user=$1 [B,NC,QSA]
RewriteRule ^user/([^/]+)/recommended/?$ user-recommended.php?user=$1 [B,NC]
RewriteRule ^artist/([^/]+)/track/([^/]+)/?$ track.php?artist=$1&track=$2 [B,NC]
RewriteRule ^artist/([^/]+)/album/([^/]+)/track/add/?$ track-add.php?artist=$1&album=$2 [B,NC]
RewriteRule ^artist/([^/]+)/album/([^/]+)/track/([^/]+)/?$ track.php?artist=$1&album=$2&track=$3 [B,NC]
RewriteRule ^artist/([^/]+)/album/add/?$ album-add.php?artist=$1 [B,NC]
RewriteRule ^artist/([^/]+)/album/([^/]+)/?$ album.php?artist=$1&album=$2 [B,NC]
......
......@@ -37,6 +37,10 @@ if ($aAlbumTracks) {
$smarty->assign('tracks', $aAlbumTracks);
}
if(isset($this_user) && $this_user->manages($artist->name)) {
$smarty->assign('add_track_link', $album->getAddTrackURL());
}
$smarty->assign('extra_head_links', array(
array(
'rel' => 'meta',
......
......@@ -61,11 +61,9 @@ class Album {
$this->id = identifierAlbum(null, $this->artist_name, null, $this->name, null, null, null, $this->mbid);
// this hack brought to you by mattl
//if ($row['image'] == ''){
//go_get_album_art($this->artist_name, $this->name);
//}
// mattl hack ovar
$this->track_query = 'SELECT name, artist_name FROM Track WHERE artist_name = '
. $adodb->qstr($this->artist_name) . ' AND album_name = '
. $adodb->qstr($this->name);
if($this->image == '') {
$this->image = false;
......@@ -96,6 +94,14 @@ class Album {
return new Album($name, $artist_name);
}
/**
* Clears the track cache
*/
function clearTrackCache() {
global $adodb;
$adodb->CacheFlush($this->track_query);
}
function getPlayCount() {
global $adodb;
$adodb->SetFetchMode(ADODB_FETCH_ASSOC);
......@@ -125,9 +131,7 @@ class Album {
function getTracks() {
global $adodb;
$adodb->SetFetchMode(ADODB_FETCH_ASSOC);
$res = $adodb->CacheGetAll(600, 'SELECT name, artist_name FROM Track WHERE artist_name = '
. $adodb->qstr($this->artist_name) . ' AND album_name = '
. $adodb->qstr($this->name));
$res = $adodb->CacheGetAll(600, $this->track_query);
foreach($res as &$row) {
$tracks[] = new Track($row['name'], $row['artist_name']);
}
......@@ -144,6 +148,15 @@ class Album {
return Server::getAlbumURL($this->artist_name, $this->name);
}
/**
* Gives the URL for managers to add a new track to this album
*
* @return A string containing the URL for adding tracks to this album
*/
function getAddTrackURL() {
return Server::getAddTrackURL($this->artist_name, $this->name);
}
/**
* Get an albums's most used tags
*
......
......@@ -342,7 +342,7 @@ class Server {
static function getArtistManagementURL($artist) {
global $friendly_urls, $base_url;
if($friendly_urls) {
return Server::getArtistURL($artist) . "/manage";
return Server::getArtistURL($artist) . '/manage';
} else {
return $base_url . '/artist-manage.php?artist=' . urlencode($artist);
}
......@@ -351,7 +351,7 @@ class Server {
static function getAddAlbumURL($artist) {
global $friendly_urls, $base_url;
if($friendly_urls) {
return Server::getArtistURL($artist) . "/album/add";
return Server::getArtistURL($artist) . '/album/add';
} else {
return $base_url . '/album-add.php?artist=' . urlencode($artist);
}
......@@ -365,6 +365,16 @@ class Server {
return $base_url . '/album.php?artist=' . urlencode($artist) . '&album=' . urlencode($album);
}
}
static function getAddTrackURL($artist, $album) {
global $friendly_urls, $base_url;
if($friendly_urls) {
return Server::getAlbumURL($artist, $album) . '/track/add';
} else {
return $base_url . '/track-add.php?artist=' . urlencode($artist) . '&album=' . urlencode($album);
}
}
static function getTrackURL($artist, $album, $track) {
global $friendly_urls, $base_url;
......
......@@ -72,6 +72,35 @@ class Track {
}
/**
* Add a new track to the database.
*
* @param string $name
* @param string $artist_name
* @param string $album_name
* @param string $streaming_url
* @param string $download_url
* @param string $license
* @return A newly created track object
*/
public static function create($name, $artist_name, $album_name, $streamurl, $downloadurl, $license) {
global $adodb;
$adodb->Execute('INSERT INTO Track (name, artist_name, album_name, streamurl, downloadurl, license, streamable) VALUES ('
. $adodb->qstr($name) . ', '
. $adodb->qstr($artist_name) . ', '
. $adodb->qstr($album_name) . ', '
. $adodb->qstr($streamurl) . ', '
. $adodb->qstr($downloadurl) . ', '
. $adodb->qstr($license) . ', '
. '1' . ')');
$album = new Album($album_name, $artist_name);
$album->clearTrackCache();
return new Track($name, $artist_name);
}
/**
* Sets the playcount
*
......
<?php
/* GNU FM -- a free network service for sharing your music listening habits
Copyright (C) 2009 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('templating.php');
require_once('data/Album.php');
require_once('data/Track.php');
require_once('utils/licenses.php');
$artist = new Artist(urldecode($_GET['artist']));
$album = new Album(urldecode($_GET['album']), $artist->name);
$smarty->assign('artist', $artist);
$smarty->assign('pageheading', '<a href="' . $artist->getURL() . '">' . $artist->name . '</a> &mdash; Add Track');
if (isset($_POST['submit'])) {
if (empty($_POST['name'])) {
$errors[] = 'A track name must be specified.';
}
$name = $_POST['name'];
if (empty($_POST['streaming_url'])) {
$errors[] = 'A streaming URL must be specified.';
}
$streaming_url = $_POST['streaming_url'];
if (substr($streaming_url, 0, 7) != 'http://') {
$streaming_url = 'http://' . $streaming_url;
}
if (!preg_match('/http:\/\/(www.)?archive.org\/download\/([^\/]*)\/.*/', $streaming_url, $matches)) {
$errors[] = 'The streaming URL must be hosted at archive.org. Make sure you aren\'t linking to a mirror location (URL should begin with http://www.archive.org/...).';
} else {
// Check we've been given correct file types
$finfo = new finfo(FILEINFO_MIME_TYPE);
$type = $finfo->buffer(file_get_contents($streaming_url, false, null, -1, 12));
if($type != 'application/ogg') {
$errors[] = 'File must be in Ogg Vorbis format.';
}
// Check the license
$archive_name = $matches[2];
$meta_url = 'http://www.archive.org/download/' . $archive_name . '/' . $archive_name . '_meta.xml';
try {
$meta = simplexml_load_file($meta_url);
$license = $meta->licenseurl;
if(!is_free_license($license)) {
$errors[] = 'Sorry, we don\'t recognise the license that this item is under as being free enough. We currently support CC-0, CC-BY, CC-BY-SA and Art Libre, if you think we should add this license please get in touch.';
}
} catch (exception $e) {
$errors[] = 'This doesn\'t appear to be a valid archive.org item.';
}
}
if($errors) {
$smarty->assign('errors', $errors);
$smarty->assign('image', $image);
$smarty->assign('name', $name);
$smarty->assign('streaming_url', $streaming_url);
} else {
// If the creation was successful send the user back to the view page
$track = Track::create($name, $artist->name, $album->name, $streaming_url, $streaming_url, $license);
header('Location: ' . $track->getURL());
}
}
$smarty->display('track-add.tpl');
?>
......@@ -39,3 +39,23 @@ function simplify_license($license) {
return 0;
}
/**
* Returns true if the supplied license is one that we accept as being free
*
* @param $license string containing a license URL
* @return bool whether this license is free or not
*/
function is_free_license($license) {
global $licenses;
foreach ($licenses as $key => $l) {
foreach ($l as $urlschema) {
if (ereg($urlschema, $license)) {
return true;
}
}
}
return false;
}
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