Thursday, June 2, 2005

Applescript to create Shrook podcast playlist


I have been getting frustrated that the podcasts that were being put into iTunes from Shrook were not being put into a single playlist.  So I have been looking for some solutions.  I first tried to create a smart playlist, but you can not create rules based upon the location of the files.


I have been working on an AppleScript that would automatically copy the tracks from Shrook into a playlist.  Below is what I have come up with so far.


The problem with this implementation is that it iterates over every item in the iTunes Library, so it takes a long time.  I am going to change it so it only iterates over the files that have been downloaded by Shrook






-- Path to the Shrook attachment folder

property pathToShrookAttachments : ""


-- name of the playlist

property podcastPlaylist : ""


if pathToShrookAttachments is "" then

set pathToShrookAttachments to choose folder with prompt "Choose your Shrook Attachments folder" default location ((((path to application support from user domain) as string) & ":Shrook2:Attachments") as alias)

end if


if podcastPlaylist is "" then

set dialogResult to display dialog "What playlist should podcasts be added to?" default answer "Podcast"

if button returned of dialogResult is "OK" then

set podcastPlaylist to text returned of dialogResult

end if

end if


tell application "iTunes"

if not (exists (some playlist whose name is podcastPlaylist)) then

set new_playlist_id to (make new playlist with properties {name:podcastPlaylist})

else

set mySource to container of view of front window

set new_playlist_id to playlist podcastPlaylist of mySource

end if


set trackList to {}

if duration of new_playlist_id is greater than 0 then

set trackList to (get database ID of (every file track of new_playlist_id))

end if

display dialog "Checking tracks..." buttons {""} giving up after 2


repeat with t from 1 to count of every file track of library playlist 1

with timeout of 300000 seconds

try

set aTr to (file track t of library playlist 1)

set trackLoc to location of aTr as string

if ((offset of (pathToShrookAttachments as string) in trackLoc) is 1) then

-- This track came from Shrook

if trackList does not contain aTr's database ID then

-- the track has not been added to playlist

duplicate aTr to new_playlist

end if

end if

end try

end timeout

end repeat


end tell


Technorati Tags:

No comments:

Post a Comment

Seamless Local Control: Integrating WeatherFlow with Home Assistant Across VLANs

I've been pleased with my Home Assistant setup for some time now. One of my main focuses has been achieving local control. This ensures...