mIRC Home    About    Download    Register    News    Help

Print Thread
#127062 08/08/05 12:15 PM
Joined: Dec 2002
Posts: 45
P
piko Offline OP
Ameglian cow
OP Offline
Ameglian cow
P
Joined: Dec 2002
Posts: 45
Hi!
I wonder if there is any mp3 sorter script that can read a id3-tag
and sort the mp3's in genres..

like:
Code:
X:\mp3\unsorted\Artist - Title
                           1. Artist - Title.mp3
                           2. Artist - Title.mp3
                           3. Artist e.t.c.
X:\mp3\unsorted\Artist2 - Title2
                           1. Artist2 - Title2.mp3
                           2. Artist2 - Title2.mp3
                           3. Artist2 e.t.c.


And then read the id3-tag of the first track (or something)
and sort in to:

Code:
X:\mp3\dance\Artist - Title
X:\mp3\rock\Artist2 - Title2


Where the id3-tag says dance in the genre line for "Artist - Title"
and rock for "Artist2 - Title2".

Is there anyway to do this, or is there anyone who knows if
there already exist a script like this or perhaps a nice little
app..?

Regards..

#127063 08/08/05 07:49 PM
Joined: Dec 2002
Posts: 3,547
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 3,547
Hey there, do you mean something like:

Code:
alias sMp3 {
  if (!%mp3dir) %mp3dir = $$sdir=" Select a directory.."
  var %x = 1
  while (%x <= $findfile(%mp3dir,*.mp3,0)) {
    mkdir $+(",%mp3dir,$mp3($findfile(%mp3dir,*.mp3,%x)).genre,\,")
    write $+(",%mp3dir,$mp3($findfile(%mp3dir,*.mp3,%x)).genre,\Songs.txt,") $nopath($findfile(%mp3dir,*.mp3,%x))
    inc %x
  }
}


-Andy

#127064 08/08/05 08:24 PM
Joined: Dec 2002
Posts: 45
P
piko Offline OP
Ameglian cow
OP Offline
Ameglian cow
P
Joined: Dec 2002
Posts: 45
Well.. kinda..
but i want it to move the entire folder instead of makin a txt laugh

#127065 09/08/05 01:09 AM
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
That's some of the worst coding I've seen from you Andy, you should know better by now...

Take a good look at your alias, it could be improved to work 1000 times faster. Remember, since a lot of people watch our posts, we should be careful not to teach other people bad scripting habits or inneficient coding.

