Class: Rmpv::Myanimelist

Inherits:
Object
  • Object
show all
Defined in:
lib/rmpv/myanimelist.rb

Instance Method Summary collapse

Constructor Details

#initializeMyanimelist

Initialize the Myanimelist client



22
23
24
25
26
27
28
# 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

Instance Method Details

#parse(file) ⇒ String, Fixnum

Parse the file names

Parameters:

  • file (String)

    name

Returns:

  • (String, Fixnum)

    name of the show and episode number



35
36
37
38
39
40
41
42
43
44
45
# 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) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
# 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