Class: Main
- Inherits:
-
Object
- Object
- Main
- Defined in:
- lib/etvnet_seek/main.rb
Constant Summary collapse
- COOKIE_FILE_NAME =
ENV['HOME'] + "/.etvnet-seek"
Instance Method Summary collapse
- #display_bottom_menu_part(mode) ⇒ Object
- #display_items(items) ⇒ Object
- #get_credentials ⇒ Object
-
#initialize ⇒ Main
constructor
A new instance of Main.
- #launch_link(link) ⇒ Object
- #process(mode, *params) ⇒ Object
- #process_access(page, item) ⇒ Object
- #seek(*params) ⇒ Object
Constructor Details
#initialize ⇒ Main
Returns a new instance of Main.
16 17 18 19 |
# File 'lib/etvnet_seek/main.rb', line 16 def initialize @cookie_helper = CookieHelper.new COOKIE_FILE_NAME @commander = Commander.new end |
Instance Method Details
#display_bottom_menu_part(mode) ⇒ Object
128 129 130 131 |
# File 'lib/etvnet_seek/main.rb', line 128 def mode puts "<number> => today; <number> a => archive" if mode == 'channels' puts "q. to exit" end |
#display_items(items) ⇒ Object
118 119 120 121 122 123 124 125 126 |
# File 'lib/etvnet_seek/main.rb', line 118 def display_items items if items.size == 0 puts "Empty search result." else items.each_with_index do |item, index| puts "#{index+1}. #{item}" end end end |
#get_credentials ⇒ Object
111 112 113 114 115 116 |
# File 'lib/etvnet_seek/main.rb', line 111 def get_credentials username = ask("Enter username : " ) password = ask("Enter password : " ) { |q| q.echo = '*' } [username, password] end |
#launch_link(link) ⇒ Object
133 134 135 136 137 138 139 |
# File 'lib/etvnet_seek/main.rb', line 133 def launch_link link if RUBY_PLATFORM =~ /(win|w)32$/ `start wmplayer #{link}` elsif RUBY_PLATFORM =~ /darwin/ `open #{link}` end end |
#process(mode, *params) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/etvnet_seek/main.rb', line 31 def process mode, *params page = PageFactory.create(mode, params) if mode == 'access' process_access page, params[0] elsif mode == 'login' item = params[0] = page.login(*get_credentials) @cookie_helper. process("access", item) else items = page.items if items.size > 0 display_items items (mode) user_selection = read_user_selection items if not user_selection.quit? current_item = items[user_selection.index] if mode == 'main' case current_item.link when /announces.html/ then process('announces') when /freeTV.html/ then process('freetv') when /category=/ then process('media', current_item.link) when /action=channels/ then process('channels', current_item.link) end elsif mode == 'channels' if user_selection.archive? process('archive_media', current_item.archive_link) else process('media', current_item.link) end else # media : announces, freetv, category if current_item.folder? or current_item.link =~ /action=view_recommended/ or current_item.has_media_links? process('media', current_item.link) else process("access", current_item) end end end end end end |
#process_access(page, item) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/etvnet_seek/main.rb', line 84 def process_access page, item = @cookie_helper. if .nil? process("login", item) else result = CookieHelper.get_auth_and_expires() = DateTime.strptime(result[1], "%A, %d-%b-%Y %H:%M:%S %Z") if < DateTime.now # cookie expired? @cookie_helper. process("login", item) else media_info = page.request_media_info(item.media_file, ) if media_info.session_expired? @cookie_helper. process("login", item) else LinkInfo.new(item, media_info) end end end end |
#seek(*params) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/etvnet_seek/main.rb', line 21 def seek *params if @commander.search_mode? params = read_keywords(*params) puts "Keywords: #{params}" if @commander.runglish_mode? end process @commander.get_initial_mode, params end |