Jump to content

iTunes Playlists


Recommended Posts

Basically, could somebody please tell me how the following would be written in AutoIt

(From the iTunes COM Documentation)

HRESULT IITUserPlaylist::AddTrack  (  [in] VARIANT *  iTrackToAdd,  
  [out, retval] IITTrack **  iAddedTrack 
 )   
 
   Add an existing track to the playlist. 

You cannot use this method to add a CD track (ITTrackKindCD) to another playlist, use IiTunes::ConvertTrack() or IiTunes::ConvertTrack2() instead.

You cannot add a shared library track (ITTrackKindSharedLibrary) to another playist.


Parameters:
 iTrackToAdd  The track to add. This is a VARIANT of type VT_DISPATCH that points to an IITTrack.  
 iAddedTrack  Returns an IITTrack object corresponding to the new track.

So if I have a track selected in iTunes on my iPod, and I get the ObjectID or whatever with the "SelectedTracks" function (that I know how to use), then how would I add it to a Playlist called "1" also on my iPod, when I press the "1" Key on my computer?

By the way, is there a simple way/program for translating WScript and/or Javascript into AutoIt?

Thanks for any help or further suggestions

edit:

I found this also on the net. Also not in autoit but i think it does what i want:

Set objApp = CreateObject("iTunes.Application")
Set colSources = objApp.Sources

Set objSource = colSources.ItemByName("Library")
Set colPlaylists = objSource.Playlists

Set objPlaylist = colPlaylists.ItemByName("My Playlist")

Set objLibrary = objApp.LibraryPlaylist
Set colTracks = objLibrary.Tracks

Set objSong = colTracks.ItemByName("Easy Love")
objPlaylist.AddTrack(objSong)
Edited by yaziquex
Link to comment
Share on other sites

  • Moderators

@LostUser - I used Ulead COOL 3D Production Studio.

---

  • Run this script
  • Select some tracks
  • Press 1, 2, or 3 and the selected tracks will be added to the corresponding playlist.
HotKeySet("1", "_HotKeyFunction")
HotKeySet("2", "_HotKeyFunction")
HotKeySet("3", "_HotKeyFunction")
HotKeySet("{ESC}", "_Exit")

Dim $aPlaylists[4]

$oiTunes = ObjCreate("iTunes.Application")
For $i = 1 To 3
    $aPlaylists[$i] = _iTunesCreatePlaylist($oiTunes, String($i))
Next

While 1
    Sleep(100)
WEnd

Func _HotKeyFunction()
    $i_HotKey = Number(@HotKeyPressed)
    _iTunesPlaylistAddSelectedTracks($oiTunes, $aPlaylists[$i_HotKey])
EndFunc   ;==>_HotKeyFunction

;===============================================================================
;
; Function Name:    _iTunesPlaylistAddSelectedTracks
; Description:      Add selected tracks to the specified playlist.
; Parameter(s):     $o_iTunes       - Object variable of an iTunes.Application Object
;                   $o_iPlaylist    - Object variable of an iTunes.Application, Playlist Object
; Requirement(s):   iTunes 6.0.2 or higher
; Return Value(s):  On Success  - Returns 1, @EXTENDED = Number of tracks added
;                   On Failure  - Returns 0 and sets @ERROR
;                   @ERROR      - 0 = No Error
;                               - 1 = Invalid Data Type ($o_iTunes)
;                               - 2 = Invalid Data Type ($o_iPlaylist)
;                               - 3 = No current track selection
; Author(s):        Bob Anthony (big_daddy)
;
;===============================================================================
;
Func _iTunesPlaylistAddSelectedTracks(ByRef $o_iTunes, ByRef $o_iPlaylist)
    If Not IsObj($o_iTunes) Then Return SetError(1, 0, 0)
    If Not IsObj($o_iPlaylist) Then Return SetError(2, 0, 0)
    
    Local $o_iTrack, $o_iTracks, $i_TrackKind, $i = 0
    
    $o_iTracks = $o_iTunes.SelectedTracks
    If Not IsObj($o_iTracks) Then Return SetError(3, 0, 0)
    
    For $o_iTrack In $o_iTracks
        $i_TrackKind = $o_iTrack.Kind
        Switch $i_TrackKind
            Case 2, 5
                ContinueLoop
        EndSwitch
        $o_iPlaylist.AddTrack ($o_iTrack)
        $i += 1
    Next
    Return SetError(0, $i, 1)
EndFunc   ;==>_iTunesPlaylistAddSelectedTracks

