summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorJan-Christoph Borchardt <JanCBorchardt@fsfe.org>2011-07-28 22:20:34 +0200
committerJan-Christoph Borchardt <JanCBorchardt@fsfe.org>2011-07-28 22:20:34 +0200
commitba246d3b27ca7a5de06e5674e9b562035d36eca0 (patch)
tree65014a4ddbfe18bff842f09239fd9aabc9469f5f /apps
parent43f99a89839d43ef042397b5b7d71f85453c7399 (diff)
parent5728f801161ae0ee25113581157a26b1b63cd9ff (diff)
downloadnextcloud-server-ba246d3b27ca7a5de06e5674e9b562035d36eca0.tar.gz
nextcloud-server-ba246d3b27ca7a5de06e5674e9b562035d36eca0.zip
Merge branch 'master' into interface
Diffstat (limited to 'apps')
-rw-r--r--apps/media/ajax/api.php3
-rw-r--r--apps/media/appinfo/database.xml18
-rw-r--r--apps/media/lib_collection.php28
-rw-r--r--apps/media/lib_scanner.php99
-rw-r--r--apps/user_openid/phpmyid.php14
5 files changed, 124 insertions, 38 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
diff --git a/apps/media/lib_scanner.php b/apps/media/lib_scanner.php
index aa0ca94a43d..296acbdbaa9 100644
--- a/apps/media/lib_scanner.php
+++ b/apps/media/lib_scanner.php
@@ -68,40 +68,79 @@ class OC_MEDIA_SCANNER{
* @return boolean
*/
public static function scanFile($path){
- if(!self::$getID3){
- self::$getID3=@new getID3();
- }
$file=OC_FILESYSTEM::getLocalFile($path);
- $data=@self::$getID3->analyze($file);
- getid3_lib::CopyTagsToComments($data);
- if(!isset($data['comments'])){
- error_log("error reading id3 tags in '$file'");
- return;
- }
- if(!isset($data['comments']['artist'])){
- error_log("error reading artist tag in '$file'");
- $artist='unknown';
- }else{
- $artist=stripslashes($data['comments']['artist'][0]);
- $artist=utf8_encode($artist);
- }
- if(!isset($data['comments']['album'])){
- error_log("error reading album tag in '$file'");
- $album='unknown';
- }else{
- $album=stripslashes($data['comments']['album'][0]);
- $album=utf8_encode($album);
- }
- if(!isset($data['comments']['title'])){
- error_log("error reading title tag in '$file'");
+ if(substr($path,-3)=='mp3' and OC_HELPER::canExecute("id3info") and OC_HELPER::canExecute("mp3info")){//use the command line tool id3info if possible
+ $output=array();
+ $size=filesize($file);
+ $length=0;
$title='unknown';
+ $album='unknown';
+ $artist='unknown';
+ $track=0;
+ exec('id3info "'.$file.'"',$output);
+ $data=array();
+ foreach($output as $line) {
+ switch(substr($line,0,3)){
+ case '***'://comments
+ break;
+ case '==='://tag information
+ $key=substr($line,4,4);
+ $value=substr($line,strpos($line,':')+2);
+ switch(strtolower($key)){
+ case 'tit1':
+ case 'tit2':
+ $title=$value;
+ break;
+ case 'tpe1':
+ case 'tpe2':
+ $artist=$value;
+ break;
+ case 'talb':
+ $album=$value;
+ break;
+ case 'trck':
+ $track=$value;
+ break;
+ }
+ break;
+ }
+ }
+ $length=exec('mp3info -p "%S" "'.$file.'"');
}else{
- $title=stripslashes($data['comments']['title'][0]);
- $title=utf8_encode($title);
+ if(!self::$getID3){
+ self::$getID3=@new getID3();
+ }
+ $data=@self::$getID3->analyze($file);
+ getid3_lib::CopyTagsToComments($data);
+ if(!isset($data['comments'])){
+ error_log("error reading id3 tags in '$file'");
+ return;
+ }
+ if(!isset($data['comments']['artist'])){
+ error_log("error reading artist tag in '$file'");
+ $artist='unknown';
+ }else{
+ $artist=stripslashes($data['comments']['artist'][0]);
+ $artist=utf8_encode($artist);
+ }
+ if(!isset($data['comments']['album'])){
+ error_log("error reading album tag in '$file'");
+ $album='unknown';
+ }else{
+ $album=stripslashes($data['comments']['album'][0]);
+ $album=utf8_encode($album);
+ }
+ if(!isset($data['comments']['title'])){
+ error_log("error reading title tag in '$file'");
+ $title='unknown';
+ }else{
+ $title=stripslashes($data['comments']['title'][0]);
+ $title=utf8_encode($title);
+ }
+ $size=$data['filesize'];
+ $track=(isset($data['comments']['track']))?$data['comments']['track'][0]:0;
+ $length=round($data['playtime_seconds']);
}
- $size=$data['filesize'];
- $track=(isset($data['comments']['track']))?$data['comments']['track'][0]:0;
- $length=round($data['playtime_seconds']);
if(!isset(self::$artists[$artist])){
$artistId=OC_MEDIA_COLLECTION::addArtist($artist);
self::$artists[$artist]=$artistId;
diff --git a/apps/user_openid/phpmyid.php b/apps/user_openid/phpmyid.php
index 146eb380f73..bc2950982fa 100644
--- a/apps/user_openid/phpmyid.php
+++ b/apps/user_openid/phpmyid.php
@@ -329,27 +329,27 @@ function checkid ( $wait ) {
user_session();
// Get the options, use defaults as necessary
- $return_to = @strlen($_REQUEST['openid_return_to'])
+ $return_to = isset($_REQUEST['openid_return_to'])
? $_REQUEST['openid_return_to']
- : error_400('Missing return1_to');
+ : error_400('Missing return_to');
- $identity = @strlen($_REQUEST['openid_identity'])
+ $identity = isset($_REQUEST['openid_identity'])
? $_REQUEST['openid_identity']
: error_get($return_to, 'Missing identity');
- $assoc_handle = @strlen($_REQUEST['openid_assoc_handle'])
+ $assoc_handle = isset($_REQUEST['openid_assoc_handle'])
? $_REQUEST['openid_assoc_handle']
: null;
- $trust_root = @strlen($_REQUEST['openid_trust_root'])
+ $trust_root = isset($_REQUEST['openid_trust_root'])
? $_REQUEST['openid_trust_root']
: $return_to;
- $sreg_required = @strlen($_REQUEST['openid_sreg_required'])
+ $sreg_required = isset($_REQUEST['openid_sreg_required'])
? $_REQUEST['openid_sreg.required']
: '';
- $sreg_optional = @strlen($_REQUEST['openid_sreg_optional'])
+ $sreg_optional = isset($_REQUEST['openid_sreg_optional'])
? $_REQUEST['openid_sreg.optional']
: '';