Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
our_own_cloud_project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
die_coolen_jungs
our_own_cloud_project
Commits
0d408fe6
Commit
0d408fe6
authored
13 years ago
by
Robin Appelman
Browse files
Options
Downloads
Patches
Plain Diff
make use of the command line tools id3info and mp3info for scanning music if they are available
parent
75057203
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
apps/media/lib_scanner.php
+69
-30
69 additions, 30 deletions
apps/media/lib_scanner.php
lib/filestorage.php
+1
-57
1 addition, 57 deletions
lib/filestorage.php
lib/helper.php
+45
-0
45 additions, 0 deletions
lib/helper.php
with
115 additions
and
87 deletions
apps/media/lib_scanner.php
+
69
−
30
View file @
0d408fe6
...
@@ -68,40 +68,79 @@ class OC_MEDIA_SCANNER{
...
@@ -68,40 +68,79 @@ class OC_MEDIA_SCANNER{
* @return boolean
* @return boolean
*/
*/
public
static
function
scanFile
(
$path
){
public
static
function
scanFile
(
$path
){
if
(
!
self
::
$getID3
){
self
::
$getID3
=@
new
getID3
();
}
$file
=
OC_FILESYSTEM
::
getLocalFile
(
$path
);
$file
=
OC_FILESYSTEM
::
getLocalFile
(
$path
);
$data
=@
self
::
$getID3
->
analyze
(
$file
);
if
(
substr
(
$path
,
-
3
)
==
'mp3'
and
OC_HELPER
::
canExecute
(
"id3info"
)
and
OC_HELPER
::
canExecute
(
"mp3info"
)){
//use the command line tool id3info if possible
getid3_lib
::
CopyTagsToComments
(
$data
);
$output
=
array
();
if
(
!
isset
(
$data
[
'comments'
])){
$size
=
filesize
(
$file
);
error_log
(
"error reading id3 tags in '
$file
'"
);
$length
=
0
;
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'
;
$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
{
}
else
{
$title
=
stripslashes
(
$data
[
'comments'
][
'title'
][
0
]);
if
(
!
self
::
$getID3
){
$title
=
utf8_encode
(
$title
);
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
])){
if
(
!
isset
(
self
::
$artists
[
$artist
])){
$artistId
=
OC_MEDIA_COLLECTION
::
addArtist
(
$artist
);
$artistId
=
OC_MEDIA_COLLECTION
::
addArtist
(
$artist
);
self
::
$artists
[
$artist
]
=
$artistId
;
self
::
$artists
[
$artist
]
=
$artistId
;
...
...
This diff is collapsed.
Click to expand it.
lib/filestorage.php
+
1
−
57
View file @
0d408fe6
...
@@ -200,7 +200,7 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{
...
@@ -200,7 +200,7 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{
}
else
if
(
function_exists
(
"mime_content_type"
))
{
}
else
if
(
function_exists
(
"mime_content_type"
))
{
// use mime magic extension if available
// use mime magic extension if available
$mime_type
=
mime_content_type
(
$this
->
datadir
.
$fspath
);
$mime_type
=
mime_content_type
(
$this
->
datadir
.
$fspath
);
}
else
if
(
self
::
canExecute
(
"file"
))
{
}
else
if
(
OC_HELPER
::
canExecute
(
"file"
))
{
// it looks like we have a 'file' command,
// it looks like we have a 'file' command,
// lets see it it does have mime support
// lets see it it does have mime support
$fp
=
popen
(
"file -i -b '
{
$this
->
datadir
}
$fspath
' 2>/dev/null"
,
"r"
);
$fp
=
popen
(
"file -i -b '
{
$this
->
datadir
}
$fspath
' 2>/dev/null"
,
"r"
);
...
@@ -223,62 +223,6 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{
...
@@ -223,62 +223,6 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{
}
}
}
}
/**
* detect if a given program is found in the search PATH
*
* helper function used by _mimetype() to detect if the
* external 'file' utility is available
*
* @param string program name
* @param string optional search path, defaults to $PATH
* @return bool true if executable program found in path
*/
private
function
canExecute
(
$name
,
$path
=
false
)
{
// path defaults to PATH from environment if not set
if
(
$path
===
false
)
{
$path
=
getenv
(
"PATH"
);
}
// check method depends on operating system
if
(
!
strncmp
(
PHP_OS
,
"WIN"
,
3
))
{
// on Windows an appropriate COM or EXE file needs to exist
$exts
=
array
(
".exe"
,
".com"
);
$check_fn
=
"file_exists"
;
}
else
{
// anywhere else we look for an executable file of that name
$exts
=
array
(
""
);
$check_fn
=
"is_executable"
;
}
// Default check will be done with $path directories :
$dirs
=
explode
(
PATH_SEPARATOR
,
$path
);
// WARNING : We have to check if open_basedir is enabled :
$obd
=
ini_get
(
'open_basedir'
);
if
(
$obd
!=
"none"
)
$obd_values
=
explode
(
PATH_SEPARATOR
,
$obd
);
if
(
count
(
$obd_values
)
>
0
)
{
// open_basedir is in effect !
// We need to check if the program is in one of these dirs :
$dirs
=
$obd_values
;
}
foreach
(
$dirs
as
$dir
)
{
foreach
(
$exts
as
$ext
)
{
if
(
$check_fn
(
"
$dir
/
$name
"
.
$ext
))
return
true
;
}
}
return
false
;
}
public
function
toTmpFile
(
$path
){
public
function
toTmpFile
(
$path
){
$tmpFolder
=
sys_get_temp_dir
();
$tmpFolder
=
sys_get_temp_dir
();
$filename
=
tempnam
(
$tmpFolder
,
'OC_TEMP_FILE_'
.
substr
(
$path
,
strrpos
(
$path
,
'.'
)));
$filename
=
tempnam
(
$tmpFolder
,
'OC_TEMP_FILE_'
.
substr
(
$path
,
strrpos
(
$path
,
'.'
)));
...
...
This diff is collapsed.
Click to expand it.
lib/helper.php
+
45
−
0
View file @
0d408fe6
...
@@ -267,6 +267,51 @@ class OC_HELPER {
...
@@ -267,6 +267,51 @@ class OC_HELPER {
if
((
isset
(
$_REQUEST
[
$s
])
&&
$_REQUEST
[
$s
]
==
$v
)
||
$v
==
$d
)
if
((
isset
(
$_REQUEST
[
$s
])
&&
$_REQUEST
[
$s
]
==
$v
)
||
$v
==
$d
)
print
"checked=
\"
checked
\"
"
;
print
"checked=
\"
checked
\"
"
;
}
}
/**
* detect if a given program is found in the search PATH
*
* @param string program name
* @param string optional search path, defaults to $PATH
* @return bool true if executable program found in path
*/
public
static
function
canExecute
(
$name
,
$path
=
false
){
// path defaults to PATH from environment if not set
if
(
$path
===
false
)
{
$path
=
getenv
(
"PATH"
);
}
// check method depends on operating system
if
(
!
strncmp
(
PHP_OS
,
"WIN"
,
3
))
{
// on Windows an appropriate COM or EXE file needs to exist
$exts
=
array
(
".exe"
,
".com"
);
$check_fn
=
"file_exists"
;
}
else
{
// anywhere else we look for an executable file of that name
$exts
=
array
(
""
);
$check_fn
=
"is_executable"
;
}
// Default check will be done with $path directories :
$dirs
=
explode
(
PATH_SEPARATOR
,
$path
);
// WARNING : We have to check if open_basedir is enabled :
$obd
=
ini_get
(
'open_basedir'
);
if
(
$obd
!=
"none"
)
$obd_values
=
explode
(
PATH_SEPARATOR
,
$obd
);
if
(
count
(
$obd_values
)
>
0
and
$obd_values
[
0
])
{
// open_basedir is in effect !
// We need to check if the program is in one of these dirs :
$dirs
=
$obd_values
;
}
foreach
(
$dirs
as
$dir
)
{
foreach
(
$exts
as
$ext
)
{
if
(
$check_fn
(
"
$dir
/
$name
"
.
$ext
))
return
true
;
}
}
return
false
;
}
}
}
?>
?>
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment