Sha256: f2a5e3c6617126016b347a9e4fd0f5a99f65c6725a2d95a0d3caabb0c478d58e

Contents?: true

Size: 1.58 KB

Versions: 1

Compression:

Stored size: 1.58 KB

Contents

#!/usr/bin/env ruby

require "rubygems"

$: << File.expand_path("../../lib", __FILE__)

require "subdb"

files = []
video_ext = Subdb::VIDEO_EXTENSIONS.join(",")

$*.each do |path|
  if File.directory?(path)
    path = path.chomp("/")
    files = files.concat(Dir.glob("#{path}/**/*{#{video_ext}}"))
  else
    files << path if Subdb::VIDEO_EXTENSIONS.include?(File.extname(path))
  end
end

files = files.sort

languages = ["pt", "en"]
i = 1

for path in files
  base = File.dirname(path) + "/" + File.basename(path, File.extname(path))
  sub = nil

  for subext in Subdb::SUB_EXTESNIONS
    subpath = base + subext

    if File.exists?(subpath)
      sub = subpath
      break
    end
  end

  puts "Scanning #{path} [#{i}/#{files.length}]"

  begin
    subdb  = Subdb.new(path)
    puts "Hash: #{subdb.hash}"

    remote = subdb.search
    puts (remote ? "Found with languages: #{remote}" : "No subtitle found")

    if sub and !remote
      puts "Local subtitle found and none on server, uploading..."

      begin
        subdb.upload(sub)
        puts "Upload completed"
      rescue
        puts "Error on upload: #{$!}"
      end
    end

    if !sub and remote
      puts "downloading from remote"

      begin
        downloaded = subdb.download(languages)

        if downloaded
          File.open(base + ".srt", "w") do |f|
            f << downloaded
          end

          puts "Download done ok"
        else
          puts "No version for your languages"
        end
      rescue
        puts "Error on download: #{$!}"
      end
    end
  rescue
    puts "Can't open: #{$!}"
  end

  puts

  i += 1
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
subdb-0.1.1 bin/subdb