Jump to content
Sign in to follow this  
Siryx

Title Renamer

Recommended Posts

Siryx

hi everyone

i downloaded a couple of songs from YT in the format : "Interpret - Title.mp3" as its filename, and i wanted to edit the attributes of the titles so that the values got from the name get written in.

Because I dont know how to do the attribute-writing-thing with autoit i wrote a script which imitates the things i would do (pressing right arrow twice with ctrl pressed while having itunes open, then deleting the " - " thing and ctrl+x and ctrl+v). works well for one-worded interprets only :(

so, what i would like to script is a program what gets the filenames then looks out for the " - " thing, and writing the value infront and after it in the file.

if somebody knows how to do it, please let me know

sincerely Siryx

Share this post


Link to post
Share on other sites
November

Hi and welcome

Check Autoit Help file for:

_FileListToArray
FileCopy or FileMove
FileDelete
StringReplace
While...WEnd
For...Next
 
Script something all the comunity will be delighted to help you.
 
Cheers!

Old Scriptology

Visual Ping 1.8 - Mass Ping Program with export to txt delimited.

Desktop 2 RGB and YMCK - Pick a color in the desktop and get the RGB and YMCK code.

Desktop 2 RGB - Pick a color in the desktop and get the RGB code.

ShootIT 1.0 - Screen Capture full and partial screen

[font="'Arial Black';"]Remember Remember The Fifth of November.[/font]

Share this post


Link to post
Share on other sites
Siryx

thanks!

Share this post


Link to post
Share on other sites
Siryx

yeah i read through the helpfiles but i dont know what to do with the array that i get from the filelist

 
#include <File.au3>
#include <Array.au3>
#include <MsgBoxConstants.au3>
 
Example()
 
Func Example()
  
    Local $aFileList = _FileListToArray("D:Music", Default, Default, True)
    If @error = 1 Then
        MsgBox($MB_SYSTEMMODAL, "", "Path was invalid.")
        Exit
    EndIf
    If @error = 4 Then
        MsgBox($MB_SYSTEMMODAL, "", "No file(s) were found.")
        Exit
    EndIf
 
    _ArrayToString($aFileList)
StringReplace($aFileList," - ","-")
EndFunc   ;==>Example
 
yeah this doesnt work. so i get the names in the array and transform them in a string then look for " - " in the string and replace it with "-".
how to write into the attributes?
how to scan for the "-" to put it into the attributes?
Edited by Siryx

Share this post


Link to post
Share on other sites
Jfish

If you just want to find the "-" then look at  StringInStr   it will let you find a string within a string and return the position of the searched term.  The "&" operator will allow you to concatenate strings.  You can use the string trim functions to chop off unwanted parts of the string.


Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Share this post


Link to post
Share on other sites
Siryx

i though of if i can make autoit find the "-" i can take the part in front and after the - and write them down as title of the mp3 and interpret of the mp3, is that possible?

Share this post


Link to post
Share on other sites
JLogan3o13

Yes it is possible, and Jfish gave you the how. Look at StringinStr in the help file:

$sString = "Interpret - Name of Song.mp3"
$iPosition = StringInStr($sString, "-")
    MsgBox(0, "", StringTrimLeft($sString, $iPosition))

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
Siryx

okay thats awesome thx. so i went a step back and forget the whole array thing cause i dont understand it

€: (wrong code deleted)
 
IT WORKED I GOT THE TITLE SEPERATED :D
 
#include <File.au3>
#include <Array.au3>
#include <MsgBoxConstants.au3>






$sString = InputBox("F2","Hello")


$iPosition = StringInStr($sString, " - ")


   $var = StringTrimLeft($sString, $iPosition + 2)
   $title = StringTrimRight($var, 4)
MsgBox(0,"",$title)
gives out the title
#include <File.au3>
#include <Array.au3>
#include <MsgBoxConstants.au3>






$sString = InputBox("F2","Hello")


$iPosition = StringInStr($sString, " - ")


   $var = StringTrimLeft($sString, $iPosition + 2)
   $title = StringTrimRight($var, 4)
MsgBox(0,"",$title)


$iPosition = StringInStr($sString, " - ")


   $interpret = StringTrimRight($sString, $iPosition+ 2)


MsgBox(0,"",$interpret)
 
okay i got both. now how to write them into the file? :$ even if i do it w/ inputbox filename is $sString but i dont come any further cause i dont know the command.. after that i try the array-thingy
 
 
Edited by Siryx

Share this post


Link to post
Share on other sites
sahsanu

Take a look to FileMove() or.. as you are testing, use FileCopy() to keep the original file.

Edit: Reading again your post, it isn't clear to me whether you want to rename the file name or change the Artist/Title tags in mp3 file. If it is the second one, you should take a look to >ID3 UDF

Edited by sahsanu

Share this post


Link to post
Share on other sites
Siryx

yes, i want to edit the ID3 Tags.

i copied them into the include folder and did #include <ID3_v3.4.au3>

hope thats right :D

 

okay there are lots of functions but i cant understand which i need to write the $title as title of the song

and something is wrong with $interpret :$

#include <File.au3>
#include <Array.au3>
#include <MsgBoxConstants.au3>
#include <ID3_v3.4.au3>


$sString = InputBox("F2","Hello")

$iPosition = StringInStr($sString, " - ")

   $var = StringTrimLeft($sString, $iPosition + 2)
   $title = StringTrimRight($var, 4)
MsgBox(0,"Title",$title)



   $interpret = StringTrimRight($sString, $iPosition+ 2)

MsgBox(0,"Interpret",$interpret)




Func _ID3Example_WriteID3NewTitles()



    _ID3ReadTag($sString,3) ;must read in existing tag first to ensure other fields are saved

    _ID3SetTagField("Title",$title)
    _ID3SetTagField("TIT2",$title)

    _ID3WriteTag($Filename) ;by default this will write both ID3v1 and ID3v2

EndFunc
Edited by Siryx

Share this post


Link to post
Share on other sites
Siryx

when i set the occurence to -1 when using stringinstr it should count from right side shouldnt it?

i did it with string reverse now

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.10.2
 Author:         myName

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here

#include <File.au3>
#include <Array.au3>
#include <MsgBoxConstants.au3>
#include <ID3_v3.4.au3>


$sString = InputBox("F2","Hello")

$iPosition = StringInStr($sString, " - ")

   $var = StringTrimLeft($sString, $iPosition + 2)
   $title = StringTrimRight($var, 4)
MsgBox(0,"Title",$title)

#cs
16bit - FRZR9000.mp3
3pm.0009RZRF - tib61
#ce

$sString2 = StringReverse($sString)
$iPosition2 = StringInStr($sString2, " - ")

   $var2 = StringTrimLeft($sString2, $iPosition2)
$interpret = StringTrimLeft($var2,2)

$interpret = StringReverse($interpret)
MsgBox(0,"Interpret",$interpret)

#cs
Func _ID3Example_WriteID3NewTitles()



    _ID3ReadTag($sString,3) ;must read in existing tag first to ensure other fields are saved

    _ID3SetTagField("Title",$title)
    _ID3SetTagField("TIT2",$title)

    _ID3WriteTag($sString) ;by default this will write both ID3v1 and ID3v2

EndFunc
#ce
Edited by Siryx

Share this post


Link to post
Share on other sites
Siryx

can anybody tell me why the part with the writing into the file isnt working? (out of that its in #cs - #ce .. )

Share this post


Link to post
Share on other sites
sahsanu

I never used ID3 UDF nor ID3 tags but after just a quick read (keep this in mind o:)) here you have just an example to work on:

#include <File.au3>
#include <ID3_v3.4.au3>

$aListMP3Files = _FileListToArray(@ScriptDir, "*.mp3")
If @error Then
    ConsoleWrite("Error retrieving file list" & @CRLF)
    Exit
EndIf

For $i = 1 To $aListMP3Files[0]
    $sArtist = StringRegExpReplace($aListMP3Files[$i], "(.+)\s-\s.+", "$1")
    $sTitle = StringRegExpReplace($aListMP3Files[$i], ".+\s-\s(.+)\..*", "$1")
    If $sArtist = $aListMP3Files[$i] Or $sTitle = $aListMP3Files[$i] Then ContinueLoop
    _WriteID3_TitleArtist($aListMP3Files[$i], $sTitle, $sArtist)
    If @error Then ConsoleWrite("Error trying to write ID3 tags in file " & $aListMP3Files[$i] & @CRLF)
Next

Func _WriteID3_TitleArtist($sID3File, $sID3Title, $sID3Artist)
    If $sID3File = Null Or $sID3Title = Null Or $sID3Artist = Null Then Return SetError(1, 1, 1)
    _ID3ReadTag($sID3File, 3) ;must read in existing tag first to ensure other fields are saved
    _ID3SetTagField("Title", $sID3Title)
    _ID3SetTagField("TIT2", $sID3Title)
    _ID3SetTagField("Artist", $sID3Artist)
    _ID3SetTagField("TPE1", $sID3Artist)
    _ID3WriteTag($sID3File) ;by default this will write both ID3v1 and ID3v2
    If @error Then Return SetError(2, 2, 2)
EndFunc   ;==>_WriteID3_TitleArtist

Cheers,

sahsanu

Edited by sahsanu

Share this post


Link to post
Share on other sites
Siryx

I never used ID3 UDF nor ID3 tags but after just a quick read (keep this in mind o:)) here you have just an example to work on:

