Advertisement
Guest User

iTunes Auto Adder.au3

a guest
Aug 2nd, 2011
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 9.51 KB | None | 0 0
  1. #Region ;**** Directives created by AutoIt3Wrapper_GUI ****
  2. #AutoIt3Wrapper_icon=1312194893_HP-iTunes-Dock-512.ico
  3. #AutoIt3Wrapper_UseX64=n
  4. #AutoIt3Wrapper_Res_Description=Fügt automatisch Lieder zur iTunes Bibliothek hinzu
  5. #AutoIt3Wrapper_Res_Fileversion=1.0.0.0
  6. #AutoIt3Wrapper_Res_LegalCopyright=Sumsum
  7. #AutoIt3Wrapper_Res_Language=1031
  8. #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
  9. #include <EditConstants.au3>
  10. #include <GUIConstantsEx.au3>
  11. #include <WindowsConstants.au3>
  12. #include <String.au3>
  13. #include <Crypt.au3>
  14.  
  15. Opt("TrayMenuMode", 3)
  16.  
  17. If Not FileExists("updater.exe") Then FileInstall("updater.exe", "updater.exe")
  18. If Not FileExists("config.ini") Then FileInstall("config.ini", "config.ini")
  19. ; Updater Update
  20. _Crypt_Startup()
  21. $updaterhash = _Crypt_HashFile("updater.exe", $CALG_MD5)
  22. _Crypt_Shutdown()
  23. If $updaterhash <> "0xD69BC415C61D414DD69BF01E5065E7CB" Then
  24.     TrayTip("Info","Neue Version des Updaters wurde installiert",20)
  25.     FileDelete("updater.exe")
  26.     FileInstall("updater.exe", "updater.exe")
  27. EndIf
  28.  
  29. RunWait("Updater.exe")
  30.  
  31. $itunesxml = IniRead("config.ini", "Einstellungen", "iTunesxml", "error")
  32. If $itunesxml = "error" Then Exit MsgBox(16, "Fehler", "Die config.ini scheint fehlerhaft zu sein, bitte lösche sie und starte das Tool neu")
  33.  
  34. $folder = IniRead("config.ini", "Einstellungen", "folder", "error")
  35. If $folder = "error" Then Exit MsgBox(16, "Fehler", "Die config.ini scheint fehlerhaft zu sein, bitte lösche sie und starte das Tool neu")
  36.  
  37. $playsongs = IniRead("config.ini", "Einstellungen", "playsongs", "error")
  38. If $playsongs = "error" Then
  39.     IniWrite("config.ini", "Einstellungen", "playsongs", 1)
  40.     $playsongs = 1
  41. EndIf
  42.  
  43. $hidetunes = IniRead("config.ini", "Einstellungen", "hidetunes", "error")
  44. If $hidetunes = "error" Then
  45.     IniWrite("config.ini", "Einstellungen", "hidetunes", 1)
  46.     $hidetunes = 0
  47. EndIf
  48.  
  49. $firstrun = IniRead("config.ini", "Einstellungen", "firstrun", "error")
  50. If $firstrun = "error" Then Exit MsgBox(16, "Fehler", "Die config.ini scheint fehlerhaft zu sein, bitte lösche sie und starte das Tool neu")
  51.  
  52. If $firstrun = 1 Then
  53.     If FileExists(@UserProfileDir & "\Music\iTunes\iTunes Music Library.xml") Then
  54.         $itunesxml = @UserProfileDir & "\Music\iTunes\iTunes Music Library.xml"
  55.         IniWrite("config.ini", "Einstellungen", "iTunesxml", @UserProfileDir & "\Music\iTunes\iTunes Music Library.xml")
  56.         MsgBox(64, "Info", "Die iTunes Music Library.xml wurde gefunden, du musst in den Einstellungen jetzt nurnoch den zu überwachenden Ordner angeben")
  57.     Else
  58.         MsgBox(64, "Info", "Die iTunes Music Library.xml wurde nicht gefunden, du musst den Ort dieser Datei manuell in den Einstellungen festlegen")
  59.         $itunesxml = ""
  60.     EndIf
  61.     IniWrite("config.ini", "Einstellungen", "firstrun", 0)
  62.     TrayTip("Info", "Von ihr kannst du die Einstellungen öffnen", 20)
  63. EndIf
  64.  
  65. $iTunesApp = ObjCreate("iTunes.Application")
  66.  
  67. $tray_settings = TrayCreateItem("Einstellungen")
  68. $tray_exit = TrayCreateItem("Beenden")
  69.  
  70. Global $blacklist = ""
  71.  
  72.  
  73. #Region ### START Koda GUI section ### Form=
  74. $Form1 = GUICreate("iTunes Auto Adder", 246, 225, 192, 124)
  75. GUISetFont(9, 400, 0, "Arial")
  76. $Label1 = GUICtrlCreateLabel("Copyright © Sumsum", 8, 40, 105, 18)
  77. GUICtrlSetFont(-1, 8, 400, 0, "Arial")
  78. GUICtrlSetColor(-1, 0x696969)
  79. $Button1 = GUICtrlCreateButton("Aktivieren", 8, 8, 75, 23, $WS_GROUP)
  80. GUICtrlSetState(-1, $GUI_DISABLE)
  81. $Button2 = GUICtrlCreateButton("Deaktivieren", 88, 8, 75, 23, $WS_GROUP)
  82. $Group1 = GUICtrlCreateGroup("Pfad zur iTunes Library.xml", 8, 64, 225, 49)
  83. $Input1 = GUICtrlCreateInput("", 16, 80, 177, 23, BitOR($ES_AUTOHSCROLL, $ES_READONLY))
  84. $Button3 = GUICtrlCreateButton("...", 200, 80, 27, 25, $WS_GROUP)
  85. GUICtrlCreateGroup("", -99, -99, 1, 1)
  86. $Group2 = GUICtrlCreateGroup("Der zu überwachende Ordner", 8, 120, 225, 49)
  87. $Input2 = GUICtrlCreateInput("", 16, 136, 177, 23, BitOR($ES_AUTOHSCROLL, $ES_READONLY))
  88. $Button4 = GUICtrlCreateButton("...", 200, 136, 27, 25, $WS_GROUP)
  89. GUICtrlCreateGroup("", -99, -99, 1, 1)
  90. $Checkbox1 = GUICtrlCreateCheckbox("Lieder nach dem hinzufügen abspielen", 8, 176, 233, 17)
  91. GUICtrlSetState(-1, $GUI_CHECKED)
  92. $Checkbox2 = GUICtrlCreateCheckbox("iTunes Fenster verstecken", 8, 200, 233, 17)
  93. GUISetState(@SW_SHOW)
  94. #EndRegion ### END Koda GUI section ###
  95.  
  96. If $playsongs = 1 Then
  97.     GUICtrlSetState($Checkbox1, $GUI_CHECKED)
  98. Else
  99.     GUICtrlSetState($Checkbox1, $GUI_UNCHECKED)
  100. EndIf
  101.  
  102. If $hidetunes = 1 Then
  103.     GUICtrlSetState($Checkbox2, $GUI_CHECKED)
  104. Else
  105.     GUICtrlSetState($Checkbox2, $GUI_UNCHECKED)
  106. EndIf
  107.  
  108. GUICtrlSetData($Input1, $itunesxml)
  109. GUICtrlSetData($Input2, $folder)
  110. If $firstrun = 0 Then
  111.     AdlibRegister("_Check", 5000)
  112. Else
  113.     GUICtrlSetState($Button1, $GUI_ENABLE)
  114.     GUICtrlSetState($Button2, $GUI_DISABLE)
  115. EndIf
  116.  
  117. While 1
  118.     $nMsg = GUIGetMsg()
  119.     Switch $nMsg
  120.         Case $GUI_EVENT_CLOSE
  121.             GUISetState(@SW_HIDE, $Form1)
  122.         Case $Button1
  123.             AdlibRegister("_Check", 5000)
  124.             GUICtrlSetState($Button1, $GUI_DISABLE)
  125.             GUICtrlSetState($Button2, $GUI_ENABLE)
  126.         Case $Button2
  127.             AdlibUnRegister("_Check")
  128.             GUICtrlSetState($Button1, $GUI_ENABLE)
  129.             GUICtrlSetState($Button2, $GUI_DISABLE)
  130.         Case $Button3
  131.             $file = FileOpenDialog("iTunes Music Library.xml", @UserProfileDir, "iTunes Library(iTunes Music Library.xml)")
  132.             If FileExists($file) Then
  133.                 $itunesxml = $file
  134.                 GUICtrlSetData($Input1, $itunesxml)
  135.                 IniWrite("config.ini", "Einstellungen", "iTunesxml", $itunesxml)
  136.             EndIf
  137.         Case $Button4
  138.             $file = FileSelectFolder("iTunes Music Library.xml", "")
  139.             If FileExists($file) Then
  140.                 $folder = $file
  141.                 GUICtrlSetData($Input2, $folder)
  142.                 IniWrite("config.ini", "Einstellungen", "folder", $folder)
  143.             EndIf
  144.         Case $Checkbox1
  145.             If GUICtrlRead($Checkbox1) = $GUI_CHECKED Then
  146.                 IniWrite("config.ini", "Einstellungen", "playsongs", 1)
  147.                 $playsongs = 1
  148.             Else
  149.                 IniWrite("config.ini", "Einstellungen", "playsongs", 0)
  150.                 $playsongs = 0
  151.             EndIf
  152.         Case $Checkbox2
  153.             If GUICtrlRead($Checkbox2) = $GUI_CHECKED Then
  154.                 $hidetunes = 1
  155.                 WinSetState("[CLASS:iTunes]", "", @SW_HIDE)
  156.                 IniWrite("config.ini", "Einstellungen", "hidetunes", 1)
  157.             Else
  158.                 $hidetunes = 0
  159.                 WinSetState("[CLASS:iTunes]", "", @SW_SHOW)
  160.                 IniWrite("config.ini", "Einstellungen", "hidetunes", 0)
  161.             EndIf
  162.     EndSwitch
  163.     $tMsg = TrayGetMsg()
  164.     Switch $tMsg
  165.         Case $tray_exit
  166.             Exit
  167.         Case $tray_settings
  168.             GUISetState(@SW_SHOW, $Form1)
  169.     EndSwitch
  170.  
  171. WEnd
  172.  
  173. Func _Check()
  174.     If Not ProcessExists("iTunes.exe") Then
  175.         $iTunesApp = ObjCreate("iTunes.Application")
  176.         MsgBox(16, "Fehler", "iTunes wurde beendet, es wird nun neugestartet")
  177.     EndIf
  178.     If $itunesxml = "" Then
  179.         AdlibUnRegister("_Check")
  180.         GUICtrlSetState($Button1, $GUI_ENABLE)
  181.         GUICtrlSetState($Button2, $GUI_DISABLE)
  182.         MsgBox(64, "Fehler", "Zuerst muss der Pfad zur iTunes Music Library.xml festgelegt werden")
  183.         GUISetState(@SW_SHOW, $Form1)
  184.         Return 0
  185.     EndIf
  186.     If $folder = "" Then
  187.         AdlibUnRegister("_Check")
  188.         GUICtrlSetState($Button1, $GUI_ENABLE)
  189.         GUICtrlSetState($Button2, $GUI_DISABLE)
  190.         MsgBox(64, "Fehler", "Zuerst musst du den zu überwachenden Ordner einstellen")
  191.         GUISetState(@SW_SHOW, $Form1)
  192.         Return 0
  193.     EndIf
  194.     $tList = _CreateTrackList($itunesxml)
  195.     $search = FileFindFirstFile($folder & "\*.*")
  196.     While 1
  197.         $file = FileFindNextFile($search)
  198.         If @error Then ExitLoop
  199.         If Not @extended = 1 Then
  200.             If Not _Trackexist($tList, $folder & "\" & $file) And Not StringInStr($file, "/") Then
  201.                 $ext = _Split_Path_Get_Extension($file)
  202.                 If $ext = "mp3" Or $ext = "m4a" Or $ext = "aac" Or $ext = "wma" And Not _IsAdded($file) Then
  203.                     TrayTip("Neues Lied", $file & " wurde hinzugefügt", 20)
  204.                     _iTunes_AddTrack($folder & "\" & $file)
  205.                     $blacklist &= $file
  206.                 EndIf
  207.             EndIf
  208.         EndIf
  209.     WEnd
  210.     FileClose($search)
  211. EndFunc   ;==>_Check
  212.  
  213. Func _iTunes_AddTrack($path)
  214.     $iTunesApp.PlayFile($path)
  215.     If Not $playsongs Then
  216.         $iTunesApp.Stop()
  217.     EndIf
  218. EndFunc   ;==>_iTunes_AddTrack
  219.  
  220. Func _IsAdded($filename)
  221.     Return StringInStr($blacklist, $filename)
  222. EndFunc   ;==>_IsAdded
  223.  
  224. Func _Trackexist($tList, $filename)
  225.     Local $exist = 0
  226.     For $i = 0 To UBound($tList) - 1 Step +1
  227.         If StringReplace($tList[$i][1], "/", "\") = $filename Then
  228.             $exist = 1
  229.             ExitLoop
  230.         EndIf
  231.     Next
  232.     Return $exist
  233. EndFunc   ;==>_Trackexist
  234.  
  235. Func _Split_Path_Get_Extension($sFilePath)
  236.     Local $BackSlashLast = StringInStr($sFilePath, '\', 0, -1)
  237.     Local $ForwardSlashLoc = StringInStr($sFilePath, '/', 0, -1)
  238.     If $ForwardSlashLoc > $BackSlashLast Then $BackSlashLast = $ForwardSlashLoc
  239.     $Sections = StringTrimLeft($sFilePath, $BackSlashLast)
  240.     Return StringTrimLeft($Sections, StringInStr($Sections, '.'))
  241. EndFunc   ;==>_Split_Path_Get_Extension
  242.  
  243. Func _CreateTrackList($ixml)
  244.     Local $tracks[1][2]
  245.     $xmlfile = FileRead($ixml)
  246.     $b1 = _StringBetween($xmlfile, "<key>Track ID</key>", "<key>File Folder Count</key>")
  247.     ReDim $tracks[UBound($b1)][2]
  248.     For $i = 0 To UBound($b1) - 1 Step +1
  249.         $b2 = _StringBetween($b1[$i], "<key>Name</key><string>", "</string>")
  250.         $tracks[$i][0] = $b2[0]
  251.         $b3 = _StringBetween($b1[$i], "<key>Location</key><string>", "</string>")
  252.         $tracks[$i][1] = _ReplaceUZ(StringTrimLeft($b3[0], 17))
  253.     Next
  254.     Return $tracks
  255. EndFunc   ;==>_CreateTrackList
  256.  
  257. Func _ReplaceUZ($string)
  258.     $string = StringReplace($string, "%20", " ")
  259.     $string = StringReplace($string, "%C3%BC", "ü")
  260.     $string = StringReplace($string, "%C3%B6", "ö")
  261.     $string = StringReplace($string, "%C3%9F", "ß")
  262.     $string = StringReplace($string, "%C3%A4", "ä")
  263.     $string = StringReplace($string, "%5B", "[")
  264.     $string = StringReplace($string, "%5D", "]")
  265.     Return $string
  266. EndFunc   ;==>_ReplaceUZ
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement