class Subfinder::Parser::Subscene

Find related subtitle file from Subscene list page

Constants

DOMAIN

Attributes

Public Class Methods

new(file_name) click to toggle source
# File lib/subfinder/parser/subscene.rb, line 12
def initialize(file_name)
  @file_name = file_name
end

Public Instance Methods

convert_to_code(language) click to toggle source
# File lib/subfinder/parser/subscene.rb, line 82
def convert_to_code(language)
  case language
  when 'Farsi/Persian'
    'fa'
  when 'English'
    'en'
  when 'Arabic'
    'ar'
  when 'French'
    'fr'
  when 'Spanish'
    'es'
  else
    language
  end
  # TODO: add other languages codes
end
get() click to toggle source
# File lib/subfinder/parser/subscene.rb, line 16
def get
  target_uri = find_link(create_links_list(open_online_document(Config.url)))
  Subfinder::Parser::Download.new(find_download_link(open_online_document(DOMAIN + target_uri))).save
end
match_point_for(target) click to toggle source
# File lib/subfinder/parser/subscene.rb, line 55
def match_point_for(target)
  point = 0
  file_name_array = @file_name.split('.')
  # next we want to know if name of the sub is seprataed by . or space
  target_array = target.split('.').size > target.split(' ').size ? target.split('.') : target.split(' ')
  target_array = target_array.map(&:downcase)

  file_name_array.each do |word|
    point += 1 if target_array.include? word.downcase
  end
  (point * 100) / file_name_array.size
end
open_online_document(url) click to toggle source
# File lib/subfinder/parser/subscene.rb, line 21
def open_online_document(url)
  RestClient.get url
rescue StandardError => e
  Logger.info "Error when connecting to '#{url}'\n Error message: #{e}\n".red
  abort('Check your internet connection or VPN and try again')
end