From 5d98a104bc750053e90da5f8dd9664e0433f900d Mon Sep 17 00:00:00 2001 From: Karl 'vollmerk' Vollmer Date: Sat, 15 Dec 2007 07:28:51 +0000 Subject: made downloads counted in stats fixes ticket #12 tweaked filename to be reformated to match the catalog rename pattern --- bin/sort_files.inc | 3 ++- docs/CHANGELOG | 2 ++ lib/class/catalog.class.php | 2 +- lib/class/song.class.php | 32 ++++++++++++++++++++++++++++++++ play/index.php | 11 ++++++++++- 5 files changed, 47 insertions(+), 3 deletions(-) diff --git a/bin/sort_files.inc b/bin/sort_files.inc index ea3b4807..cb01e7f1 100644 --- a/bin/sort_files.inc +++ b/bin/sort_files.inc @@ -60,8 +60,9 @@ while ($r = mysql_fetch_row($db_results)) { foreach ($songs as $song) { /* Find this poor song a home */ $song->format_song(); + $song->format_pattern(); $directory = sort_find_home($song,$catalog->sort_pattern,$catalog->path); - $filename = sort_find_filename($song,$catalog->rename_pattern); + $filename = $song->f_file; $fullpath = $directory . "/" . $filename; /* Check for Demo Mode */ diff --git a/docs/CHANGELOG b/docs/CHANGELOG index b2701638..f7f25517 100755 --- a/docs/CHANGELOG +++ b/docs/CHANGELOG @@ -4,6 +4,8 @@ -------------------------------------------------------------------------- v.3.4-Alpha4 + - Fixed download filename to match the catalog filename pattern + - Added downloads back to stats tracking - Fixed disable/re-enable of users - Fixed a bug where ajax actions wouldn't trigger a redirect to login when session expired, instead they would just break diff --git a/lib/class/catalog.class.php b/lib/class/catalog.class.php index 21d725db..39c2c7ea 100644 --- a/lib/class/catalog.class.php +++ b/lib/class/catalog.class.php @@ -2299,7 +2299,7 @@ class Catalog { $result .= xml_from_array($xml,1,'itunes'); } - return $result; + return $result; } diff --git a/lib/class/song.class.php b/lib/class/song.class.php index b7c59621..0ad9af68 100644 --- a/lib/class/song.class.php +++ b/lib/class/song.class.php @@ -705,6 +705,38 @@ class Song { } // format + /** + * format_pattern + * This reformates the song information based on the catalog + * rename patterns + */ + public function format_pattern() { + + $catalog = new Catalog($this->catalog); + + $extension = ltrim(substr($this->file,strlen($this->file)-4,4),"."); + + /* Create the filename that this file should have */ + $album = $this->f_album_full; + $artist = $this->f_artist_full; + $genre = $this->f_genre; + $track = $this->track; + $title = $this->title; + $year = $this->year; + + /* Start replacing stuff */ + $replace_array = array('%a','%A','%t','%T','%y','%g'); + $content_array = array($artist,$album,$title,$track,$year,$genre); + + $rename_pattern = str_replace($replace_array,$content_array,$catalog->rename_pattern); + + $rename_pattern = preg_replace("[\-\:\!]","_",$rename_pattern); + + $this->f_pattern = $rename_pattern; + $this->f_file = $rename_pattern . "." . $extension; + + } // format_pattern + /** * @function get_rel_path * @discussion returns the path of the song file stripped of the catalog path diff --git a/play/index.php b/play/index.php index 19bc1cd4..56e7fa27 100644 --- a/play/index.php +++ b/play/index.php @@ -188,7 +188,8 @@ $song_name = $song->f_artist_full . " - " . $song->title . "." . $song->type; if ($_GET['action'] == 'download' AND $GLOBALS['user']->prefs['download']) { // STUPID IE - $song_name = str_replace(array('?','/','\\'),"_",$song_name); + $song->format_pattern(); + $song_name = str_replace(array('?','/','\\'),"_",$song->f_file); // Use Horde's Browser class to send the headers header("Content-Length: " . $song->size); @@ -212,6 +213,14 @@ if ($_GET['action'] == 'download' AND $GLOBALS['user']->prefs['download']) { else { fpassthru($fp); } + + // Make sure that a good chunk of the song has been played + if ($bytesStreamed > $minBytesStreamed) { + debug_event('Stats','Downloaded, Registering stats for ' . $song->title,'5'); + + $user->update_stats($song->id); + + } // if enough bytes are streamed fclose($fp); exit(); -- cgit