Let's say his mp3 folder has 1000 mp3's in here (that's even being modest). That means:

1000 while iterations, with in each iteration you use a $findfile(%mp3dir,*.mp3,0) which returns the total amount of files in the folder. Can you imagine how long that takes? It has to look up 1000 times the amount of files in the folder. If there's anything worse than putting $lines(file) inside a while condition, it is $findfile. You should put the total files in a variable and reference that.

Inside the while loop, you are referencing the same file 3 times, being $findfile(%mp3dir,*.mp3,%x). That means 3000 times it has to look up this value == crappy. You should put the value in a variable, and reference that variable instead, will make a huge difference.

Lastly, a huge mistake here is to use write to write to a text file. As you know, for each /write operation, mIRC must open the specified file, write the string, and close it. Imagine doing that 1000 times, trust me it's very inefficient. You should atleast use the file handling commands. With /fopen, you open the file once, and then you can write to it, without each time opening/closing the file, with /fwrite. When you're done, you close the file with /fclose.

Anyway, even with the optimizations mentioned, it will still be highly inefficient because of the while loop. The best thing you can do here, is do 1 single $findfile call, and specify a custom alias in the command part of $findfile, which will take care of it.

Remember, $findfile is not an ordinary identifier like $gettok or the likes, which return a result much much faster. $findfile is an intensive identifier which should be used wisely. It has to scan a folder and all its subfolders (if no depth is specified), and check for each file if it matches the matchtext specified in $findfile. That takes much much longer than any other identifier.

Something along the lines of:

//!.echo -q $findfile(%mp3dir,*.mp3,0,myalias $1-)

alias myalias {
; $1- = filename
; your code here
}

Note that this code, as optimized as it is, will still choke on a lot of files. If you have 10000+ files, then don't expect this to finish in 20 seconds, it may very well take ages. Nothing that can be done about that, unless you resort to DLL's like whilefix, which has a builtin findfilecall command.


Gone.
#127066 09/08/05 10:24 AM
Joined: Nov 2003
Posts: 2,327
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Nov 2003
Posts: 2,327
Try this:

Code:
alias mp3Sort {
  if (!$isid) { 
    echo -a Usage: $mp3Sort(<directory 1>,<directory 2>) 
    return
  }
  var %dir = $iif(*\ iswm $2,$2,$2\)
  return $findfile($1,*.mp3,0,1,!.echo -q $copyfile($1-,%dir $+ $sound($1-).artist - $sound($1-).title,%dir))
}
alias -l copyfile {
  if (!$isdir($+($3,$mkfn($remove($2,$3))))) { .mkdir $+(",$3,$mkfn($remove($2,$3)),\") }
  if (!$isfile($+($3,$mkfn($remove($2,$3)),\,$mkfn($remove($2,$3)),.mp3))) { .copy " $+ $1" $+(",$3,$mkfn($remove($2,$3)),\,$mkfn($remove($2,$3)),.mp3") }
  return $isfile($+($3,$mkfn($remove($2,$3)),\,$mkfn($remove($2,$3)),.mp3))
}


//echo -a $mp3Sort(directory one,directory two)

The above alias copies the files, it doesn't move them, but it's very very slow (26 seconds to move 9 files here).


New username: hixxy
#127067 09/08/05 11:09 AM
Joined: Dec 2002
Posts: 45
P
piko Offline OP
Ameglian cow
OP Offline
Ameglian cow
P
Joined: Dec 2002
Posts: 45
this worked i think, but it copied the mp3's to a folder that was named as the track.. so "1. artist - title.mp3" was copied into a folder wich was named "Artist - title", and the mp3 was named as the id3-tag..

#127068 09/08/05 11:38 AM
Joined: Nov 2003
Posts: 2,327
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Nov 2003
Posts: 2,327
That'll teach me to read the whole post before replying in future won't it :tongue:

Code:
alias mp3Sort {
  if (!$isid) {
    echo -a Usage: $!mp3Sort(folder1,folder2)
    return
  }
  if (!$isdir($1)) || (!$isdir($2)) { return }
  var %dir = $iif(*\ iswm $2,$2,$2\)
  return $findfile($1,*.mp3,0,1,!.echo -q $copyfile($1-,%dir))
}
alias -l copyfile {
  if (!$isid) {
    echo -a Usage: $!copyfile(file,directory)
    return $false
  }
  if ($isfile($1)) && ($isdir($2)) {
    if (!$isdir($+($2,$mkfn($iif($sound($1).genre != $null,$v1,Unknown)),\))) { .mkdir $+(",$2,$mkfn($iif($sound($1).genre != $null,$v1,Unknown)),\") }
    .copy " $+ $1" $+(",$2,$mkfn($iif($sound($1).genre != $null,$v1,Unknown)),\,$nopath($1),")
    return $true
  }
  return $false
}


This is used the same as the other one ($mp3Sort(folder1,folder2)) but this time it actually does what you want (I hope) smile


New username: hixxy
#127069 10/08/05 12:10 PM
Joined: Dec 2002
Posts: 45
P
piko Offline OP
Ameglian cow
OP Offline
Ameglian cow
P
Joined: Dec 2002
Posts: 45
well, when i use "//echo -a $mp3Sort(folder1,folder2)", I get
"* /echo: insufficient parameters", was i supposed to use //echo? smile


Link Copied to Clipboard