class Subfinder::Parser::Subscene
Find related subtitle file from Subscene
list page
Constants
- DOMAIN
Attributes
link[R]
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
create_links_list(page)
click to toggle source
# File lib/subfinder/parser/subscene.rb, line 68 def create_links_list(page) array = [] doc = Nokogiri::HTML(page) doc.xpath('//table//tr').each do |link| next if link.xpath('./td/a/span/text()')[0].nil? # language array << [convert_to_code(link.xpath('./td/a/span/text()')[0].to_s.strip), # language link.xpath('./td/a/span/text()')[1].to_s.strip, # name link.xpath('./td/a/@href')[0].to_s.strip] # link end Logger.debug "array_list: #{array}" array end
find_download_link(page)
click to toggle source
# File lib/subfinder/parser/subscene.rb, line 28 def find_download_link(page) doc = Nokogiri::HTML(page) download_link = nil doc.css('.download').each do |link| download_link = link.xpath('./a/@href').to_s.strip # link end Logger.debug "download_link: #{download_link}" DOMAIN + download_link end
find_link(links)
click to toggle source
# File lib/subfinder/parser/subscene.rb, line 38 def find_link(links) max_match_point = 0 winner = '' links.each do |link| next if link[0] != Config.language match_point = match_point_for link[1] if match_point > max_match_point max_match_point = match_point winner = link[2] end end Logger.debug "winner is #{winner}" winner 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