From 0949ff48904b06438fc4215854d7fa3ba884474e Mon Sep 17 00:00:00 2001 From: Karl 'vollmerk' Vollmer Date: Mon, 6 Aug 2007 07:23:42 +0000 Subject: fixed find missing tracks, tweaked openstrands class again to account for lack of [[CCDATA tag on some xml responses --- docs/CHANGELOG | 1 + lib/class/album.class.php | 41 ++++++++++++++++++++++++++++++-- lib/class/metadata.class.php | 42 +++++++++++++++++++++++++++++++++ modules/infotools/openstrands.class.php | 8 ++++--- server/stats.ajax.php | 24 +++++++++++++++++++ templates/show_album.inc.php | 13 ++++++---- templates/show_objects.inc.php | 7 ++++++ 7 files changed, 127 insertions(+), 9 deletions(-) diff --git a/docs/CHANGELOG b/docs/CHANGELOG index cd3abbd6..a9edae7a 100755 --- a/docs/CHANGELOG +++ b/docs/CHANGELOG @@ -4,6 +4,7 @@ -------------------------------------------------------------------------- v.3.4-Alpha2 + - Added Find Missing tracks, requires MyStrands - Added ability to show Album art on Browse -> Albums - Added Similar Artists Link, requires MyStrands - Fixed hovering on the static Ratings displays diff --git a/lib/class/album.class.php b/lib/class/album.class.php index b72633e3..b47e6b03 100644 --- a/lib/class/album.class.php +++ b/lib/class/album.class.php @@ -29,6 +29,7 @@ class Album { /* Variables from DB */ public $id; public $name; + public $full_name; // Prefix + Name, genereated by format(); public $year; public $prefix; @@ -48,7 +49,7 @@ class Album { * pull the album or thumb art by default or * get any of the counts. */ - function __construct($album_id = 0) { + public function __construct($album_id='') { if (!$album_id) { return false; } @@ -64,12 +65,31 @@ class Album { } // Little bit of formating here - $this->f_name = trim($info['prefix'] . ' ' . $info['name']); + $this->full_name = trim($info['prefix'] . ' ' . $info['name']); return true; } //constructor + /** + * construct_from_array + * This is often used by the metadata class, it fills out an album object from a + * named array, _fake is set to true + */ + public static function construct_from_array($data) { + + $album = new Album(0); + foreach ($data as $key=>$value) { + $album->$key = $value; + } + + // Make sure that we tell em it's fake + $album->_fake = true; + + return $album; + + } // construct_from_array + /** * _get_info * This is a private function that pulls the album @@ -156,6 +176,23 @@ class Album { } // has_art + /** + * has_track + * This checks to see if this album has a track of the specified title + */ + public function has_track($title) { + + $title = Dba::escape($title); + + $sql = "SELECT `id` FROM `song` WHERE `album`='$this->id' AND `title`='$title'"; + $db_results = Dba::query($sql); + + $data = Dba::fetch_assoc($db_results); + + return $data; + + } // has_track + /** * format * This is the format function for this object. It sets cleaned up diff --git a/lib/class/metadata.class.php b/lib/class/metadata.class.php index 30a34f4b..8f5abf2b 100644 --- a/lib/class/metadata.class.php +++ b/lib/class/metadata.class.php @@ -85,6 +85,48 @@ class metadata { } // recommend_similar + /** + * find_missing_tracks + * This returns an array of song objects using the construct_from_array() that are + * not in the specified album. + */ + public static function find_missing_tracks($album_id) { + + // Build our object + $album = new Album($album_id); + $objects = array(); + + // For now it's only mystrands + OpenStrands::set_auth_token(Config::get('mystrands_developer_key')); + $openstrands = new OpenStrands($GLOBALS['user']->prefs['mystrands_user'],$GLOBALS['user']->prefs['mystrands_pass']); + + if (!$openstrands) { return false; } + + // First find the album on mystrands + $result = $openstrands->search_albums($album->full_name,'1'); + + $mystrands_id = $result['0']['__attributes']['AlbumId']; + + if (!$mystrands_id) { return false; } + + $tracks = $openstrands->lookup_album_tracks($mystrands_id); + + // Recurse the data we've found and check the local album + foreach ($tracks as $track) { + if (!$album->has_track($track['TrackName'])) { + $data['title'] = $track['TrackName']; + $data['track'] = $track['TrackNumber']; + $data['disc'] = $track['DiscNumber']; + $data['artist'] = $track['ArtistName']; + $data['links'] = "" . get_user_icon('world_link','MyStrands') . ""; + $objects[] = Album::construct_from_array($data); + } + } // end foreach + + return $objects; + + } // find_missing_tracks + } // metadata ?> diff --git a/modules/infotools/openstrands.class.php b/modules/infotools/openstrands.class.php index 51b4dee0..2e4b54da 100644 --- a/modules/infotools/openstrands.class.php +++ b/modules/infotools/openstrands.class.php @@ -66,11 +66,13 @@ class openStrands { */ public function __construct($username,$password) { + // Check to see if we've already authenticated + if (self::$authenticated) { return true; } + if (!self::$auth_token) { echo 'No Auth Token, quiting'; return false; } + // Trust them enough to let them try once self::$authenticated = true; - if (!self::$auth_token) { echo 'No Auth Token, quiting'; return false; } - // Test login with the provided credientials $auth_data = $this->user_validate($username,$password); @@ -596,7 +598,7 @@ class openStrands { $tag = $this->_currentTag; if (strlen($tag) AND $this->_key >= 0) { - $this->results[$this->_key][$tag] = trim($cdata); + $this->results[$this->_key][$tag] .= trim($cdata); } diff --git a/server/stats.ajax.php b/server/stats.ajax.php index 5054ce03..1ca6391b 100644 --- a/server/stats.ajax.php +++ b/server/stats.ajax.php @@ -69,6 +69,30 @@ switch ($_REQUEST['action']) { $results['additional_information'] = ob_get_contents(); ob_end_clean(); break; + case 'show_check_album_tracks': + ob_start(); + show_box_top(_('Find Missing Tracks')); + echo "Loading..."; + $ajax_action = Ajax::action('?page=stats&action=check_album_tracks&id=' . $_REQUEST['id'],'show_album_tracks_refresh'); Ajax::run($ajax_action); + show_box_bottom(); + $results['additional_information'] = ob_get_contents(); + ob_end_clean(); + break; + case 'check_album_tracks': + + // Set the headers + $headers = array('title'=>_('Title'),'track'=>_('Track'),'artist'=>_('Artist'),'links'=>_('Links')); + + // Ask the great and wise metadata + $objects = metadata::find_missing_tracks($_REQUEST['id']); + + ob_start(); + show_box_top(_('Find Missing Tracks')); + require_once Config::get('prefix') . '/templates/show_objects.inc.php'; + show_box_bottom(); + $results['additional_information'] = ob_get_contents(); + ob_end_clean(); + break; default: $results['rfc3514'] = '0x1'; break; diff --git a/templates/show_album.inc.php b/templates/show_album.inc.php index f357f35a..7e10e085 100644 --- a/templates/show_album.inc.php +++ b/templates/show_album.inc.php @@ -25,8 +25,8 @@ $ajax_url = Config::get('ajax_url'); // Title for this album $title = scrub_out($album->name) . ' (' . $album->year . ') -- ' . $album->f_artist; ?> - -
+ +
id . "&type=popup&sid=" . session_id(); @@ -42,7 +42,7 @@ $title = scrub_out($album->name) . ' (' . $album->year . ') -- ' . $album->f_ar
:
-
+
id,_('Play Album'),'play_full_' . $album->id); ?> id,_('Play Random from Album'),'play_random_' . $album->id); ?> has_access('75')) { ?> @@ -55,9 +55,14 @@ $title = scrub_out($album->name) . ' (' . $album->year . ') -- ' . $album->f_ar
+ + id,_('Find Missing Tracks'),'album_missing_tracks'); ?> +
- +
+  +
name . ' ' . _('Songs')); $object_ids = $album->get_songs(); diff --git a/templates/show_objects.inc.php b/templates/show_objects.inc.php index cd1445a7..12629919 100644 --- a/templates/show_objects.inc.php +++ b/templates/show_objects.inc.php @@ -37,4 +37,11 @@ + + + + + + + -- cgit