Sign in to follow this  
Followers 0
torels

iPod Transfer

3 posts in this topic

Hi there

I wrote something similar to this some time ago. See here. But honestly I didn't like is very much because of its very low functionality and efficency.

  • It took ages to get the ID3 tags from the files so to copy them
  • It had no GUI because of lazyness and few experience
  • And so on...
But the main problem was Point 1. Fortunately I Found a file named iTunesDB on the iPod and opening it I found out it contained all the info that I precedently retrieved reading ID3 tags (which took loads of time). So after some time spent on analysing the file and (unsuccesfully) searching the forums and the internet I managed to get the infos I needed and to put them in an array. And I wrote this script:

#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <GuiListView.au3>
#include <file.au3>
Dim $pos[5] = [0, 0, 0, 0, 0]
Global $iTunesDBPath
$checked = 1
Opt("TrayAutoPause", 0)
$iTDB = _Get_iPods()
$Gui = GUICreate("iPod Transfer - Home - torels_", 754, 338)

$ListView1 = GUICtrlCreateListView("|Title|Artist|Path", 0, 0, 553, 313, Default, $LVS_EX_CHECKBOXES)
_GUICtrlListView_RegisterSortCallBack($ListView1)
$ChoseDir = GUICtrlCreateButton("...", 736, 104, 17, 18, 0)
$Filename = GUICtrlCreateInput("", 560, 104, 169, 18)
GUICtrlCreateLabel("Save To", 560, 88, 45, 15)
$Search = GUICtrlCreateButton("Search", 568, 216, 169, 25, 0)
$Transfer = GUICtrlCreateButton("Transfer!", 360, 178, 185, 33, 0)
$Progress1 = GUICtrlCreateProgress(0, 318, 553, 17)
$Progress2 = GUICtrlCreateProgress(558, 318, 754 - 558, 17)
$Info = GUICtrlCreateButton("Info", 568, 248, 169, 25, 0)
$Status = GUICtrlCreateLabel("Connected to " & DriveGetLabel(StringLeft($iTunesDBPath, 3)), 560, 24, 192, 57)
$rArtist = GUICtrlCreateRadio("Artist", 568, 272)
$rTitle = GUICtrlCreateRadio("Title", 568, 292)
$rAll = GUICtrlCreateRadio("All", 680, 272)
ControlHide($Gui, "", $rArtist)
ControlHide($Gui, "", $rTitle)
ControlHide($Gui, "", $rAll)
ControlShow($Gui, "", $Transfer)
GUISetState(@SW_SHOW, $Gui)

_Fill($iTDB, $ListView1)
GUICtrlSetPos($Transfer, 568, 178, 169, 25)
;GUICtrlSetPos($Progress1,0, 520, 553, 17)

