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

bob5731

macrumors regular
Original poster
Jun 27, 2008
120
1
handbrake auto

I'm ripping dvd to my NAS then win does move to the NAS
How do i fix it?
How I add code to move it to my NAS?

https://github.com/rfletcher/handbrake-auto

code is =
tell application "/Applications/HandBrake.app"

set scriptname to "/Users/bob/Desktop/handbrake-auto-master/handbrake.rb"

set scriptlog to "~/Library/Logs/" & scriptname & ".log"


do shell script "echo 'starting up...' >>" & scriptlog

do shell script "~/usr/local/bin" & scriptname & " &>>" & scriptlog & " &"

end tell

Script Error
HandBrake got an error: sh: /Users/bob/Users/bob/Library/Logs/Users/bob/Desktop/handbrake-auto-master/handbrake.rb.log: No such file or directory

Wed Jan 3 16:23:33 CST 2018
starting up...
 
Last edited:
This line...
set scriptlog to "~/Library/Logs/" & scriptname & ".log"

Is producing the bad file path in this error...
HandBrake got an error: sh: /Users/bob/Users/bob/Library/Logs/Users/bob/Desktop/handbrake-auto-master/handbrake.rb.log: No such file or directory

As for the rest of the question, I try not to use Applescript for the bulk of my logic. It's a lot easier in Ruby or Python. But to do it, you are going to need to find something that lets you mount the network drive (if it isn't already mounted), find it's path, and then issue a copy command to copy the file to the destination.

I've got my own scripts, but they don't do any sort of auto-copying for me like you are trying to do. My end goals are usually to handle embedding of chapter and iTunes metadata for me in a more automated way.
 
I have 1000 dvd that I'm copying to my mac the to the NAS.
Applescript or automator but I do not know how to do it.

code is =
tell application "/Applications/HandBrake.app"

set scriptname to "handbrake.rb"

set scriptlog to "~/MAC HD/Library/Logs/" & scriptname & ".log"


do shell script "date >>" & scriptlog

do shell script "echo 'starting up...' >>" & scriptlog


do shell script "~/bin/" & scriptname & " &>>" & scriptlog & " &"

do shell script "~/usr/local/bin" & scriptname & " &>>" & scriptlog & " &"

end tell


Script Error
HandBrake got an error: date: illegal time format
usage: date [-jnu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
[-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]

code is in Ruby =
require "enumerator"
mode = "auto" # auto | movie | tv
# config
$handbrake_bin = "~/bin/handbrake"
$input_device = "/dev/disk1"
$output_dir = "~/Movies"
$output_format = "m4v"
# greatest allowed pct. difference between two longest titles on a tv disc
$max_tv_title_differential = 0.1
$min_tv_duration = 540 # 20 minutes
$handbrake_opts = [
"-i " + $input_device,
"--preset Default",
"--native-language eng",
]
def eject_dvd
system("drutil eject")
$?.exitstatus == 0
end
def get_dvd_label
`/sbin/mount | /usr/bin/grep #{$input_device}`.gsub(/.*(\/Volumes\/.*) \(.*/, '\1').chop().split('/').last()
end
def get_rip_mode
durations = get_titles.collect { |title|
title[:duration]
}.sort.reverse
if durations.length > 1 && (1 - (durations[1].to_f / durations[0].to_f)) <= $max_tv_title_differential
mode = "tv"
else
mode = "movie"
end
end
def get_episode_titles
get_titles().find_all { |title|
title[:duration] > $min_tv_duration
}
end
def get_output_file
index = 0
begin
output_file = File.expand_path($output_dir) + "/" + get_dvd_label() + "-" + (index += 1).to_s + "." + $output_format
end while File.exists?(output_file)
output_file
end
def get_titles
titles = []
title = nil
# `cat ~/tv.txt`.each_line do |line|
rip(["--title 0"], true).each_line do |line|
if title && line.match(/^[^\s]/)
titles << title
title = nil
end
if matches = line.match(/^\+\s+title\s+(\d+)/)
title = { :number => matches[1].to_i }
elsif matches = line.match(/\s+duration:\s([\d:]+)/):
title[:duration] = parse_duration matches[1]
end
end
titles
end
def parse_duration(str)
values = [
{ :s => 1 },
{ :m => 60 },
{ :h => 3600 },
{ :d => 86400 }
]
str.split(':').reverse.to_enum:)each_with_index).collect do |chunk, index|
chunk.to_i * values[index].values.first
end.inject do |sum, seconds|
sum + seconds
end
end
def rip(opts = [], return_output = false)
command = [
"/opt/local/bin/nice -n 20",
File.expand_path($handbrake_bin),
$handbrake_opts,
opts
]
command = command.flatten.join(' ')
puts "Running: #{command}"
if return_output
`#{command} 2>&1`
else
system(command)
end
end
begin
if mode == "auto"
mode = get_rip_mode
end
if mode == "movie"
rip [
"--longest",
"-o \"#{get_output_file()}\""
]
elsif mode == "tv"
get_episode_titles.each do |title|
rip [
"--title #{title[:number]}",
"-o \"#{get_output_file()}\""
]
end
end
rescue
nil
end
eject_dvd()
 
