summaryrefslogtreecommitdiffstats
path: root/apps/media
diff options
context:
space:
mode:
authorRobin Appelman <icewind1991@gmail.com>2011-07-28 20:59:36 +0200
committerRobin Appelman <icewind1991@gmail.com>2011-07-28 20:59:36 +0200
commitbc51425bb753d7a5adffe707053b6186a4de7bba (patch)
tree513260893bf9cc5514280f834c59231cbe0a16e5 /apps/media
parent7d15a45e09bfa27597a1169e12ba79b6e5221946 (diff)
downloadnextcloud-server-bc51425bb753d7a5adffe707053b6186a4de7bba.tar.gz
nextcloud-server-bc51425bb753d7a5adffe707053b6186a4de7bba.zip
keep track of playcount as last played time of music files
Diffstat (limited to 'apps/media')
-rw-r--r--apps/media/ajax/api.php3
-rw-r--r--apps/media/appinfo/database.xml18
-rw-r--r--apps/media/lib_collection.php28
3 files changed, 48 insertions, 1 deletions
diff --git a/apps/media/ajax/api.php b/apps/media/ajax/api.php
index 0ccfb63f418..84d5dd17882 100644
--- a/apps/media/ajax/api.php
+++ b/apps/media/ajax/api.php
@@ -105,6 +105,9 @@ if($arguments['action']){
$ftype=OC_FILESYSTEM::getMimeType( $arguments['path'] );
+ $songId=OC_MEDIA_COLLECTION::getSongByPath($arguments['path']);
+ OC_MEDIA_COLLECTION::registerPlay($songId);
+
header('Content-Type:'.$ftype);
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
diff --git a/apps/media/appinfo/database.xml b/apps/media/appinfo/database.xml
index 91fa1f9e2a1..223682fcfcd 100644
--- a/apps/media/appinfo/database.xml
+++ b/apps/media/appinfo/database.xml
@@ -206,6 +206,24 @@
<length>4</length>
</field>
+ <field>
+ <name>song_playcount</name>
+ <type>integer</type>
+ <default>
+ </default>
+ <notnull>true</notnull>
+ <length>4</length>
+ </field>
+
+ <field>
+ <name>song_lastplayed</name>
+ <type>integer</type>
+ <default>
+ </default>
+ <notnull>true</notnull>
+ <length>4</length>
+ </field>
+
</declaration>
</table>
diff --git a/apps/media/lib_collection.php b/apps/media/lib_collection.php
index 6e2011675ad..278e450b778 100644
--- a/apps/media/lib_collection.php
+++ b/apps/media/lib_collection.php
@@ -270,7 +270,8 @@ class OC_MEDIA_COLLECTION{
if($songId!=0){
return $songId;
}else{
- $query=OC_DB::prepare("INSERT INTO `*PREFIX*media_songs` (`song_id` ,`song_name` ,`song_artist` ,`song_album` ,`song_path` ,`song_user`,`song_length`,`song_track`,`song_size`) VALUES (NULL , ?, ?, ?, ?,?,?,?,?)");
+ $query=OC_DB::prepare("INSERT INTO `*PREFIX*media_songs` (`song_id` ,`song_name` ,`song_artist` ,`song_album` ,`song_path` ,`song_user`,`song_length`,`song_track`,`song_size`,`song_playcount`,`song_lastplayed`)
+ VALUES (NULL , ?, ?, ?, ?,?,?,?,?,0,0)");
$query->execute(array($name,$artist,$album,$path,$uid,$length,$track,$size));
$songId=OC_DB::insertid();
// self::setLastUpdated();
@@ -346,6 +347,31 @@ class OC_MEDIA_COLLECTION{
$query=OC_DB::prepare("DELETE FROM *PREFIX*media_songs WHERE song_path LIKE ?");
$query->execute(array("$path%"));
}
+
+ /**
+ * increase the play count of a song
+ * @param int songId
+ */
+ public static function registerPlay($songId){
+ $now=time();
+ $query=OC_DB::prepare('UPDATE *PREFIX*media_songs SET song_playcount=song_playcount+1, song_lastplayed=? WHERE song_id=? AND song_lastplayed<?');
+ $query->execute(array($now,$songId,$now-60));
+ }
+
+ /**
+ * get the id of the song by path
+ * @param string $path
+ * @return int
+ */
+ public static function getSongByPath($path){
+ $query=OC_DB::prepare("SELECT song_id FROM *PREFIX*media_songs WHERE song_path = ?");
+ $result=$query->execute(array($path))->fetchAll();
+ if(count($result)>0){
+ return $result[0]['song_id'];
+ }else{
+ return 0;
+ }
+ }
}
?> \ No newline at end of file