#include <File.au3>
#include <ID3_v3.4.au3>

$aListMP3Files = _FileListToArray(@ScriptDir, "*.mp3")
If @error Then
    ConsoleWrite("Error retrieving file list" & @CRLF)
    Exit
EndIf

For $i = 1 To $aListMP3Files[0]
    $sArtist = StringRegExpReplace($aListMP3Files[$i], "(.+)\s-\s.+", "$1")
    $sTitle = StringRegExpReplace($aListMP3Files[$i], ".+\s-\s(.+)\..*", "$1")
    If $sArtist = $aListMP3Files[$i] Or $sTitle = $aListMP3Files[$i] Then ContinueLoop
    _WriteID3_TitleArtist($aListMP3Files[$i], $sTitle, $sArtist)
    If @error Then ConsoleWrite("Error trying to write ID3 tags in file " & $aListMP3Files[$i] & @CRLF)
Next

Func _WriteID3_TitleArtist($sID3File, $sID3Title, $sID3Artist)
    If $sID3File = Null Or $sID3Title = Null Or $sID3Artist = Null Then Return SetError(1, 1, 1)
    _ID3ReadTag($sID3File, 3) ;must read in existing tag first to ensure other fields are saved
    _ID3SetTagField("Title", $sID3Title)
    _ID3SetTagField("TIT2", $sID3Title)
    _ID3SetTagField("Artist", $sID3Artist)
    _ID3SetTagField("TPE1", $sID3Artist)
    _ID3WriteTag($sID3File) ;by default this will write both ID3v1 and ID3v2
    If @error Then Return SetError(2, 2, 2)