While 1
    Switch GUIGetMsg($Gui)
        Case - 3
            Exit
        Case $Search
            $Mode = ""
            If GUICtrlRead($rAll) = $GUI_CHECKED Then $Mode = "All"
            If GUICtrlRead($rTitle) = $GUI_CHECKED Then $Mode = "Title"
            If GUICtrlRead($rArtist) = $GUI_CHECKED Then $Mode = "Artist"
            If $Mode = "" Then $Mode = "All"
            $KeyWord = InputBox("Search", "Search Keywords. Blank for all!", "", "", -1, 200)
            If @error Then ContinueLoop
            $hSearch = _Search($KeyWord, $iTDB, $Mode)
            _Fill($hSearch, $ListView1)
        Case $ListView1
            If GUICtrlGetState($ListView1) = 0 Then
                If $checked = 1 Then
                    ;_Fill($iTDB, $ListView1, 0)
                    $ct = _GUICtrlListView_GetItemCount($ListView1)
                    For $i = 0 To $ct
                        _GUICtrlListView_SetItemChecked($ListView1, $i, False)
                    Next
                    $checked = 0
                Else
                    $ct = _GUICtrlListView_GetItemCount($ListView1)
                    For $i = 0 To $ct
                        _GUICtrlListView_SetItemChecked($ListView1, $i, True)
                    Next
                    $checked = 1
                EndIf
            Else
                _GUICtrlListView_BeginUpdate($ListView1)
                _GUICtrlListView_SortItems($ListView1, GUICtrlGetState($ListView1))
                _GUICtrlListView_EndUpdate($ListView1)
                ;_ArraySort($iTDB, 0,0,0,GUICtrlGetState($ListView1))
                ;_Fill($iTDB, $ListView1)
            EndIf
        Case $ChoseDir
            $hFile = FileSelectFolder("Save to...", @DesktopDir, 1 + 2)
            If @error Then ContinueLoop
            GUICtrlSetData($Filename, $hFile)
        Case $Transfer
            $path = GUICtrlRead($Filename)
            If StringRight($path, 1) = "\" Then $path = StringLeft($path, StringLen($path) - 1)
            If StringStripWS($path, 4) = "" Then
                MsgBox(64, "iPod Transfer", "Please select a Pah where to save the files you will transfer!")
                ContinueLoop
            EndIf
            If Not FileExists($path) Then 
                $confirm = MsgBox(4 + 48, "iPod Tranfer", "The directory """ & $path & """ does not exist. Do you wish to create the directory now in order to Transfer the files from your iPod?")
                If $confirm = 7 Then
                    MsgBox(64, "Information", "The file copy has been cancelled!")
                    ContinueLoop
                EndIf
            EndIf
            $ct = _GUICtrlListView_GetItemCount($ListView1) - 1
            If FileExists($path) Then
                For $i = 0 To $ct
                    $From = _GUICtrlListView_GetItemText($ListView1, $i, 3)
                    $Title = _GUICtrlListView_GetItemText($ListView1, $i, 1)
                    $Artist = _GUICtrlListView_GetItemText($ListView1, $i, 2)
                    If _GUICtrlListView_GetItemChecked($ListView1, $i) = $GUI_CHECKED Then
                        FileCopy(StringLeft($iTunesDBPath, 2) & $From, $path & "\" & $Artist & "\" & $Title & " - " & $Artist & StringRight($From, 4), 8 + 1)
                        GUICtrlSetData($Status, "Copying File """ & $Title & " - " & $Artist & """. File " & $i & " of " & $ct & "." & @CRLF & Floor($i * 100 / $ct) & "%")
                    EndIf
                    GUICtrlSetData($Progress1, $i * 100 / $ct)
                Next
                GUICtrlSetData($Progress1, 0)
                GUICtrlSetData($Status, "Connected to " & DriveGetLabel(StringLeft($iTunesDBPath, 3)))
            Else
                GUICtrlSetData($Status, $path & """ is not a valid path!""")
                Sleep(2000)
                GUICtrlSetData($Status, "Connected to " & DriveGetLabel(StringLeft($iTunesDBPath, 3)))
            EndIf
        Case $Info
            MsgBox(0, "iPod Transfer", "Powered and developed by torels_ under GNU GPL license." & _
                    @CRLF & "iPod Transfer v2. For Info and Support please visit http://torels.altervista.org")
    EndSwitch
    $np = GUIGetCursorInfo($Gui)
    If $pos[4] <> $np[4] Then
        $pos = GUIGetCursorInfo($Gui)
        Switch $pos[4]
            Case $Transfer
                GUICtrlSetPos($Transfer, 560, 178, 185, 33)
                GUICtrlSetPos($Search, 568, 216, 169, 25)
                GUICtrlSetPos($Info, 568, 248, 169, 25)
                ControlHide($Gui, "", $rArtist)
                ControlHide($Gui, "", $rTitle)
                ControlHide($Gui, "", $rAll)
            Case $Search
                GUICtrlSetPos($Transfer, 568, 178, 169, 25)
                GUICtrlSetPos($Search, 560, 216 - 7, 185, 33)
                GUICtrlSetPos($Info, 568, 248, 169, 25)
                ControlShow($Gui, "", $rArtist)
                ControlShow($Gui, "", $rTitle)
                ControlShow($Gui, "", $rAll)
            Case $Info
                GUICtrlSetPos($Transfer, 568, 178, 169, 25)
                GUICtrlSetPos($Search, 568, 216, 169, 25)
                GUICtrlSetPos($Info, 560, 248, 185, 33)
                ControlHide($Gui, "", $rArtist)
                ControlHide($Gui, "", $rTitle)
                ControlHide($Gui, "", $rAll)
        EndSwitch
    EndIf
WEnd

Func _Get_iPods()
    Local $ComboString
    $StartGui = GUICreate("iPod Transfer", 200, 80)
    $Combo = GUICtrlCreateCombo("Select Your iPod", 5, 5, 190)
    $OK = GUICtrlCreateButton("Select iPod", 100 - 190 / 2, 40, 190, 30)
    $List = DriveGetDrive("Removable")
    For $i = 1 To UBound($List) - 1
        If DriveStatus($List[$i]) = "Ready" Then
            If FileExists($List[$i] & "\" & "iPod_Control\iTunes\iTunesDB") Then $ComboString &= StringUpper($List[$i]) & "\ - " & DriveGetLabel($List[$i]) & "|"
        EndIf
    Next
    GUISetState()
    GUICtrlSetData($Combo, $ComboString)
    While 1
        Switch GUIGetMsg()
            Case - 3
                Exit
            Case $OK
                If FileExists(StringLeft(GUICtrlRead($Combo), 3)) Then
                    $iTunesDBPath = StringLeft(GUICtrlRead($Combo), 3) & "iPod_Control\iTunes\iTunesDB"
                    GUIDelete($StartGui)
                    $iTDB = _Read_iPod(_iTunesDB_Read($iTunesDBPath))
                    ExitLoop
                Else
                    MsgBox(16, "Error", """" & GUICtrlRead($Combo) & """ is not a valid iPod Device!")
                EndIf
        EndSwitch
    WEnd
    Return $iTDB
EndFunc   ;==>_Get_iPods

Func _Fill($iTDB, $LV, $sel = 1)
    _GUICtrlListView_BeginUpdate($LV)
    _GUICtrlListView_DeleteAllItems($LV)
    If $sel = 1 Then $sel = $GUI_CHECKED
    If $sel <> 1 Then $sel = $GUI_UNCHECKED
    $UBound = UBound($iTDB) - 1
    For $i = 1 To $UBound
        GUICtrlCreateListViewItem("|" & $iTDB[$i][1] & "|" & $iTDB[$i][2] & "|" & $iTDB[$i][0], $LV)
        GUICtrlSetState(-1, $sel)
        GUICtrlSetData($Progress1, $i * 100 / $UBound)
    Next
    GUICtrlSendMsg($ListView1, 0x101E, 0, 20)
    GUICtrlSendMsg($ListView1, 0x101E, 1, 150)
    GUICtrlSendMsg($ListView1, 0x101E, 2, 200)
    GUICtrlSendMsg($ListView1, 0x101E, 3, 149)
    _GUICtrlListView_EndUpdate($LV)
    GUICtrlSetData($Progress1, 0)
EndFunc   ;==>_Fill

Func _Search($KeyWord, $iTDB, $Mode = "Title", $ExactMatch = 0)
    Local $aRet[1][3]
    If StringStripWS($KeyWord, 8) = "" Or $KeyWord = "*" Then Return $iTDB
    Switch $Mode
        Case "Title"
            $Mode = 1
        Case "Artist"
            $Mode = 2
        Case "All"
            $Mode = 3
    EndSwitch
    $Size = UBound($iTDB) - 1
    ProgressOn("iPod Transfer v2", "Searching...")
    If $Mode < 3 Then ;Artist | Title
        For $i = 0 To UBound($iTDB) - 1
            ProgressSet($i * 100 / $Size, $i & " Entries Searched")
            If $ExactMatch = 1 Then
                If $iTDB[$i][$Mode] = $KeyWord Then
                    ReDim $aRet[UBound($aRet) + 1][3]
                    $aRet[UBound($aRet) - 1][0] = $iTDB[$i][0]
                    $aRet[UBound($aRet) - 1][1] = $iTDB[$i][1]
                    $aRet[UBound($aRet) - 1][2] = $iTDB[$i][2]
                EndIf
            Else
                If StringInStr($iTDB[$i][$Mode], $KeyWord, 0) Then
                    ReDim $aRet[UBound($aRet) + 1][3]
                    $aRet[UBound($aRet) - 1][0] = $iTDB[$i][0]
                    $aRet[UBound($aRet) - 1][1] = $iTDB[$i][1]
                    $aRet[UBound($aRet) - 1][2] = $iTDB[$i][2]
                EndIf
            EndIf
        Next
    Else
        For $i = 0 To UBound($iTDB) - 1
            ProgressSet($i * 100 / $Size, $i & " Entries Searched")
            If $ExactMatch = 1 Then
                If $iTDB[$i][1] = $KeyWord Or $iTDB[$i][2] = $KeyWord Then
                    ReDim $aRet[UBound($aRet) + 1][3]
                    $aRet[UBound($aRet) - 1][0] = $iTDB[$i][0]
                    $aRet[UBound($aRet) - 1][1] = $iTDB[$i][1]
                    $aRet[UBound($aRet) - 1][2] = $iTDB[$i][2]
                EndIf
            Else
                If StringInStr($iTDB[$i][1], $KeyWord) Or StringInStr($iTDB[$i][2], $KeyWord) Then
                    ReDim $aRet[UBound($aRet) + 1][3]
                    $aRet[UBound($aRet) - 1][0] = $iTDB[$i][0]
                    $aRet[UBound($aRet) - 1][1] = $iTDB[$i][1]
                    $aRet[UBound($aRet) - 1][2] = $iTDB[$i][2]
                EndIf
            EndIf
        Next
    EndIf
    ProgressOff()
    ;_ArrayDisplay($aRet)
    Return $aRet
EndFunc   ;==>_Search

Func _Read_iPod($iTunesDB)
    Local $aData[1][3]
    $Curr_Title = $iTunesDB[2]
    $Curr_Artist = $iTunesDB[3]
    $Drive = StringLeft($iTunesDB[0], 2)
    ProgressOn("iPod Transfer", "Scanning Your iPod...")
    $s = UBound($iTunesDB) - 1
    For $i = 2 To UBound($iTunesDB) - 1
        ProgressSet($i * 100 / $s, $i & " Entries Read")
        $Plus = 1
        If StringLeft($iTunesDB[$i], 1) = "\" Then
            $Size = UBound($aData)
            ReDim $aData[$Size + 1][3]
            $aData[$Size][0] = StringLeft($iTunesDB[$i], 32)
            $aData[$Size][1] = $Curr_Title
            $aData[$Size][2] = $Curr_Artist
            If StringLen($iTunesDB[$i]) > 32 Then $Plus = 0
            If StringInStr($iTunesDB[$i + 1 + $Plus], "mhit") Then $Plus = 2
            $Curr_Title = $iTunesDB[$i + 1 + $Plus]
            $Curr_Artist = $iTunesDB[$i + 2 + $Plus]
        EndIf
    Next
    $aData[0][0] = UBound($iTunesDB) - 1 ;files in iPod (Including Videos)
    ProgressOff()
    ;_ArrayDisplay($aData)
    Return $aData
EndFunc   ;==>_Read_iPod

Func _iTunesDB_Read($iTunesDB)
    ;Tested on iPod 5.5G (iPod Video)
    $StopAt = 0
    $Read = _RemoveNuls($iTunesDB)
    $label = DriveGetLabel(StringLeft($iTunesDB, 3))
    $s = StringSplit($Read, "mhod", 1) ;subdivide every value of the DB (contained in a <mhod> XML tag)
    For $i = 0 To UBound($s) - 1 ;Throw away any extra rubbish chars
        $r = StringStripWS($s[$i], 1)
        If StringInStr($r, "iPod_Control") Then $r = StringReplace($r, ":", "\")
        $r = StringRight($r, StringLen($r) - 6)
        If $r = $label Then
            $StopAt = $i
            ExitLoop ;When Drive label is reached... Stop!
        EndIf
        $s[$i] = $r
    Next
    ReDim $s[$StopAt]
    $s[0] = $iTunesDB
    ;_ArrayDisplay($s) ; --> Debbugging Use Only
    Return $s
EndFunc   ;==>_iTunesDB_Read

Func _RemoveNuls($inFile)
    $hFile = FileOpen($inFile, 0)
    $vRead = FileRead($hFile)
    FileClose($hFile)
    $vWrite = StringReplace($vRead, Chr(0x0), "") ;<- This!
    Return $vWrite
EndFunc   ;==>_RemoveNuls

Func OnAutoItExit()
    _GUICtrlListView_UnRegisterSortCallBack($ListView1)
EndFunc   ;==>OnAutoItExit

Thanks to PsaltyDS and Trancexxx for the _RemoveNuls() function, which took quite a while to understand XD

The main features include Searching, a Selective copy of the files, a GUI enlisting all the files on the iPod and an Artist and Title Subdivision of these files.

It works perfectly with files added by iTunes, but doesn't with those added by floola :P

This script has been tested on a 5.5G iPod (iPod Video) but it should work with other versions too. If someone wants to test it on other iPod versions too it would be great :)

any suggestions and improvements are well accepted :)