Last edited:
Please post the log file. What happens when you run the Ruby script in Terminal. The Running: lines might be useful for problem solving.

Example :
Code:
Johns-Mac:~ kryten$ ruby bin/handbrake.rb
Running: /Users/kryten/bin/HandBrakeCLI -i /dev/disk3 --preset Normal --native-language eng --title 0
Running: /Users/kryten/bin/HandBrakeCLI -i /dev/disk3 --preset Normal --native-language eng -o "/Users/kryten/Movies/Blade Runner.m4v"
[00:06:08] hb_init: starting libhb thread
[00:06:08] thread 700000081000 started ("libhb")
HandBrake 1.0.7 (2017040900) - Darwin x86_64 - https://handbrake.fr
2 CPUs detected

Info : https://forums.macrumors.com/thread...-backup-encoding-tagging-for-mac-os-x.805573/
 
Last edited:
I got the code from github.

libdvdcss.pkg will not insatll.

/usr/local/bin/handbrake.rb:11: syntax error, unexpected '~', expecting end-of-input

$output_dir = "~/Users/bob/Movies/Video”
 
Last edited:
I got the code from github.

libdvdcss.pkg will not insatll.

/usr/local/bin/handbrake.rb:11: syntax error, unexpected '~', expecting end-of-input

$output_dir = "~/Users/bob/Movies/Video”
I've used the files from github for testing on El Capitan 10.11.6.
Change this :
Code:
$output_dir = "~/Users/bob/Movies/Video”
to this:
Code:
$output_dir = "~/Movies/Video”
Try again.
 
/Users/bob/Desktop/handbrake-auto-master/handbrake.rb:9: unknown regexp options - lcal

/Users/bob/Desktop/handbrake-auto-master/handbrake.rb:9: syntax error, unexpected tSTRING_BEG, expecting keyword_do or '{' or '('

/Users/bob/Desktop/handbrake-auto-master/handbrake.rb:14: syntax error, unexpected tIDENTIFIER, expecting end-of-input

$output_format = "m4v"
 
Last edited:
What version of macOS are you using? You seem to be running two different handbrake.rb scripts.
Code:
/usr/local/bin/handbrake.rb
and
Code:
/Users/bob/Desktop/handbrake-auto-master/handbrake.rb
Stick to one. Please attach the script to your post. You can also attach a screenshot of your Terminal app when you run the script.
 
Os x 10.11.06

I do TI work. But I can not program a mac.

Code:
#!/usr/bin/ruby

require "enumerator"

mode = "auto" # auto | movie | tv

# config

$handbrake_bin = “~/usr/local/binhandbrake"
$input_device = “/dev/disk2”


$output_dir = “~/Movies/Video”
$output_format = "m4v"
# greatest allowed pct. difference between two longest titles on a tv disc
$max_tv_title_differential = 0.1
$min_tv_duration = 540 # 20 minutes

$handbrake_opts = [
  "-i " + $input_device,
  "--preset Default",
  "--native-language eng",
]

def eject_dvd
  system("drutil eject")
  $?.exitstatus == 0
end

def get_dvd_label
  `/sbin/mount | /usr/bin/grep #{$input_device}`.gsub(/.*(\/Volumes\/.*) \(.*/, '\1').chop().split('/').last()
end

def get_rip_mode
  durations = get_titles.collect { |title|
    title[:duration]
  }.sort.reverse

  if durations.length > 1 && (1 - (durations[1].to_f / durations[0].to_f)) <= $max_tv_title_differential
    mode = "tv"
  else
    mode = "movie"
  end
end

def get_episode_titles
  get_titles().find_all { |title|
    title[:duration] > $min_tv_duration
  }
end

def get_output_file
  index = 0
  begin
    output_file = File.expand_path($output_dir) + "/" + get_dvd_label() + "-" + (index += 1).to_s + "." + $output_format
  end while File.exists?(output_file)
  output_file
end

def get_titles
  titles = []
  title = nil

  # `cat ~/tv.txt`.each_line do |line|
  rip(["--title 0"], true).each_line do |line|
    if title && line.match(/^[^\s]/)
      titles << title
      title = nil
    end

    if matches = line.match(/^\+\s+title\s+(\d+)/)
      title = { :number => matches[1].to_i }
    elsif matches = line.match(/\s+duration:\s([\d:]+)/):
      title[:duration] = parse_duration matches[1]
    end
  end

  titles
end

def parse_duration(str)
  values = [
    { :s => 1 },
    { :m => 60 },
    { :h => 3600 },
    { :d => 86400 }
  ]

  str.split(':').reverse.to_enum(:each_with_index).collect do |chunk, index|
    chunk.to_i * values[index].values.first
  end.inject do |sum, seconds|
    sum + seconds
  end
end

def rip(opts = [], return_output = false)
  command = [
    "/opt/local/bin/nice -n 20",
    File.expand_path($handbrake_bin),
    $handbrake_opts,
    opts
  ]

  command = command.flatten.join(' ')

  puts "Running: #{command}"

  if return_output
    `#{command} 2>&1`
  else
    system(command)
  end
end


begin
  if mode == "auto"
    mode = get_rip_mode
  end

  if mode == "movie"
    rip [
      "--longest",
      "-o \"#{get_output_file()}\""
    ]
  elsif mode == "tv"
    get_episode_titles.each do |title|
      rip [
        "--title #{title[:number]}",
        "-o \"#{get_output_file()}\""
      ]
    end
  end
rescue
  nil
end

eject_dvd()
 

Attachments

  • Screen Shot 2018-01-08 at 5.18.49 PM.png
    Screen Shot 2018-01-08 at 5.18.49 PM.png
    78.6 KB · Views: 136
  • Screen Shot 2018-01-08 at 5.22.25 PM.png
    Screen Shot 2018-01-08 at 5.22.25 PM.png
    104.7 KB · Views: 165
Last edited:
Might be a typo but this can't be right. Do those folders really exist? I'm guessing from your previous post that you log on as user bob so this :

Code:
$handbrake_bin = “~/usr/local/binhandbrake"
translates to :
Code:
$handbrake_bin = “/Users/bob/usr/local/binhandbrake"
There's a missing forward slash as well. So change to :
Code:
$handbrake_bin = "/usr/local/bin/handbrake"

I just noticed that there's a mixture of smart quotes and normal quotes. Everything needs to be in normal quotes eg ""
Can you spot the difference?
Code:
$handbrake_bin = “~/usr/local/binhandbrake"
$input_device = “/dev/disk2”
$output_dir = “~/Movies/Video”

Please post the ouput when you run this in Terminal :

Code:
ls -al /Users/bob/Desktop/handbrake-auto-master/handbrake.rb

Run the Ruby script like this :
Code:
ruby /Users/bob/Desktop/handbrake-auto-master/handbrake.rb

Forget about the AppleScript part for now.
 
I'm user bob.

I have done the code like

$handbrake_bin = “/Users/bob/usr/local/binhandbrake"
$input_device = “/dev/disk2”
$output_dir = “~/Movies/Video”
$output_format = "m4v"
and like
$handbrake_bin = “~/usr/local/binhandbrake"
$input_device = “/dev/disk2”
$output_dir = “~/Movies/Video”
$output_format = "m4v"

I get the some errors

Code:
#!/usr/bin/ruby

require "enumerator"

mode = "auto" # auto | movie | tv

# config

$handbrake_bin = “~/usr/local/binhandbrake"
$input_device = “/dev/disk2”
$output_dir = “~/Movies/Video”
$output_format = "m4v"

# greatest allowed pct. difference between two longest titles on a tv disc
$max_tv_title_differential = 0.1
$min_tv_duration = 540 # 20 minutes

$handbrake_opts = [
  "-i " + $input_device,
  "--preset Default",
  "--native-language eng",
]

def eject_dvd
  system("drutil eject")
  $?.exitstatus == 0
end

def get_dvd_label
  `/sbin/mount | /usr/bin/grep #{$input_device}`.gsub(/.*(\/Volumes\/.*) \(.*/, '\1').chop().split('/').last()
end

def get_rip_mode
  durations = get_titles.collect { |title|
    title[:duration]
  }.sort.reverse

  if durations.length > 1 && (1 - (durations[1].to_f / durations[0].to_f)) <= $max_tv_title_differential
    mode = "tv"
  else
    mode = "movie"
  end
end

def get_episode_titles
  get_titles().find_all { |title|
    title[:duration] > $min_tv_duration
  }
end

def get_output_file
  index = 0
  begin
    output_file = File.expand_path($output_dir) + "/" + get_dvd_label() + "-" + (index += 1).to_s + "." + $output_format
  end while File.exists?(output_file)
  output_file
end

def get_titles
  titles = []
  title = nil

  # `cat ~/tv.txt`.each_line do |line|
  rip(["--title 0"], true).each_line do |line|
    if title && line.match(/^[^\s]/)
      titles << title
      title = nil
    end

    if matches = line.match(/^\+\s+title\s+(\d+)/)
      title = { :number => matches[1].to_i }
    elsif matches = line.match(/\s+duration:\s([\d:]+)/):
      title[:duration] = parse_duration matches[1]
    end
  end

  titles
end

def parse_duration(str)
  values = [
    { :s => 1 },
    { :m => 60 },
    { :h => 3600 },
    { :d => 86400 }
  ]

  str.split(':').reverse.to_enum(:each_with_index).collect do |chunk, index|
    chunk.to_i * values[index].values.first
  end.inject do |sum, seconds|
    sum + seconds
  end
end

def rip(opts = [], return_output = false)
  command = [
    "/opt/local/bin/nice -n 20",
    File.expand_path($handbrake_bin),
    $handbrake_opts,
    opts
  ]

  command = command.flatten.join(' ')

  puts "Running: #{command}"

  if return_output
    `#{command} 2>&1`
  else
    system(command)
  end
end


begin
  if mode == "auto"
    mode = get_rip_mode
  end

  if mode == "movie"
    rip [
      "--longest",
      "-o \"#{get_output_file()}\""
    ]
  elsif mode == "tv"
    get_episode_titles.each do |title|
      rip [
        "--title #{title[:number]}",
        "-o \"#{get_output_file()}\""
      ]
    end
  end
rescue
  nil
end

eject_dvd()
 

Attachments

  • Screen Shot 2018-01-09 at 9.48.25 AM.png
    Screen Shot 2018-01-09 at 9.48.25 AM.png
    50.7 KB · Views: 136
Last edited:
Can you fix it for me?

^[[ALast login: Wed Jan 10 22:57:39 on ttys000

iMac:~ bob$ ls -al /Users/bob/Desktop/handbrake-auto-master/handbrake.rb

-rwxr-xr-x@ 1 bob staff 2644 Jan 10 23:16 /Users/bob/Desktop/handbrake-auto-master/handbrake.rb

iMac:~ bob$ ruby /Users/bob/Desktop/handbrake-auto-master/handbrake.rb

/Users/bob/Desktop/handbrake-auto-master/handbrake.rb:10: syntax error, unexpected '~', expecting end-of-input

$output_dir = "~/Users/bob/Movies/video“

^

iMac:~ bob$
 
Last edited:
I've been trying to help you to fix it yourself but you keep posting the same mistakes. If you're having difficulties in understanding the help given please say so. The code snippet below has normal quotes. Please make the necessary changes between the quotes and use in the handbrake.rb script. Good luck.

Code:
$handbrake_bin = ""
$input_device = ""
$output_dir = ""
$output_format = ""

Please reread the posts I made.
 
I have difficulties in understanding normal quotes and smart quotes. Are talking about
Single and Double Quotation?

I fix it up to Movies.
 
Last edited:
How I'm get
Win i run it through rubymine.
it is ejecting dvd

Code:
#!/usr/bin/ruby

require "enumerator"

mode = "auto" # auto | movie | tv

# config
$handbrake_bin = "~/bin/handbrake"
$input_device = "/dev/disk2"
$output_dir = "~/Movies"
$output_format = "m4v"

# greatest allowed pct. difference between two longest titles on a tv disc
$max_tv_title_differential = 0.1
$min_tv_duration = 540 # 20 minutes

$handbrake_opts = [
  "-i " + $input_device,
  "--preset Default",
  "--native-language eng",
]

def eject_dvd
  system("drutil eject")
  $?.exitstatus == 0
end

def get_dvd_label
  `/sbin/mount | /usr/bin/grep #{$input_device}`.gsub(/.*(\/Volumes\/.*) \(.*/, '\1').chop().split('/').last()
end

def get_rip_mode
  durations = get_titles.collect { |title|
    title[:duration]
  }.sort.reverse

  if durations.length > 1 && (1 - (durations[1].to_f / durations[0].to_f)) <= $max_tv_title_differential
    mode = "tv"
  else
    mode = "movie"
  end
end

def get_episode_titles
  get_titles().find_all { |title|
    title[:duration] > $min_tv_duration
  }
end

def get_output_file
  index = 0
  begin
    output_file = File.expand_path($output_dir) + "/" + get_dvd_label() + "-" + (index += 1).to_s + "." + $output_format
  end while File.exists?(output_file)
  output_file
end

def get_titles
  titles = []
  title = nil

  # `cat ~/tv.txt`.each_line do |line|
  rip(["--title 0"], true).each_line do |line|
    if title && line.match(/^[^\s]/)
      titles << title
      title = nil
    end

    if matches = line.match(/^\+\s+title\s+(\d+)/)
      title = { :number => matches[1].to_i }
    elsif matches = line.match(/\s+duration:\s([\d:]+)/);
        title[:duration] = parse_duration matches[1]
    end
  end

  titles
end

def parse_duration(str)
  values = [
      { :s => 1 },
      { :m => 60 },
      { :h => 3600 },
      { :d => 86400 }
  ]

  str.split(':').reverse.to_enum(:each_with_index).collect do |chunk, index|
    chunk.to_i * values[index].values.first
  end.inject do |sum, seconds|
    sum + seconds
  end
end

def rip(opts = [], return_output = false)
  command = [
      "/opt/local/bin/nice -n 20",
      File.expand_path($handbrake_bin),
      $handbrake_opts,
      opts
  ]

  command = command.flatten.join(' ')

  puts "Running: #{command}"

  if return_output
    `#{command} 2>&1`
  else
    system(command)
  end
end


begin
  if mode == "auto"
    mode = get_rip_mode
  end

  if mode == "movie"
    rip [
            "--longest",
            "-o \"#{get_output_file()}\""
        ]
  elsif mode == "tv"
    get_episode_titles.each do |title|
      rip [
              "--title #{title[:number]}",
              "-o \"#{get_output_file()}\""
          ]
    end
  end
rescue
  nil
end

eject_dvd()

/usr/bin/ruby -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) /Users/bob/Desktop/handbrake-auto-master/handbrake.rb
Running: /opt/local/bin/nice -n 20 /Users/bob/bin/handbrake -i /dev/disk2 --preset Default --native-language eng --title 0
Running: /opt/local/bin/nice -n 20 /Users/bob/bin/handbrake -i /dev/disk2 --preset Default --native-language eng --longest -o "/Users/bob/Movies/FLIGHT_OF_THE_NAVIGATOR-1.m4v"
sh: /opt/local/bin/nice: No such file or directory

Process finished with exit code 0
 

Attachments

  • Screen Shot 2018-01-11 at 12.30.12 PM.png
    Screen Shot 2018-01-11 at 12.30.12 PM.png
    218.7 KB · Views: 292
Last edited:
elsif matches = line.match(/\s+duration:\s([\d:]+)/): need to be a ;

then the code will eject dvd.

I'm ripping dvd the
Eject dvd then ripping dvd
In m4v format.
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.