;===============================================================================
;
; Function Name:    _iTunesCreatePlaylist
; Description:      Creates a new playlist in the main library.
; Parameter(s):     $o_iTunes       - Object variable of an iTunes.Application Object
;                   $s_PlaylistName - The name of the new playlist (may be NULL or empty).
; Requirement(s):   iTunes 6.0.2 or higher
; Return Value(s):  On Success  - Returns a playlist object corresponding to the new playlist.
;                   On Failure  - Returns 0 and sets @ERROR
;                   @ERROR      - 0 = No Error
;                               - 1 = Invalid Data Type
;                               - 2 = An unexpected error occurred
; Author(s):        Bob Anthony (big_daddy)
;
;===============================================================================
;
Func _iTunesCreatePlaylist(ByRef $o_iTunes, $s_PlaylistName)
    If Not IsObj($o_iTunes) Then Return SetError(1, 0, 0)
    
    Local $o_iPlaylist
    
    $o_Playlist = $o_iTunes.CreatePlaylist ($s_PlaylistName)
    If Not IsObj($o_Playlist) Then SetError(2, 0, 0)
    
    Return SetError(0, 0, $o_Playlist)
EndFunc   ;==>_iTunesCreatePlaylist

Func _Exit()
    Exit
EndFunc   ;==>_Exit
Link to comment
Share on other sites

Thanks a lot BD that helped heaps.

Another friend I know used ur script nd made this I thought I should put it here if anyone else is interested:

$iPodName = "YAZIQUEX"
$iTunesApp = ObjCreate("iTunes.Application")
$source = $iTunesApp.Sources.ItemByName($iPodName)
$playlists = $source.Playlists
$alreadyinplaylist = 0

HotKeySet("1","_AddTrack1")
HotKeySet("2","_AddTrack2")
HotKeySet("3","_AddTrack3")
HotKeySet("4","_AddTrack4")
HotKeySet("5","_AddTrack5")
HotKeySet("6","_AddTrack6")
HotKeySet("7","_AddTrack7")
HotKeySet("8","_AddTrack8")
HotKeySet("9","_AddTrack9")

While 1
    Sleep(10000)
WEnd

Func _AddTrack1()
    _AddTrack("z1")
EndFunc
Func _AddTrack2()
    _AddTrack("z2")
EndFunc
...and so on untill _AddTrack9()


Func _AddTrack($TargetPlaylist)
    If WinExists("iTunes") Then
    $currenttrack = $iTunesApp.CurrentTrack
    $playlist = $playlists.ItemByName($TargetPlaylist)
            For $track In $playlist.Tracks
                If $track.TrackDatabaseID = $currenttrack.TrackDatabaseID Then $alreadyinplaylist = 1
            Next
            If $alreadyinplaylist = 0 Then $playlist.AddTrack($currenttrack)
            $alreadyinplaylist = 0
    EndIf
EndFunc

I think I'm really getting the hang of this stuff :-)

Link to comment
Share on other sites

  • 1 year later...

How would I modify the following vb script so that it works in AutoIT?

Set objApp = CreateObject("iTunes.Application")

Set colSources = objApp.Sources

Set objSource = colSources.ItemByName("Library")

Set colPlaylists = objSource.Playlists

Set objPlaylist = colPlaylists.ItemByName("Party Shuffle")

objPlaylist.PlayFirstTrack

Link to comment
Share on other sites

How would I modify the following vb script so that it works in AutoIT?

Set objApp = CreateObject("iTunes.Application")

Set colSources = objApp.Sources

Set objSource = colSources.ItemByName("Library")

Set colPlaylists = objSource.Playlists

Set objPlaylist = colPlaylists.ItemByName("Party Shuffle")

objPlaylist.PlayFirstTrack

OK - first line in my attempt to convert and already an error. This seemed like it would have been easy.

Isn't AutoIT's version of the first line somthing like

$iTunesApp = ObjCreate("iTunes.Application")

I get an error that says the command is not valid. Has AutoIt syntax changed?

Please understand I am a rusty programmer. I used to do it alot but have not in years. Times, they have changed.

Link to comment
Share on other sites

To anyone that cares, the error with line 1 was becasue I was using a program that only used the AutoITX DLL which has a VERY limited set of the full AutoIT project. Once I used full AutoIT, the error went away.

The converted script is as follows:

$objApp = ObjCreate("iTunes.Application")

$colSources = $objApp.Sources

$objSource = $colSources.ItemByName("Library")

$colPlaylists = $objSource.Playlists

$objPlaylist = $colPlaylists.ItemByName("Party Shuffle")

$objPlaylist.PlayFirstTrack()

Thank you to all (aka none) that suggested the vbs to au3 conversion program. While it is apparently a dead program (bummer) it worked great for converting this simple script and has worked wonders in helping me start learing AutoIT programming.

Edited by mashenden
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...