Some Projects:[list][*]ZIP UDF using no external files[*]iPod Music Transfer [*]iTunes UDF - fully integrate iTunes with au3[*]iTunes info (taskbar player hover)[*]Instant Run - run scripts without saving them before :)[*]Get Tube - YouTube Downloader[*]Lyric Finder 2 - Find Lyrics to any of your song[*]DeskBox - A Desktop Extension Tool[/list]indifference will ruin the world, but in the end... WHO CARES :P---------------http://torels.altervista.org

Share this post


Link to post
Share on other sites



69 views and no reply ? :)

hasn't anyone tried the code ?


Some Projects:[list][*]ZIP UDF using no external files[*]iPod Music Transfer [*]iTunes UDF - fully integrate iTunes with au3[*]iTunes info (taskbar player hover)[*]Instant Run - run scripts without saving them before :)[*]Get Tube - YouTube Downloader[*]Lyric Finder 2 - Find Lyrics to any of your song[*]DeskBox - A Desktop Extension Tool[/list]indifference will ruin the world, but in the end... WHO CARES :P---------------http://torels.altervista.org

Share this post


Link to post
Share on other sites

Once again, thanks for sharing!

Will check it out when I get the chance ... and are particularly interested in going the other way - to the iPod.


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

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  
Followers 0