Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Region ;**** Directives created by AutoIt3Wrapper_GUI ****
- #AutoIt3Wrapper_icon=1312194893_HP-iTunes-Dock-512.ico
- #AutoIt3Wrapper_UseX64=n
- #AutoIt3Wrapper_Res_Description=Fügt automatisch Lieder zur iTunes Bibliothek hinzu
- #AutoIt3Wrapper_Res_Fileversion=1.0.0.0
- #AutoIt3Wrapper_Res_LegalCopyright=Sumsum
- #AutoIt3Wrapper_Res_Language=1031
- #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
- #include <EditConstants.au3>
- #include <GUIConstantsEx.au3>
- #include <WindowsConstants.au3>
- #include <String.au3>
- #include <Crypt.au3>
- Opt("TrayMenuMode", 3)
- If Not FileExists("updater.exe") Then FileInstall("updater.exe", "updater.exe")
- If Not FileExists("config.ini") Then FileInstall("config.ini", "config.ini")
- ; Updater Update
- _Crypt_Startup()
- $updaterhash = _Crypt_HashFile("updater.exe", $CALG_MD5)
- _Crypt_Shutdown()
- If $updaterhash <> "0xD69BC415C61D414DD69BF01E5065E7CB" Then
- TrayTip("Info","Neue Version des Updaters wurde installiert",20)
- FileDelete("updater.exe")
- FileInstall("updater.exe", "updater.exe")
- EndIf
- RunWait("Updater.exe")
- $itunesxml = IniRead("config.ini", "Einstellungen", "iTunesxml", "error")
- If $itunesxml = "error" Then Exit MsgBox(16, "Fehler", "Die config.ini scheint fehlerhaft zu sein, bitte lösche sie und starte das Tool neu")
- $folder = IniRead("config.ini", "Einstellungen", "folder", "error")
- If $folder = "error" Then Exit MsgBox(16, "Fehler", "Die config.ini scheint fehlerhaft zu sein, bitte lösche sie und starte das Tool neu")
- $playsongs = IniRead("config.ini", "Einstellungen", "playsongs", "error")
- If $playsongs = "error" Then
- IniWrite("config.ini", "Einstellungen", "playsongs", 1)
- $playsongs = 1
- EndIf
- $hidetunes = IniRead("config.ini", "Einstellungen", "hidetunes", "error")
- If $hidetunes = "error" Then
- IniWrite("config.ini", "Einstellungen", "hidetunes", 1)
- $hidetunes = 0
- EndIf
- $firstrun = IniRead("config.ini", "Einstellungen", "firstrun", "error")
- If $firstrun = "error" Then Exit MsgBox(16, "Fehler", "Die config.ini scheint fehlerhaft zu sein, bitte lösche sie und starte das Tool neu")
- If $firstrun = 1 Then
- If FileExists(@UserProfileDir & "\Music\iTunes\iTunes Music Library.xml") Then
- $itunesxml = @UserProfileDir & "\Music\iTunes\iTunes Music Library.xml"
- IniWrite("config.ini", "Einstellungen", "iTunesxml", @UserProfileDir & "\Music\iTunes\iTunes Music Library.xml")
- MsgBox(64, "Info", "Die iTunes Music Library.xml wurde gefunden, du musst in den Einstellungen jetzt nurnoch den zu überwachenden Ordner angeben")
- Else
- MsgBox(64, "Info", "Die iTunes Music Library.xml wurde nicht gefunden, du musst den Ort dieser Datei manuell in den Einstellungen festlegen")
- $itunesxml = ""
- EndIf
- IniWrite("config.ini", "Einstellungen", "firstrun", 0)
- TrayTip("Info", "Von ihr kannst du die Einstellungen öffnen", 20)
- EndIf
- $iTunesApp = ObjCreate("iTunes.Application")
- $tray_settings = TrayCreateItem("Einstellungen")
- $tray_exit = TrayCreateItem("Beenden")
- Global $blacklist = ""
- #Region ### START Koda GUI section ### Form=
- $Form1 = GUICreate("iTunes Auto Adder", 246, 225, 192, 124)
- GUISetFont(9, 400, 0, "Arial")
- $Label1 = GUICtrlCreateLabel("Copyright © Sumsum", 8, 40, 105, 18)
- GUICtrlSetFont(-1, 8, 400, 0, "Arial")
- GUICtrlSetColor(-1, 0x696969)
- $Button1 = GUICtrlCreateButton("Aktivieren", 8, 8, 75, 23, $WS_GROUP)
- GUICtrlSetState(-1, $GUI_DISABLE)
- $Button2 = GUICtrlCreateButton("Deaktivieren", 88, 8, 75, 23, $WS_GROUP)
- $Group1 = GUICtrlCreateGroup("Pfad zur iTunes Library.xml", 8, 64, 225, 49)
- $Input1 = GUICtrlCreateInput("", 16, 80, 177, 23, BitOR($ES_AUTOHSCROLL, $ES_READONLY))
- $Button3 = GUICtrlCreateButton("...", 200, 80, 27, 25, $WS_GROUP)
- GUICtrlCreateGroup("", -99, -99, 1, 1)
- $Group2 = GUICtrlCreateGroup("Der zu überwachende Ordner", 8, 120, 225, 49)
- $Input2 = GUICtrlCreateInput("", 16, 136, 177, 23, BitOR($ES_AUTOHSCROLL, $ES_READONLY))
- $Button4 = GUICtrlCreateButton("...", 200, 136, 27, 25, $WS_GROUP)
- GUICtrlCreateGroup("", -99, -99, 1, 1)
- $Checkbox1 = GUICtrlCreateCheckbox("Lieder nach dem hinzufügen abspielen", 8, 176, 233, 17)
- GUICtrlSetState(-1, $GUI_CHECKED)
- $Checkbox2 = GUICtrlCreateCheckbox("iTunes Fenster verstecken", 8, 200, 233, 17)
- GUISetState(@SW_SHOW)
- #EndRegion ### END Koda GUI section ###
- If $playsongs = 1 Then
- GUICtrlSetState($Checkbox1, $GUI_CHECKED)
- Else
- GUICtrlSetState($Checkbox1, $GUI_UNCHECKED)
- EndIf
- If $hidetunes = 1 Then
- GUICtrlSetState($Checkbox2, $GUI_CHECKED)
- Else
- GUICtrlSetState($Checkbox2, $GUI_UNCHECKED)
- EndIf
- GUICtrlSetData($Input1, $itunesxml)
- GUICtrlSetData($Input2, $folder)
- If $firstrun = 0 Then
- AdlibRegister("_Check", 5000)
- Else
- GUICtrlSetState($Button1, $GUI_ENABLE)
- GUICtrlSetState($Button2, $GUI_DISABLE)
- EndIf
- While 1
- $nMsg = GUIGetMsg()
- Switch $nMsg
- Case $GUI_EVENT_CLOSE
- GUISetState(@SW_HIDE, $Form1)
- Case $Button1
- AdlibRegister("_Check", 5000)
- GUICtrlSetState($Button1, $GUI_DISABLE)
- GUICtrlSetState($Button2, $GUI_ENABLE)
- Case $Button2
- AdlibUnRegister("_Check")
- GUICtrlSetState($Button1, $GUI_ENABLE)
- GUICtrlSetState($Button2, $GUI_DISABLE)
- Case $Button3
- $file = FileOpenDialog("iTunes Music Library.xml", @UserProfileDir, "iTunes Library(iTunes Music Library.xml)")
- If FileExists($file) Then
- $itunesxml = $file
- GUICtrlSetData($Input1, $itunesxml)
- IniWrite("config.ini", "Einstellungen", "iTunesxml", $itunesxml)
- EndIf
- Case $Button4
- $file = FileSelectFolder("iTunes Music Library.xml", "")
- If FileExists($file) Then
- $folder = $file
- GUICtrlSetData($Input2, $folder)
- IniWrite("config.ini", "Einstellungen", "folder", $folder)
- EndIf
- Case $Checkbox1
- If GUICtrlRead($Checkbox1) = $GUI_CHECKED Then
- IniWrite("config.ini", "Einstellungen", "playsongs", 1)
- $playsongs = 1
- Else
- IniWrite("config.ini", "Einstellungen", "playsongs", 0)
- $playsongs = 0
- EndIf
- Case $Checkbox2
- If GUICtrlRead($Checkbox2) = $GUI_CHECKED Then
- $hidetunes = 1
- WinSetState("[CLASS:iTunes]", "", @SW_HIDE)
- IniWrite("config.ini", "Einstellungen", "hidetunes", 1)
- Else
- $hidetunes = 0
- WinSetState("[CLASS:iTunes]", "", @SW_SHOW)
- IniWrite("config.ini", "Einstellungen", "hidetunes", 0)
- EndIf
- EndSwitch
- $tMsg = TrayGetMsg()
- Switch $tMsg
- Case $tray_exit
- Exit
- Case $tray_settings
- GUISetState(@SW_SHOW, $Form1)
- EndSwitch
- WEnd
- Func _Check()
- If Not ProcessExists("iTunes.exe") Then
- $iTunesApp = ObjCreate("iTunes.Application")
- MsgBox(16, "Fehler", "iTunes wurde beendet, es wird nun neugestartet")
- EndIf
- If $itunesxml = "" Then
- AdlibUnRegister("_Check")
- GUICtrlSetState($Button1, $GUI_ENABLE)
- GUICtrlSetState($Button2, $GUI_DISABLE)
- MsgBox(64, "Fehler", "Zuerst muss der Pfad zur iTunes Music Library.xml festgelegt werden")
- GUISetState(@SW_SHOW, $Form1)
- Return 0
- EndIf
- If $folder = "" Then
- AdlibUnRegister("_Check")
- GUICtrlSetState($Button1, $GUI_ENABLE)
- GUICtrlSetState($Button2, $GUI_DISABLE)
- MsgBox(64, "Fehler", "Zuerst musst du den zu überwachenden Ordner einstellen")
- GUISetState(@SW_SHOW, $Form1)
- Return 0
- EndIf
- $tList = _CreateTrackList($itunesxml)
- $search = FileFindFirstFile($folder & "\*.*")
- While 1
- $file = FileFindNextFile($search)
- If @error Then ExitLoop
- If Not @extended = 1 Then
- If Not _Trackexist($tList, $folder & "\" & $file) And Not StringInStr($file, "/") Then
- $ext = _Split_Path_Get_Extension($file)
- If $ext = "mp3" Or $ext = "m4a" Or $ext = "aac" Or $ext = "wma" And Not _IsAdded($file) Then
- TrayTip("Neues Lied", $file & " wurde hinzugefügt", 20)
- _iTunes_AddTrack($folder & "\" & $file)
- $blacklist &= $file
- EndIf
- EndIf
- EndIf
- WEnd
- FileClose($search)
- EndFunc ;==>_Check
- Func _iTunes_AddTrack($path)
- $iTunesApp.PlayFile($path)
- If Not $playsongs Then
- $iTunesApp.Stop()
- EndIf
- EndFunc ;==>_iTunes_AddTrack
- Func _IsAdded($filename)
- Return StringInStr($blacklist, $filename)
- EndFunc ;==>_IsAdded
- Func _Trackexist($tList, $filename)
- Local $exist = 0
- For $i = 0 To UBound($tList) - 1 Step +1
- If StringReplace($tList[$i][1], "/", "\") = $filename Then
- $exist = 1
- ExitLoop
- EndIf
- Next
- Return $exist
- EndFunc ;==>_Trackexist
- Func _Split_Path_Get_Extension($sFilePath)
- Local $BackSlashLast = StringInStr($sFilePath, '\', 0, -1)
- Local $ForwardSlashLoc = StringInStr($sFilePath, '/', 0, -1)
- If $ForwardSlashLoc > $BackSlashLast Then $BackSlashLast = $ForwardSlashLoc
- $Sections = StringTrimLeft($sFilePath, $BackSlashLast)
- Return StringTrimLeft($Sections, StringInStr($Sections, '.'))
- EndFunc ;==>_Split_Path_Get_Extension
- Func _CreateTrackList($ixml)
- Local $tracks[1][2]
- $xmlfile = FileRead($ixml)
- $b1 = _StringBetween($xmlfile, "<key>Track ID</key>", "<key>File Folder Count</key>")
- ReDim $tracks[UBound($b1)][2]
- For $i = 0 To UBound($b1) - 1 Step +1
- $b2 = _StringBetween($b1[$i], "<key>Name</key><string>", "</string>")
- $tracks[$i][0] = $b2[0]
- $b3 = _StringBetween($b1[$i], "<key>Location</key><string>", "</string>")
- $tracks[$i][1] = _ReplaceUZ(StringTrimLeft($b3[0], 17))
- Next
- Return $tracks
- EndFunc ;==>_CreateTrackList
- Func _ReplaceUZ($string)
- $string = StringReplace($string, "%20", " ")
- $string = StringReplace($string, "%C3%BC", "ü")
- $string = StringReplace($string, "%C3%B6", "ö")
- $string = StringReplace($string, "%C3%9F", "ß")
- $string = StringReplace($string, "%C3%A4", "ä")
- $string = StringReplace($string, "%5B", "[")
- $string = StringReplace($string, "%5D", "]")
- Return $string
- EndFunc ;==>_ReplaceUZ
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement