Sha256: 83a65fbb15304d260a603ecc9062f664f60940d7baa5a92e87ddc4a8b9eb7689

Contents?: true

Size: 1.57 KB

Versions: 6

Compression:

Stored size: 1.57 KB

Contents

module DownloadTV

	class MyEpisodes

		def initialize(user=nil, save_cookie)
			@agent = Mechanize.new
			@user = user
			@save_cookie = save_cookie
		end

		def login
			if !@user || @user==""
				print "Enter your MyEpisodes username: "
				@user = STDIN.gets.chomp
			end

			print "Enter your MyEpisodes password: "
			pass = STDIN.noecho(&:gets).chomp
			puts

			page = @agent.get "https://www.myepisodes.com/login.php"

			login_form = page.forms[1]
			login_form.username = @user
			login_form.password = pass

			page = @agent.submit(login_form, login_form.buttons.first)

			raise InvalidLoginError if page.filename == "login.php"

			save_cookie() if @save_cookie

			@agent
			
		end

		def load_cookie
			if File.exists? "cookie"
				@agent.cookie_jar.load "cookie"
				page = @agent.get "https://www.myepisodes.com/login.php"
				if page.links[1].text == "Register"
					puts "The cookie is invalid/has expired."
					login
				end
				@agent
			else
				puts "Cookie file not found"
				login
			end
			
		end

		def save_cookie
			@agent.cookie_jar.save("cookie", session: true)
			@agent
			
		end
		
		def get_shows(last)
			page = @agent.get "https://www.myepisodes.com/ajax/service.php?mode=view_privatelist"
			shows = page.parser.css('tr.past')

			s = shows.select do |i|
				airdate = i.css('td.date')[0].text
				Date.parse(airdate) >= last
			end

			s.map do |i|
				name = i.css('td.showname').text
				ep = i.css('td.longnumber').text

				ep.insert(0, "S")
				ep.sub!("x", "E")

				"#{name} #{ep}"
			end
			
		end
		
	end

	class InvalidLoginError < StandardError

	end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
download_tv-2.1.0 lib/download_tv/myepisodes.rb
download_tv-2.0.6 lib/download_tv/myepisodes.rb
download_tv-2.0.5 lib/download_tv/myepisodes.rb
download_tv-2.0.4 lib/download_tv/myepisodes.rb
download_tv-2.0.3 lib/download_tv/myepisodes.rb
download_tv-2.0.0 lib/download_tv/myepisodes.rb