command line id3 tag renew

Have a good idea ? Want to suggest something ? Have a couple of lines of code to back it up ?
Post it here !

command line id3 tag renew

Postby kanna on 30-01-2008 16:37

On Unix system it would be nice to have a cron job to renew the database. Also it is pain to renew all my 80 Gb music files - it takes on my slow machine (PIII@500) about hour. Would it be possible to add only recently added files. I know about add new folder to database, but thats not it.

Thanks
kanna
AmpJuke user
AmpJuke user
 
Posts: 23
Joined: 14-12-2007 15:26

Postby Michael on 30-01-2008 17:42

Hello kanna,

Welcome to the AmpJuke forum and thanks for posting.
By the way: Also a big thank you for the previous translation to Estonian, - it's really appreciated.

The cron job feature you're asking for is surely something that's worth considering !
I "only" have around 40Gb music, but it can also take some time (<15 minutes) on my machine (details here).

I'll look into it, and include it in a later release - possibly 0.7.1 (the next) or perhaps a little later in the 0.7.x-series.

Thanks again for your contribution (Estonian language and sugggestion).

//Michael.
User avatar
Michael
Site Admin
Site Admin
 
Posts: 449
Joined: 03-07-2007 13:46
Location: Denmark

Postby Michael on 30-01-2008 21:33

Hi kanna,

Had a few minutes available, so I just did a quick hack on this and came up with a reasonable solution, as follows:

The scan+import is done using the "scan.php" file.
Unfortunately, there's a check near the top to see if the user has an active session (normally not the case when calling "scan.php" on a commandline and/or within cron).

Furthermore, scan.php expects a parameter - $act - (in the URL) that tells the script what to do.