EndFunc   ;==>_WriteID3_TitleArtist

Cheers,

sahsanu

so this does all that what i am trying to? i dont understand what its doing

StringRegExpReplace($aListMP3Files[$i], "(.+)\s-\s.+", "$1")

what does the [$i] in the string mean?

what is the "(.+)s-s.+", "$1") doing?

actually i dont think i can understand all this with my knowledge. i am doing it with copying the title out of itunes and insert it in the field after.. so its still automated

thx to everybody who tried to help me out - you helped me a lot :)

Edited by Siryx

Share this post


Link to post
Share on other sites
sahsanu

so this does all that what i am trying to? i dont understand what its doing

StringRegExpReplace($aListMP3Files[$i], "(.+)\s-\s.+", "$1")

what does the [$i] in the string mean?

what is the "(.+)s-s.+", "$1") doing?

 

Hello,

As far as I know, yes, the example script I posted should do what you want (read a list of mp3 files and write and ID3 with the Title and Artist readed from their own file name).

The script does:

1.- Get the list of mp3 files in the same folder as the script and put them into an array.

2.- Loop the array extracting the Artist and Title from the mp3 file name and put them into variables.

3.- Inside the loop it also write the ID3 tags for every mp3 found.

Regarding StringRegExpReplace, it's just another approach to extract the artist and title using regular expressions. Of course, you can use your own StrimTrim etc. functions. Here an example:

