linux - Speed-up Bash ID3 to MySQL import -


I have 2 Bash scripts that go through a directory, extract ID3 information for MP3 and they Import tag information into a MySQL DB It takes a lot of time to complete the walk, so I was hoping someone could help me make the script more efficient.

The scripts are as follows:

makeid3dbentry.sh

  track = $ (id3info "$ 1" | grep '^ === TIT2' sed -e 's /.*: // g') ARTIST = $ (id3info "$ 1" | grep '^ === TPE1' | sed -e 's /.*: //g') ALBUM = $ ( Id3info "$ 1" | grep '^ === TALB' | sed -e 's /.*: //g') ALBUMARTIST = $ (id3info "$ 1" | grep '^ === TPE2' | sed - e 's /.*: // g') COLS = '`artist``,` name`, `album`,`' $$ {ARTIST // \ "/ \\\"} '', '' $ To avoid {TRACK / '$'}, avoid $ {string // substrings / replace} "VALS = '" / \ "/ \\\"}' "" '$ {album // \ "/ \\ \ "} '" "' $ {ALBUMARTIST // \" / \\\ "} '" "' $ {1} '' SETLIST = '` artist` = "' $$ ARTIST // \" / \\ \ "} '',` Name` = "'$ {track //" / \\\ "}' ',` album` = "' $ {album // \" / \\\ "} '',` Albumartist` = "'$ {ALBUMARTIST / '' $ '', '' '' $ {SETLIST} '' '' ('$ {COLS}') values' ('$ {VALS}' } ') In' echo 'INSERT;'   

This produces an INSERT statement such as

  `music` in INSERT (` artist`, `name`,` album`, 'album artist '' File name ') value ("1200 microgram", "ayahuosa", "1200 microgram", "1200 microgram", "/ mnt / shared media / music / album / 1200 microgram / 1200 micrograms [2002] / 1-01 -1200 microgram - "1200 microgram", `Albertast '=" 1200 microgram ",` filename` = "- 1200 microgram", `name` =" ayahuska "," album "/ mnt / share Video / Audio / 1200 microgram / 1200 microgram [2002] / 1-01 - 1200 microgram - Ayahuska MP3 ";   

Main update script:

UpdateMusicdb.sh DIRFULLPATH = "$ {1}" DIRECTORY = $ (BaseName "$ {DIRFULLPATH}") SQLFILE = "/ var / www / html / scripts / sql / rebuilddb_ $" {DIRECTORY} .sql "find" $ {DIRFULLPATH} "-type F -iname" * .mp3 "-exec /var/www/html/scripts/bash/makeid3dbentry.sh {} & gt;" $ {SQLFILE} " \; mysql --defts- Additional file = / var / www / html / config / website.cnf --default-cHunner-set = UTF8 "website" & lt; "$ {SQLFILE}"

Unfortunately I'm bash & amp; To see the Linux environment as well as where the obstacles are and how to improve these scripts. I appreciate any suggestions on improving scripts or on a different perspective if this is better / faster.

You already have a comment as a suggestion in the id3info Avoid walking times.

You can find makeid3dbentry.sh also for a file in a simple "$ {@}" around your code. with -exec yourcript.sh {} + (works like xargs). This way you can greatly reduce the number of invitations to your script. I would probably recommend doing this whole thing as a script, however, you wrap the insert statement for loop in your Find command (without -exec parameter) And can pipe this output into the file.

Your MySQL database believes that you are using INODB, until the work is completed (on each insert) start transactions at the top of your code ; insert and below COMMIT; View,

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -