class Tvgem::Tvdb

Public Instance Methods

elementtohash(xml,elementname) click to toggle source

def readzip(seriesid) zipfilename = open(“thetvdb.com/api/B7FB16C98BC878DE/series/#{seriesid}/all/en.zip”) Zip::File.open(zipfilename) do |zipfile| zipfile.each do |entry| puts “Reading #{entry.name}” case entry.name when “en.xml” puts “case en” @content = entry.get_input_stream.read when “banners.xml” puts “Case banner” @banners = entry.get_input_stream.read when “actors.xml” puts “case actors” @actors = Hpricot(entry.get_input_stream.read) puts “wjbdwlhg” end end end end

# File lib/tvgem.rb, line 58
def elementtohash(xml,elementname)
  doc = Hpricot(xml)  
  coll = []
  (doc/"//#{elementname}").each do |child|
    hash = Hash.new     
    (child/"/").each do |gchild|      
      unless  (gchild.innerHTML).empty?
        hash.store(gchild.name, gchild.innerHTML)
      end
    end
    coll << hash
  end
  return coll  
end
getSeriesByName(seriesname) click to toggle source
# File lib/tvgem.rb, line 11
def getSeriesByName(seriesname)
  @doc = Hpricot(open("http://thetvdb.com/api/GetSeries.php?seriesname=#{seriesname}"))
  choices = []
  (@doc/"data//series").each do |temp|    
    choice = SeriesDesc.new
    choice.seriesid = (temp/"//seriesid").first.inner_html
    choice.seriesname = (temp/"//seriesname").first.inner_html
    if (!(temp/"//overview").first.blank? )
    choice.overview = (temp/"//overview").first.inner_html end
    if (!(temp/"//banner").first.blank? )
    choice.banner = (temp/"//banner").first.inner_html end
    choice.firstaired = (temp/"//firstaired").first.inner_html
    choices << choice
    end
  if (choices.empty?)
    puts "Its Empty"
    else
  return choices
  end
end
getdetail(detail) click to toggle source
# File lib/tvgem.rb, line 32
def getdetail(detail)
  item = (@doc/"data/series//#{detail}").first
  return item
end
getxml(seriesid,type) click to toggle source
# File lib/tvgem.rb, line 73
def getxml(seriesid,type)
  xml = open("http://thetvdb.com/api/B7FB16C98BC878DE/series/#{seriesid}/all/#{type}.xml")
  return xml
end
xmlfromzip(seriesid,xmlname) click to toggle source
# File lib/tvgem.rb, line 78
def xmlfromzip(seriesid,xmlname)
  zipfilename = open("http://thetvdb.com/api/B7FB16C98BC878DE/series/85111/all/en.zip",&:read)
    Zip::File.open(zipfilename) do |zipfile|
      zipfile.each do |entry|
      if entry.name == "#{xmlname}.xml"
        @content = entry.get_input_stream.read
      end
    end
  end
  return @content
end