#include <File.au3>
#include <ID3_v3.4.au3>

$aListMP3Files = _FileListToArray(@ScriptDir, "*.mp3")
If @error Then
    ConsoleWrite("Error retrieving file list" & @CRLF)
    Exit
EndIf

For $i = 1 To $aListMP3Files[0]
    $iPosition = StringInStr($aListMP3Files[$i], " - ")
    $sTemp = StringTrimLeft($aListMP3Files[$i], $iPosition + 2)
    $sTitle = StringTrimRight($sTemp, 4)

    $sTemp = StringReverse($aListMP3Files[$i])
    $iPosition2 = StringInStr($sTemp, " - ")
    $sTemp = StringTrimLeft($sTemp, $iPosition2)
    $sArtist = StringReverse(StringTrimLeft($sTemp, 2))

    If $sArtist = $aListMP3Files[$i] Or $sTitle = $aListMP3Files[$i] Then ContinueLoop
    _WriteID3_TitleArtist($aListMP3Files[$i], $sTitle, $sArtist)
    If @error Then ConsoleWrite("Error trying to write ID3 tags in file " & $aListMP3Files[$i] & @CRLF)
Next

Func _WriteID3_TitleArtist($sID3File, $sID3Title, $sID3Artist)
    If $sID3File = Null Or $sID3Title = Null Or $sID3Artist = Null Then Return SetError(1, 1, 1)
    _ID3ReadTag($sID3File, 3) ;must read in existing tag first to ensure other fields are saved
    _ID3SetTagField("Title", $sID3Title)
    _ID3SetTagField("TIT2", $sID3Title)
    _ID3SetTagField("Artist", $sID3Artist)
    _ID3SetTagField("TPE1", $sID3Artist)
    _ID3WriteTag($sID3File) ;by default this will write both ID3v1 and ID3v2
    If @error Then Return SetError(2, 2, 2)
EndFunc   ;==>_WriteID3_TitleArtist

Regarding your question, What does the [$i] in the string mean?.

$aListMP3Files[] is an array containing the list of mp3 files found on the folder. The $i is a variable assigned in the loop starting from 1, so in every loop $i adds +1, 1, 2, 3, 4, .... so in every loop $aListMP3Files[$i] means that the variable contain the data in the array in position $i. I know may explanation isn't really good so take a look in the help file and search for Array and Loops (that is one the first things you should do if you want to learn to programm with AutoIt).

Regarding, what is the "(.+)s-s.+", "$1") doing?.

That is a Regular Expression and this is the exaplanation:

(.+)\s-\s.+

Match the regex below and capture its match into backreference number 1 «(.+)»
   Match any single character that is NOT a line break character (line feed) «.+»
      Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
Match a single character that is a “whitespace character” (any Unicode separator, tab, line feed, carriage return, vertical tab, form feed, next line) «\s»
Match the character “-” literally «-»
Match a single character that is a “whitespace character” (any Unicode separator, tab, line feed, carriage return, vertical tab, form feed, next line) «\s»
Match any single character that is NOT a line break character (line feed) «.+»
   Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»

$1

Insert the text that was last matched by capturing group number 1 «$1»

Anyway, If you understand StringReverse, StringTrim, etc. functions, go ahead, forgot for now Regular Expressions (you'll have time to learn them in the future).

Cheers,

sahsanu

Share this post


Link to post
Share on other sites
sahsanu

so this does all that what i am trying to? i dont understand what its doing

StringRegExpReplace($aListMP3Files[$i], "(.+)\s-\s.+", "$1")

what does the [$i] in the string mean?

what is the "(.+)s-s.+", "$1") doing?

 

Hello,

As far as I know, yes, the example script I posted should do what you want (read a list of mp3 files and write and ID3 with the Title and Artist readed from their own file name).