So I edited "scan.php" and modified the first few lines, - basically commenting out the check for the session as well as hardcoding a value for $act, so the modified "scan.php" now looks like this:
Code: Select all
<?php
$act='rebuild';
/*
if (!file_exists('db_new.sql')) {
   session_start();
   if (!isset($_SESSION['login'])) {
      echo 'Not logged in. <a href="login.php">Click here to login</a>.';
      exit;
   }
}
*/
// 0.6.1: Check that we can write to db.php:
if (file_exists('db.php')) {
[..the rest of scan.php...]


Guess what: It works.
Doing this on a command line actually performs a scan+import w.o. "intervention" (i.e.: you can run it in a terminal):
mhi@netvista:~$ cd /var/www/ampjuke
mhi@netvista:/var/www/ampjuke$ php ./scan.php


Some stuff to remember:
- You might need to 'cd' to a different directory on your box.
- You might need to enter the absolute path to php; f.ex.: /usr/local/bin/php/php
- All output is written to the screen - but can redirected to a file using: php ./scan.php > scan_report.htm (yes, scan.php outputs HTML...).
- Commenting out the session-check, will enable *anybody* to start a scan+import, so you might consider renaming scan.php to something else.
- The reason why you're supposed to be in the directory where AmpJuke is installed is just because scan.php includes the getid3-stuff one directory below relative to cwd.

...hope this makes sense.
Putting the above mentioned terminal-commands into a file, make the file executable, and inserting that into your crontab will actually make scan+import run at the intervals you specify in the crontab.

Since you asked for the option to scan+import using cron, I assume you're familiar with cron.

If you want, I can make a short FAQ-entry (in the FAQ) describing what should be done.

//Michael.
User avatar
Michael
Site Admin
Site Admin
 
Posts: 449
Joined: 03-07-2007 13:46
Location: Denmark

Postby kanna on 31-01-2008 15:37

It works on command line! - Thanks for the quick fix!
Adding it to my cron.
Code: Select all
PHP Notice:  Undefined index:  QUERY_STRING in /var/www/ampjuke/cron.php on line 35

error comes when executing :
Code: Select all
php ./scan.php > scan.html


Added through webmin following line to crontab:
Code: Select all
cd /var/www/ampjuke/ && php ./scan.php > scan.html



But still it would be nice to have quicker database update. Like updating only files with newer date tag than 1 day - when having 24 hour conjob. Using somthing like that:
Code: Select all
/usr/bin/find /music_location/ -mtime -1 -fprint /var/www/amjuke/last_01_day_changes.txt
kanna
AmpJuke user
AmpJuke user
 
Posts: 23
Joined: 14-12-2007 15:26

Postby Michael on 01-02-2008 14:43

But still it would be nice to have quicker database update. Like updating only files with newer date tag...

Agree - I'll include that in one of the next releases.
What I have in mind is a parameter like "Only scan+import music added or modified in the last XX days", - where XX can be any numeric value entered by the user.
If XX f.ex. is 10, then music added/modifed within the last 10 days will be scanned+imported.
This will obviously be based on the filemtime function.
What do you think about this ?

By the way: Just comment out the PHP Notice about the QUERY_STRING in your cron-modified version of scan.php.
It's only used to tell scan.php what to do (the $act-parameter, if you remember).
We're using a hardcoded value for $act in the modified version of scan.php, so QUERY_STRING isn't really used.

Have a nice weekend.

//Michael.
User avatar
Michael
Site Admin
Site Admin
 
Posts: 449
Joined: 03-07-2007 13:46
Location: Denmark

Postby kanna on 01-02-2008 19:15

What I have in mind is a parameter like "Only scan+import music added or modified in the last XX days", - where XX can be any numeric value entered by the user.
If XX f.ex. is 10, then music added/modifed within the last 10 days will be scanned+imported.
This will obviously be based on the filemtime function.
What do you think about this ?


I don't see any reason to choose how new music I want to scan. Why should I want to left out some 11 days ago added music? In my opinion goal is to have all the music as quickly as possible added to database keeping same time server load as low as possible. So I think there should be two options
to "Scan+import all music files" and "Scan+import new music files".
System should write last scan time tag, and when executing new scan use it as reference and perhaps subtract some hours in case when server has renewed time meanwhile.

Kanna
kanna
AmpJuke user
AmpJuke user
 
Posts: 23
Joined: 14-12-2007 15:26

Postby Michael on 01-02-2008 21:22

I don't see any reason to choose how new music I want to scan. Why should I want to left out some 11 days ago added music?

You're absolutely right.

So I think there should be two options
to "Scan+import all music files" and "Scan+import new music files".

Yep. Old functionality as well as the new option.

System should write last scan time tag, and when executing new scan use it as reference and perhaps subtract some hours in case when server has renewed time meanwhile.

...and perhaps the "Scan+import new music files" option has additional information saying something like "Last scan occurred <date> (which is <days> ago)".
...where <days> is a field the user optionally can change. The field <days> will have a default value of: current date - last scan date.

Thanks for your suggestion, it's really appreciated.

//Michael.
User avatar
Michael
Site Admin
Site Admin
 
Posts: 449
Joined: 03-07-2007 13:46
Location: Denmark

Postby Michael on 08-02-2008 19:26

Kanna,

Just FYI, I'm including a functionality similar to whats described previously in the next release of AmpJuke.

//Michael.
User avatar
Michael
Site Admin
Site Admin
 
Posts: 449
Joined: 03-07-2007 13:46
Location: Denmark

Postby kanna on 08-02-2008 21:58

Thats super!

Thanks,

Kanna

Edit:17.02.08

Added two lines to new (0.7.1) Amjuke scan.php beside previous additions to make the cron job automatic for 24 hour.

Code: Select all
function process_files($dir,&$ok,&$warnings,&$errors,&$act,$print_details,$cutoff_date) {
// 0.7.1: cutoff_date introduced
$errors=0;
$ok=0;
$warnings=0;
$errors=0;
$total=0;
$first_file=1;
$handle=opendir($dir);
$yesterday  = mktime(0, 0, 0, date("m")  , date("d")-1, date("Y"));
$cutoff_date=$yesterday;
$error_buf="<tr><td>Dir=".$dir."</td>";


Added these lines:
Code: Select all
$yesterday  = mktime(0, 0, 0, date("m")  , date("d")-1, date("Y"));
$cutoff_date=$yesterday;


Seems to work fine - 1 hour tag reading vs. 20 seconds :)
kanna
AmpJuke user
AmpJuke user
 
Posts: 23
Joined: 14-12-2007 15:26


Return to Requests / suggestions

Who is online

Users browsing this forum: No registered users and 1 guest

cron