Advertisement
applehelpwriter

Episodes.app

Jun 25th, 2013
434
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (*
  2.  
  3. Scripting by Applehelpwriter 2013
  4. http://applehelpwriter.com
  5.  
  6. ******How to use:
  7. Compile in AS Editor, save as an .app
  8.  
  9. *****What it does:
  10. Lets you watch a series in order without you having to remember which episode you watched last.
  11. Set up the Preferences and it will automatically pick the next unwatched episode when you run it.
  12. Can keep track of multiple different series at the same time. Use the 'Watch' folder to choose which series you want at any given time. You can change the 'Watch' folder back to any previously watched series and it will know where you left off (so long as you started watching the series through Episodes.app - if you want it to pick up a series you've already started watching before using Episodes, go into Finder and change the colour label to 'grey' for each movie file that you've already seen; the app will take care of everything after that).
  13.  
  14. ****NOTE
  15. Should only be used with VLC Player - some bugs in QT due to missing codecs in that app
  16.  
  17. ***Known issues:
  18. Some minor bugs still need ironing out; non known as critical to date
  19.  
  20. **Development:
  21. I'm working on a Cocoa version with a prettier interface, so I probably won't do much else with this one. Feel free to adapt it to your own purposes.
  22.  
  23. Phil :)
  24. http://applehelpwriter.com
  25.  
  26.  
  27. *)
  28.  
  29.  
  30. property myName : "episodes"
  31. property theFolder : "Nothing!"
  32. property theApp : "unset.app"
  33. property theMovie : "unset"
  34. property theSeries : ""
  35. property thePlayer : "no player"
  36. property movieList : {}
  37. property myPath : ""
  38. property myList : {}
  39. property seriesValue : 0
  40.  
  41.  
  42. try
  43.     display dialog "What would you like to do?" with title (myName & ".app") buttons {"Cancel", "Preferences", ("Watch " & theSeries)} default button ("Watch " & theSeries) with icon 1
  44.     set dialogResult to the button returned of the result
  45.     if dialogResult = ("Watch " & theSeries) then
  46.         watchIt()
  47.     else
  48.         if dialogResult = "Preferences" then
  49.             setUp()
  50.             watchIt()
  51.         end if
  52.     end if
  53.    
  54.    
  55. on error number -1728
  56.     error number -128
  57. end try
  58.  
  59.  
  60.  
  61.  
  62. on watchIt()
  63.     try
  64.         checkFolder()
  65.         checkSeries()
  66.         checkPlayer()
  67.         checkMovie()
  68.        
  69.         try
  70.             tell application id thePlayer
  71.                 activate
  72.                 open myPath
  73.             end tell
  74.            
  75.         end try
  76.        
  77.         return
  78.     on error number -1728
  79.         error number -128
  80.     end try
  81. end watchIt
  82.  
  83.  
  84. on checkFolder()
  85.     try
  86.         if theFolder = "Nothing!" then
  87.             beep
  88.            
  89.             display dialog "You haven't set a folder to watch yet!" with title (myName & ".app") buttons {"Cancel", "Preferences"} default button "Preferences" with icon 1
  90.            
  91.             set dialogResult to the button returned of the result
  92.             if dialogResult = "Preferences" then
  93.                 setUp()
  94.                
  95.             end if
  96.         else
  97.             return
  98.         end if
  99.     on error number -1728
  100.         error number -128
  101.        
  102.     end try
  103. end checkFolder
  104.  
  105.  
  106. on checkSeries()
  107.     try
  108.         if seriesValue = 0 then
  109.             try
  110.                 display dialog "Currently watching: " & return & return & theFolder & return & return & "Enter a short name for the series:" default answer theSeries buttons {"Cancel", "OK"} default button "OK" with title (myName & ".app") with icon 1
  111.             on error number -128
  112.                 setUp()
  113.             end try
  114.             set theSeries to text returned of the result as string
  115.             set the seriesValue to 1
  116.         end if
  117.        
  118.     on error number -1728
  119.         error number -128
  120.     end try
  121. end checkSeries
  122.  
  123.  
  124. on checkPlayer()
  125.     try
  126.         if thePlayer = "no player" then
  127.             setPlayer()
  128.         else
  129.             display dialog ("Ready to watch " & theSeries & "?") default button "OK" with icon 1
  130.         end if
  131.        
  132.     on error number -1728
  133.         error number -128
  134.     end try
  135. end checkPlayer
  136.  
  137.  
  138.  
  139. on checkMovie()
  140.     try
  141.         tell application "Finder"
  142.             try
  143.                 set myList to the name of every document file of the theFolder whose label index is 0
  144.             on error --error 1
  145.                 (* this whole error block needs fixing before release*)
  146.                 set seriesValue to 0
  147.                 display dialog "No unwatched movies here" buttons {"Cancel", "Preferences"} default button "Preferences" with icon 0
  148.                 set theNextAction to the button returned of the result
  149.                 if theNextAction is "Preferences" then
  150.                     set theFolder to choose folder with prompt "Choose the folder to watch:"
  151.                     try
  152.                         set myList to the name of every document file of the theFolder whose label index is 0
  153.                     on error --error 2
  154.                         display dialog "Still no unwatched movies here!" buttons {"Cancel", "Preferences"} default button "Preferences" with icon 0
  155.                         set theNextAction to the button returned of the result
  156.                         if theNextAction is "Preferences" then
  157.                             set theFolder to choose folder with prompt "Choose the folder to watch:"
  158.                             try
  159.                                 set myList to the name of every document file of the theFolder whose label index is 0
  160.                             on error --error 3
  161.                                 display dialog myName & ".app can't find any movies to play" & return & return & "Quitting — please restart " & myName & " to try again." with icon 0
  162.                             end try
  163.                         end if
  164.                     end try
  165.                 end if
  166.             end try
  167.             set theMovie to item 1 of myList as string
  168.             set myPath to (theFolder & theMovie) as string
  169.             set the label index of the document file theMovie of theFolder to 7
  170.            
  171.         end tell
  172.        
  173.     on error number -1728
  174.         error number -128
  175.     end try
  176. end checkMovie
  177.  
  178.  
  179.  
  180. on setUp()
  181.     try
  182.        
  183.         set optionsList to {"About", "Defaults", "Show settings", "Set Player", "Set Series Name", "Set Watch folder"}
  184.         repeat
  185.             choose from list optionsList with prompt "Choose an item:" with title (myName & ".app") default items "Set Watch Folder"
  186.             set dialogResult to (item 1 of the result)
  187.            
  188.             if dialogResult = "Set Watch folder" then
  189.                 setFolder()
  190.                 exit repeat
  191.             else if dialogResult = "Set Player" then
  192.                 setPlayer()
  193.                 exit repeat
  194.             else if dialogResult = "Set Series Name" then
  195.                 set seriesValue to 0
  196.                 checkSeries()
  197.                 exit repeat
  198.             else if dialogResult = "About" then
  199.                 display dialog ("Sorry, this feature hasn't been implemented yet!") buttons {"OK"} default button 1 with title (myName & ".app") with icon 1
  200.                 setUp()
  201.                 exit repeat
  202.             else if dialogResult = "Show settings" then
  203.                 showSettings()
  204.                 exit repeat
  205.             else if dialogResult = "Defaults" then
  206.                 try
  207.                     display dialog "Return " & myName & ".app to default settings?" buttons {"No", "Yes"} cancel button "No" default button "No" with title (myName & ".app") with icon 2
  208.                 on error number -128
  209.                     setUp()
  210.                     exit repeat
  211.                 end try
  212.                 doReset()
  213.                 setUp()
  214.                 exit repeat
  215.             end if
  216.         end repeat
  217.     on error number -1728
  218.         error number -128
  219.     end try
  220. end setUp
  221.  
  222. on showSettings()
  223.     display dialog ("The current series is " & theSeries & return & "The current player is " & thePlayer & return & "The current folder being watched is " & theFolder & return) buttons {"OK"} default button 1 with title (myName & ".app") with icon 1
  224.     setUp()
  225. end showSettings
  226.  
  227.  
  228.  
  229.  
  230.  
  231. on doReset()
  232.     set the theFolder to "Nothing!"
  233.     set theApp to "unset.app"
  234.     set theMovie to "unset"
  235.     set theSeries to ""
  236.     set thePlayer to "no player"
  237.     set the movieList to {}
  238.     set myPath to ""
  239.     set myList to {}
  240.     set seriesValue to 0
  241.     display dialog myName & ".app has been reset to default settings." & return & return & "Finder labels have not been reset. This must be done manually in Finder." with title (myName & ".app") with icon 1
  242.     return
  243. end doReset
  244.  
  245.  
  246.  
  247. on setFolder()
  248.     try
  249.         set theFolder to choose folder with prompt "Choose the folder to watch:" default location path to "cusr" from the user domain
  250.     on error number -128
  251.         setUp()
  252.     end try
  253. end setFolder
  254.  
  255.  
  256.  
  257.  
  258. on setPlayer()
  259.     try
  260.         try
  261.             set theApp to (choose file with prompt ("Pick the MEDIA PLAYER to use with this folder. Note this does not change your default system media player") of type {"app"} default location path to "apps" from local domain) as text
  262.         on error number -128
  263.             setUp()
  264.         end try
  265.         set thePlayer to the id of application theApp
  266.         if thePlayer = "com.apple.QuickTimePlayerX" then
  267.             display dialog "QuickTime may not be able to play some movie files!" & return & return & myName & " works best with the open source VLC Player instead." with title (myName & ".app") buttons {"Cancel", "Use QT anyway", "Preferences"} default button "Preferences" with icon 2
  268.             set nextAction to the button returned of the result
  269.             if nextAction = "Use QT anyway" then
  270.                 return
  271.             else if nextAction = "Preferences" then
  272.                 setPlayer()
  273.             end if
  274.         end if
  275.         return
  276.     on error number -1728
  277.         error number -128
  278.     end try
  279. end setPlayer
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement