Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

KristaffaH

macrumors newbie
Original poster
Jul 18, 2010
4
0
Hi guys!

Im currently creating a Automator service.

THE GOAL:
1. Right click on a random folder containing videofiles, and run the service.
2. Automator sends only the videofiles (not subtitles ++) from the selected folder to VisualHub for convertion.
3. VisualHub loads presets and decides output location and exports .m4v files ready to play on iphone.
4. Automator copies the subtitle files from the folder (from step 1) to the same output location as VisualHub exports the videoes.
5. Both videoes and subtitles are sent to Subler for soft coding the subtitles on to the videos, and exported again.
6. The finished files are sent to itunes.


THE STATUS:
I have already come a long way. With that i mean people have done a lot of work for me ;)
You see i have found most of the scripting on the web and put it together in automator.
So i have a complete workflow running step 1-4.

This is my current workflow.
1. A script searches through my selected folder, and finds all movie files inside that folder
(script name: "Extract_Movies_Workflow" found on apples sites)
View Script

2.A second script sends this files to VisualHub for convertion, load settings and selects output location
View Script

3. A "Get selected finder items" action choose files from the selected folder in step 1.
(This action does not get its input from the previous actions.)

4. A copy of the "Extract_Movies_Workflow" script, searches through the selected folder,
only this time it looks for subtitle files like .srt, .sub, .idx and .ssa
View Script

5. A "Copy Finder-objects" action copies the subtitle files to the same folder as VisualHub exports its videoes.


THE QUESTION:
Okey so here is where im at. The thing is, im REALY noob at programming.
So i have searched the web for clues on how to code the part where subler loads first a video,
then the subtitle with the same name as the video, exports it and repeats the prosess for all the files in that folder.
Can anyone help me?

Subler has also a CLI version, and their is a help file showing the commands for the CLI version here.
Does this help?


I think i need some part of this code for repeating the action for the whole folder but i can't understand all of what it does?
(of course needs to change finder application, but i mean the "setList" and "repeat" code)

tell application "Finder"
set theList to every file of folder (path to desktop folder as string)
set i to 1
repeat the count of theList times
set theItem to item i of theList as string
--then manipulate it.
set i to i + 1
end repeat
end tell




One of my problems is that i mix bash scripting (which is in Terminal, right?) and apple script. This two languages can't be mixed right?
I realy want to learn the programming stuff, not just copy other peoples work, but its so damn difficult. Can't get my head around it.

Anyway. Hope some of you can help me, I would realy appriciate it!
Thanks alot!
-Kris
 

Awesomeness

macrumors member
Feb 12, 2009
73
0
I'm not sure what you're asking, but here's an explanation to this AppleScript: (I tabbed it so that it makes better sense)

Code:
 tell application "Finder"
	set theList to every file of folder (path to desktop folder as string)
	set i to 1
	repeat the count of theList times
		set theItem to item i of theList as string
		--then manipulate it.
        
		set i to i + 1
	end repeat
end tell

What this AppleScript means is:

Code:
 tell Finder to:
	create a list called theList, which is full of each file in the folder "Users/<yourname>/Desktop"
	set a counter, called i, for looking down theList, starting at 1
		repeat this part right here the length of theList times: (e.g if there)
		make a file called theItem
		set theItem to file number i on the list
		--then manipulate it.  (everything after two dashes in a line is a
		--comment, in it we can say whatever we want, because the
		--computer ignores it.  You use it to explain lines of code and stuff.)
		make i one number higher, so we look at the next file on the list next time around the repeat
	this is the end of the part we repeat over and over.
this is the end of what we tell finder to do.
 

KristaffaH

macrumors newbie
Original poster
Jul 18, 2010
4
0
Thanks Awesomeness! That cleared some things up.
Hehe i wrote a damn long post and didn't even get the question out.

What I meant was this:

Subler is an app which merges video and subtitles into one videofile.
I need to write a script that tells Subler to load every videofile in a specific folder (one at the time) and then merge the belonging subtitle (which has the same name as the videofile) on to that video.

I have thought of two ways to do this:
1. Use Automators "Watch me do" action and load Subler manually, load the video and load the subtitle, BUT how do i repeat this for every file in that folder?
2. Somehow script the commands to load the video and subtitle. This is where i thought maybe the CLI version would help me out. Two of the CLI commands are. How can i get this to work?

-i set input file
The file to which Subler will add things.

-s set subtitle input file
the subtitle file (.srt)

Now i can't even run these commands in Terminal.
I try commands like:

Code:
open -a Subler -i set input file (path to videofile)

But this doesn't work. I'm probably totalty off here. Please help!

Hope i made the question a bit easier to understand.
Thanks
-Kris
 

KristaffaH

macrumors newbie
Original poster
Jul 18, 2010
4
0
I got this code to work in Terminal:

Code:
/Applications/SublerCLI -i /Users/Kristoffer/Desktop/Nitro\ Circus\ S01E01.mp4 -s /Users/Kristoffer/Desktop/Nitro\ Circus\ S01E01.srt

So with this code i managed to load a movie and merge it with its subtitle.
The problem here is that the code above uses specific paths to the files, where i want it to get its input files from a script that searches through a folder and sends all the files in this folder through the merging prosess.
 

DriverJC

macrumors newbie
Aug 8, 2010
1
0
Let me see if I can help you. I know almost nothing about AppleScript but do know bash

I do this exact thing with the exception of the Subtitles. However I use HandbrakeCLI to do the encoding.

Applications in Use:
--HandbrakeCLI
--AtomicParsley32
--SublerCLI