The script does:

1.- Get the list of mp3 files in the same folder as the script and put them into an array.

2.- Loop the array extracting the Artist and Title from the mp3 file name and put them into variables.

3.- Inside the loop it also write the ID3 tags for every mp3 found.

Regarding StringRegExpReplace, it's just another approach to extract the artist and title using regular expressions. Of course, you can use your own StrimTrim etc. functions. Here an example:

#include <File.au3>
#include <ID3_v3.4.au3>

$aListMP3Files = _FileListToArray(@ScriptDir, "*.mp3")
If @error Then
    ConsoleWrite("Error retrieving file list" & @CRLF)
    Exit
EndIf

For $i = 1 To $aListMP3Files[0]
    $iPosition = StringInStr($aListMP3Files[$i], " - ")
    $sTemp = StringTrimLeft($aListMP3Files[$i], $iPosition + 2)
    $sTitle = StringTrimRight($sTemp, 4)

    $sTemp = StringReverse($aListMP3Files[$i])
    $iPosition2 = StringInStr($sTemp, " - ")
    $sTemp = StringTrimLeft($sTemp, $iPosition2)
    $sArtist = StringReverse(StringTrimLeft($sTemp, 2))

    If $sArtist = $aListMP3Files[$i] Or $sTitle = $aListMP3Files[$i] Then ContinueLoop
    _WriteID3_TitleArtist($aListMP3Files[$i], $sTitle, $sArtist)
    If @error Then ConsoleWrite("Error trying to write ID3 tags in file " & $aListMP3Files[$i] & @CRLF)
Next

Func _WriteID3_TitleArtist($sID3File, $sID3Title, $sID3Artist)
    If $sID3File = Null Or $sID3Title = Null Or $sID3Artist = Null Then Return SetError(1, 1, 1)
    _ID3ReadTag($sID3File, 3) ;must read in existing tag first to ensure other fields are saved
    _ID3SetTagField("Title", $sID3Title)
    _ID3SetTagField("TIT2", $sID3Title)
    _ID3SetTagField("Artist", $sID3Artist)
    _ID3SetTagField("TPE1", $sID3Artist)
    _ID3WriteTag($sID3File) ;by default this will write both ID3v1 and ID3v2
    If @error Then Return SetError(2, 2, 2)
EndFunc   ;==>_WriteID3_TitleArtist

Regarding your question, What does the [$i] in the string mean?.

$aListMP3Files[] is an array containing the list of mp3 files found on the folder. The $i is a variable assigned in the loop starting from 1, so in every loop $i adds +1, 1, 2, 3, 4, .... so in every loop $aListMP3Files[$i] means that the variable contain the data in the array in position $i. I know may explanation isn't really good so take a look in the help file and search for Array and Loops (that is one the first things you should do if you want to learn to programm with AutoIt).

Regarding, what is the "(.+)s-s.+", "$1") doing?.

That is a Regular Expression and this is the exaplanation:

(.+)\s-\s.+

Match the regex below and capture its match into backreference number 1 «(.+)»
   Match any single character that is NOT a line break character (line feed) «.+»
      Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
Match a single character that is a “whitespace character” (any Unicode separator, tab, line feed, carriage return, vertical tab, form feed, next line) «\s»
Match the character “-” literally «-»
Match a single character that is a “whitespace character” (any Unicode separator, tab, line feed, carriage return, vertical tab, form feed, next line) «\s»
Match any single character that is NOT a line break character (line feed) «.+»
   Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»

$1

Insert the text that was last matched by capturing group number 1 «$1»

Anyway, If you understand StringReverse, StringTrim, etc. functions, go ahead, forgot for now Regular Expressions (you'll have time to learn them in the future).

Cheers,

sahsanu

  • Like 1

Share this post


Link to post
Share on other sites
Siryx

thank you so much ! :)

Share this post


Link to post
Share on other sites
Siryx

after some trying around i found out the program deletes like 50/70% of the complete ID3 tags without setting title or artist. theyre technically blank o.o i tried both scripts so its maybe a bug in the included file 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×