Created
July 17, 2011 18:09
-
-
Save barbuza/1087877 to your computer and use it in GitHub Desktop.
tag tv show episodes from <SHOW NAME>_S<SEASON NUM>_E<EPISODE NUM>_<EPISODE ID>
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set seasonNumPattern to "\\d\\d" | |
set episodeNumPattern to "\\d\\d" | |
tell application "iTunes" | |
repeat with I from 1 to count tracks of user playlist "show" | |
set track_ to track I of user playlist "show" | |
set name_ to name of track_ | |
set seasonNum to (find text "(?<=S)(" & seasonNumPattern & ")" in name_ with regexp and string result) as integer | |
set episodeNum to (find text "(?<=E)(" & episodeNumPattern & ")" in name_ with regexp and string result) as integer | |
set showName to change "[[:space:]]+" into " " in (change "[[:punct:]]" into " " in (find text "^(.*)(?=S" & seasonNumPattern & ")" in name_ with regexp and string result) with regexp) with regexp | |
set episodeId to change "^[[:space:]]" into "" in (change "[[:space:]]+" into " " in (change "[[:punct:]]" into " " in (find text "(?<=E" & episodeNumPattern & ")(.*)" in name_ with regexp and string result) with regexp) with regexp) with regexp | |
set video kind of aTrack to TV show | |
set show of aTrack to showName | |
set season number of aTrack to seasonNum | |
set episode number of aTrack to episodeNum | |
set episode ID of aTrack to episodeId | |
end repeat | |
end tell |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment