Class: SonyCameraRemoteAPI::Client::Main
- Inherits:
-
Thor
- Object
- Thor
- SonyCameraRemoteAPI::Client::Main
- Includes:
- ConfigUtils, Scripts, Utils
- Defined in:
- lib/sony_camera_remote_api/client/main.rb
Class Method Summary collapse
-
.common_options ⇒ Object
Common options for all shooting modes.
-
.movie_common_options ⇒ Object
Common options for movie/looprec shooting modes.
-
.still_common_options ⇒ Object
Common options for still/intervalstill shooting modes.
Instance Method Summary collapse
- #cont ⇒ Object
- #contents ⇒ Object
- #intrec ⇒ Object
- #liveview ⇒ Object
- #looprec ⇒ Object
- #movie ⇒ Object
- #still ⇒ Object
Methods included from ConfigUtils
default_camera, read_config_file, save_ssdp_config, write_config_file
Methods included from Scripts
connect, connection_script, path, restart_and_connect, root, run_external_command
Methods included from Utils
generate_sequencial_filenames, get_next_file_number, partial_and_unique_match, print_array_in_columns
Class Method Details
.common_options ⇒ Object
Common options for all shooting modes
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 |
# File 'lib/sony_camera_remote_api/client/main.rb', line 264 def self. option :zoom, type: :numeric, desc: 'Zoom position (0-99)', banner: 'POSITION' option :zoom_mode, type: :string, desc: 'Zoom setting', banner: 'MODE' option :focus_mode, type: :string, desc: 'Focus mode', banner: 'MODE' option :exposure, type: :string, desc: 'Exposure mode', banner: 'MODE' option :ev, type: :string, desc: 'Exposure compensation', banner: 'EV' option :fnum, type: :string, desc: 'F number', banner: 'NUM' option :shutter, type: :string, desc: 'Shutter speed', banner: 'NSEC' option :iso, type: :string, desc: 'ISO speed rate', banner: 'NUM' option :wb, type: :string, desc: 'White balance mode', banner: 'MODE' option :temp, type: :numeric, desc: 'Color temperature', banner: 'K' option :scene, type: :string, desc: 'Scene selection', banner: 'MODE' option :flip, type: :string, desc: 'Flip', banner: 'MODE' option :tv, type: :string, desc: 'TV color system', banner: 'MODE' option :ir, type: :string, desc: 'IR remote control', banner: 'MODE' option :apo, type: :string, desc: 'Auto power off', banner: 'MODE' option :beep, type: :string, desc: 'Beep mode', banner: 'MODE' end |
.movie_common_options ⇒ Object
Common options for movie/looprec shooting modes
296 297 298 299 300 301 302 303 304 |
# File 'lib/sony_camera_remote_api/client/main.rb', line 296 def self. option :time, type: :numeric, desc: 'Recording time (sec)', banner: 'NSEC' option :format, type: :string, desc: 'Movie Format', banner: 'MODE' option :quality, type: :string, desc: 'Movie Quality', banner: 'MODE' option :steady, type: :string, desc: 'Steady Mode', banner: 'MODE' option :color, type: :string, desc: 'Color setting', banner: 'MODE' option :noise, type: :string, desc: 'Wind noise reduction', banner: 'MODE' option :audio, type: :string, desc: 'Audio recording', banner: 'MODE' end |
.still_common_options ⇒ Object
Common options for still/intervalstill shooting modes
284 285 286 287 288 289 290 291 292 293 |
# File 'lib/sony_camera_remote_api/client/main.rb', line 284 def self. option :track, type: :string, desc: 'Tracking focus', banner: 'MODE' option :self, type: :numeric, desc: 'Self timer', banner: 'NSEC' option :flash, type: :string, desc: 'Flash mode', banner: 'MODE' option :size, type: :string, desc: 'Still size', banner: 'PIXEL' option :aspect, type: :string, desc: 'Still aspect', banner: 'MODE' option :quality, type: :string, desc: 'Still quality', banner: 'MODE' option :postview, type: :string, desc: 'Postview image size', banner: 'PIXEL' option :angle, type: :numeric, desc: 'View angle', banner: 'DEGREE' end |
Instance Method Details
#cont ⇒ Object
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 |
# File 'lib/sony_camera_remote_api/client/main.rb', line 382 def cont init_camera unless @cam.support_group? :ContShootingMode puts 'This camera does not support continuous shooting mode. Exiting...' exit 1 end @cam.change_function_to_shoot('still', [:mode]) # Set/Get options set_parameter :ContShootingMode, [:mode] set_parameter :ContShootingSpeed, [:speed] if [:setting] get_parameter_and_show :ContShootingMode # ContShootingSpeed API will fail when ContShootingMode = 'Single' get_parameter_and_show :ContShootingSpeed return end @cam.act_zoom absolute: [:zoom] case [:mode] when 'Single', 'MotionShot', 'Burst' @cam.capture_still filename: [:output], transfer: [:transfer] when 'Continuous', 'Spd Priority Cont.' @cam.start_continuous_shooting if [:time] sleep [:time] puts 'Time expired!' else # Continue forever until trapped by SIGINT trapped = false trap(:INT) { trapped = true } puts 'Type C-c (SIGINT) to quit recording.' loop do break if trapped sleep 0.1 end puts 'Trapped!' trap(:INT, 'DEFAULT') end @cam.stop_continuous_shooting prefix: [:output], transfer: [:transfer] end finalize end |
#contents ⇒ Object
599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 |
# File 'lib/sony_camera_remote_api/client/main.rb', line 599 def contents init_camera @cam.change_function_to_transfer puts 'Retrieving...' if [:datelist] dates = @cam.get_date_list date_count: [:count] num_contents = dates.map { |d, c| c }.inject(:+) puts "#{dates.size} date folders / #{num_contents} contents found." puts "Dates\t\tN-Contents" dates.each do |date, count| puts "#{date['title']}\t#{count}" end return end if [:date] contents = @cam.get_content_list type: [:type], date: [:date], sort: [:sort], count: [:count] else contents = @cam.get_content_list type: [:type], sort: [:sort], count: [:count] end if contents.blank? puts 'No contents!' else puts "#{contents.size} contents found." puts "File name\t\tKind\t\tCreated time\t\tURL" contents.each do |c| filename = c['content']['original'][0]['fileName'] kind = c['contentKind'] ctime = c['createdTime'] url = c['content']['original'][0]['url'] puts "#{filename}\t\t#{kind}\t\t#{ctime}\t\t#{url}" end if [:transfer] @cam.transfer_contents contents end if [:delete] answer = $terminal.ask('All contents listed above are deleted. Continue? [y/N]') { |q| q.validate = /[yn]/i; q.default = 'n' } @cam.delete_contents contents if answer == 'y' end end finalize end |
#intrec ⇒ Object
479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 |
# File 'lib/sony_camera_remote_api/client/main.rb', line 479 def intrec init_camera @cam.change_function_to_shoot('intervalstill') # Set/Get options set_parameter :IntervalTime, [:interval] if [:setting] get_parameter_and_show :IntervalTime return end @cam.act_zoom absolute: [:zoom] @cam.start_interval_recording if [:time] sleep [:time] puts 'Time expired!' else # continue forever until trapped by SIGINT trapped = false trap(:INT) { trapped = true } puts 'Type C-c (SIGINT) to quit recording.' loop do break if trapped sleep 0.1 end puts 'Trapped!' trap(:INT, 'DEFAULT') end @cam.stop_interval_recording transfer: [:transfer] finalize end |
#liveview ⇒ Object
565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 |
# File 'lib/sony_camera_remote_api/client/main.rb', line 565 def liveview init_camera # Set/Get options if [:setting] get_parameter_and_show :LiveviewSize return end @cam.act_zoom absolute: [:zoom] th = @cam.start_liveview_thread(time: [:time], size: [:size]) do |img, info| filename = "#{img.sequence_number}.jpg" File.write filename, img.jpeg_data puts "Wrote: #{filename}." end trap(:INT) { th.kill } puts 'Liveview download started. Type C-c (SIGINT) to quit.' th.join trap(:INT, 'DEFAULT') puts 'Finished.' finalize end |
#looprec ⇒ Object
523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 |
# File 'lib/sony_camera_remote_api/client/main.rb', line 523 def looprec init_camera @cam.change_function_to_shoot('looprec') # Set/Get options set_parameter :LoopRecTime, [:loop_time] if [:setting] get_parameter_and_show :LoopRecTime return end @cam.act_zoom absolute: [:zoom] @cam.start_loop_recording if [:time] sleep([:time] * 60) puts 'Time expired!' else # record forever until trapped by SIGINT trapped = false trap(:INT) { trapped = true } puts 'Type C-c (SIGINT) to quit recording.' loop do break if trapped sleep 0.1 end puts 'Trapped!' trap(:INT, 'DEFAULT') end @cam.stop_loop_recording filename: [:output], transfer: [:transfer] finalize end |
#movie ⇒ Object
437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 |
# File 'lib/sony_camera_remote_api/client/main.rb', line 437 def movie init_camera @cam.change_function_to_shoot('movie') # Set/Get options if [:setting] return end @cam.act_zoom absolute: [:zoom] @cam.start_movie_recording if [:time] sleep [:time] puts 'Time expired!' else # record forever until trapped by SIGINT trapped = false trap(:INT) { trapped = true } puts 'Type C-c (SIGINT) to quit recording.' loop do break if trapped sleep 0.1 end puts 'Trapped!' trap(:INT, 'DEFAULT') end @cam.stop_movie_recording filename: [:output], transfer: [:transfer] finalize end |
#still ⇒ Object
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 |
# File 'lib/sony_camera_remote_api/client/main.rb', line 315 def still init_camera @cam.change_function_to_shoot 'still', 'Single' # Set/Get options if [:setting] return end @cam.act_zoom absolute: [:zoom] # Interval option resembles Intervalrec shooting mode. # The advantage is that we can transfer captured stills each time, meanwhile Intervalrec shooting mode cannot. # However, the interval time tends to be longer than that of Intervalrec mode. if [:interval] if [:output] # Generate sequencial filenames based on --output option generator = generate_sequencial_filenames [:output], 'JPG' end # Capture forever until trapped by SIGINT trapped = false trap(:INT) { trapped = true } puts "Capturing stills by #{options[:interval]} sec. Type C-c (SIGINT) to quit capturing." start_time = Time.now loop do loop_start = Time.now if [:output] @cam.capture_still filename: generator.next, transfer: [:transfer] else @cam.capture_still transfer: [:transfer] end if trapped puts 'Trapped!' break end loop_end = Time.now # If total time exceeds, quit capturing. if [:time] && [:time] < loop_end - start_time puts 'Time expired!' break end # Wait until specified interval elapses elapsed = loop_end - loop_start if [:interval] - elapsed > 0 sleep([:interval] - elapsed) end end trap(:INT, 'DEFAULT') else @cam.capture_still filename: [:output], transfer: [:transfer] end finalize end |