class Rmpv::Myanimelist
Public Class Methods
new()
click to toggle source
Initialize the Myanimelist
client
# File lib/rmpv/myanimelist.rb, line 22 def initialize myanimeconfig = YAML.load File.open("#{Dir.home}/.rmpvrc") MyAnimeList.configure do |config| config.username = myanimeconfig["myanimelist"]["username"] config.password = myanimeconfig["myanimelist"]["password"] end end
Public Instance Methods
parse(file)
click to toggle source
Parse the file names
@param [String] file name @return [String, Fixnum] name of the show and episode number
# File lib/rmpv/myanimelist.rb, line 35 def parse(file) raw_name = file raw_name = raw_name[0, raw_name.rindex(/\./)] # remove extension raw_name = raw_name.gsub(/(\.|_|\-)/, '') # Chars used in filenames as a substitute for spaces raw_name = raw_name.gsub(/\(.*?\)/, '') # Remove anything surrounded by paranthesis raw_name = raw_name.gsub(/\[.*?\]/, '') # Remove anything surrounded by paranthesis ep = /(\d+)/.match(raw_name)[1] name = raw_name.gsub(/(\d+)/, '').strip! episode = ep.nil? ? 1 : ep.to_i return name, episode end
scrobble(anime, ep)
click to toggle source
# File lib/rmpv/myanimelist.rb, line 47 def scrobble(anime, ep) tries = 5 begin info = MyAnimeList.search_anime(anime) rescue Exception => e tries -= 1 if tries > 0 retry else puts "Couldn't connect to Myanimelist servers: #{e}" end end end