Total of 4 Scripts
--Autorip --> Breaks down the Filename of the movie to get the Encoding Preset for the Encode.
--Tag-Videos --> Breaks down the name of the encoded file to get the Title, Artist, Album, Album Artist, Episode Num, TV Series Name, Date, Rating, Comment, Grouping, Media Kind (STIK), Advisory. it Dumps my DVDPedia Database to get the following: Director, Producer, Description, Cast, Studio, Writer
--Tag-Optimize --> Uses SublerCLI to Optimize the file
--Sync-Library --> Syncs the files to different drives and libraries

--At present I have to call the various scripts each time I want to run them However this is good as it lets me decide when I want to run them. i.e. it will stop the encoding when the current dir is empty so I can reboot and update the OS and such. In order to have them call each other I just have to add the path and script name as the last line in the script

I have attached the scripts I use you should be able to understand how I breakup the filename of the video

My filenaming scheme is
Movie Title - Date - MPAARating - Source - Encoding - Genre - UPC
i.e.
Code:
101 Dalmations - 1961-06-15 - G - DVD - SDAppleTV - Kids & Family - 9780788817250
Source field is either DVD (DVD Movies); Files (Downloaded Files); TVDVD (TV Series); MVDVD (Music Videos)
Encoding field is either SDAppleTV (Standard Def AppleTV); HDAppleTV (High Def AppleTV); iTouch (iPod Touch)

Let me know if you need any clarification

Joel
 

Attachments

  • AutoRip.txt
    9.4 KB · Views: 313
  • tag-videos32.txt
    11.1 KB · Views: 187
  • tag-optimize.txt
    2.5 KB · Views: 150
  • sync-library.txt
    2.9 KB · Views: 175

KristaffaH

macrumors newbie
Original poster
Jul 18, 2010
4
0
Hey DriverJC !

Thanks alot for the work man!
Have you written those scripts yourself? Man those are complicated!

I think this will realy help me.
Like I said before I have all the encoding scripts working, only thing i need is a script for
merging the encoded videoes with its matching subtitle. So my base code will be this:

Code:
/Applications/SublerCLI -i (location of encoded videofile).mp4 
-s (locationn of matching subtitle).srt
I will add som tag codes as well (but the code above is the main code).

What my problem is is that i don't want the location string to be static. I want a code for searching
through a folder and start with the first videofile it finds and repeat the process until it has done the whole folder.

I found this code in your tag-optimize script:

Code:
for SOURCE in $(find * -maxdepth 0 -print); do
#   echo "Optimizing $SOURCE"
   sleep 1

"/Volumes/Mac Pro Storage/0-Applications/./SublerCLI" -i "$SOURCE" -O

This is, at least a part of, the code for determin the source of the process right?
So i can exchange the

Code:
Volumes/Mac Pro Storage/0-Applications/./SublerCLI" -i "$SOURCE"

with:

Code:
/Applications/SublerCLI -i "$SOURCE" -s (???)

But i need an extra code for determin the subtitle source like: subtitle source= same name as -i source but with .srt/.sub ending.


Do you understand what im trying to achieve here?
Thanks alot for you help!
I hope i will get this to work...
-Kris
 

Gallleke

macrumors newbie
Aug 16, 2010
1
0
Mux Srt and Movies Script

I wrote a script for muxing movies and subtitles. Basically, I made folder 'Conversions' with 3 subfolders 'Input', 'Output' and 'Subtitles'. The original movies are in 'Input', the ones converted with Visual Hub in 'Output' and the matching subtitles in 'Subtitles'. My subtitles always have the same name as my movies. To make it work on your mac, you'll have to change the path names.

THE SCRIPT DOESNT PICK THE SUBTITLE WITH THE SAME NAME, IT JUST ADDS THE FIRST SUBTITLE TO THE FIRST VIDEO, AND SO ON...

I'm soon gonna write a script that automates visual hub and subler in one step (quite easy, just use the automator visualhub workflow, then run my script). I made an app out of this now, it's okay (everything is now automated), but I'd like to make it kinda smarter (match subtitles with the filename of the movie, add episode number based on the filename of the movie if its a tv show, keep everything organised in folders in the input and output folders, ...)

To make my folder structure even clearer :

/Users/Home/Desktop/Box/Conversions contains :
  • Input
  • Output
  • Subtitles
  • SublerCLI (= file)
  • Workflow.app (My AppleScript)

Code:
-- Loop through all the converted Finder items and Mux them with the
--	correct .srt file.
tell application "Finder"
	
	-- First we need the applescript notation of the input paths
	set MoviePath to POSIX file "/Users/Home/Desktop/Box/Conversions/Output"
	set SubtitlePath to POSIX file "/Users/Home/Desktop/Box/Conversions/Subtitles"
	
	set MovieInput to every file of folder MoviePath
	set SubtitleInput to every file of folder SubtitlePath
	
	-- We need the shell notation of input paths for the shell script to work
	set MoviePath to POSIX path of MoviePath
	set SubtitlePath to POSIX path of SubtitlePath
	
	-- LOOP
	set i to 1
	repeat the count of MovieInput times
		
		-- CurrentFile is the name of the handled movie
		set CurrentMovie to item i of MovieInput as string
		set CurrentSubtitle to item i of SubtitleInput as string
		
		set MovieFileName to POSIX path of (CurrentMovie)
		set SubtitleFileName to POSIX path of (CurrentSubtitle)
		
		-- Mux the srt with a Shell script
		do shell script "/Users/Home/Desktop/Box/Conversions/SublerCLI -i " & quoted form of MovieFileName & " -s " & quoted form of SubtitleFileName & ""
		
		set i to i + 1
		
	end repeat
	
end tell
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.