Class: IPlayer::GUI::App

Inherits:
Wx::App
  • Object
show all
Includes:
IPlayer, Errors
Defined in:
lib/iplayer/gui/app.rb

Constant Summary

Constants included from IPlayer

AUDIO_FILETYPE, IPlayer::GUI_VERSION, VERSION, VIDEO_FILETYPE

Instance Method Summary collapse

Constructor Details

#initialize(initial_frame_class, about, options) ⇒ App

Returns a new instance of App.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/iplayer/gui/app.rb', line 10

def initialize(initial_frame_class, about, options)
  @initial_frame_class = initial_frame_class
  @about = about
  @options = options
  super()
  if http_proxy = @options[:http_proxy]
    http_proxy = 'http://' + http_proxy unless http_proxy =~ %r{^http://}
    u = URI.parse(http_proxy)
    http = Net::HTTP::Proxy(u.host, u.port, u.user, u.password)
  else
    http = Net::HTTP
  end
  @browser = Browser.new(http)
  @flags = {}
end

Instance Method Details

#download(pid, path) ⇒ Object

Raises:

  • (MP4Unavailable)


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/iplayer/gui/app.rb', line 30

def download(pid, path)
  downloader = Downloader.new(@browser, pid)
  available_versions = downloader.available_versions
  raise MP4Unavailable if available_versions.empty?
  version = available_versions.sort_by{ |v|
    @options[:type_preference].index(v.name) || 100
  }.first

  self.yield

  downloader.download(version.pid, path) do |position, max|
    return if check_flag(:stop_download)
    yield position, max
    self.yield
  end
end

#get_default_filename(pid) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/iplayer/gui/app.rb', line 51

def get_default_filename(pid)
  self.yield
  begin
     = Metadata.new(pid, @browser)
    title    = .full_title
    filetype = .filetype
  rescue MetadataError
    title    = pid
    filetype = VIDEO_FILETYPE
  end
  "#{ title }.#{ filetype }".gsub(/[^a-z0-9 \-\.]+/i, '')
end

#nameObject



64
65
66
# File 'lib/iplayer/gui/app.rb', line 64

def name
  @about[:name]
end

#on_initObject



26
27
28
# File 'lib/iplayer/gui/app.rb', line 26

def on_init
  @initial_frame_class.new(self).show
end

#show_about_boxObject



68
69
70
# File 'lib/iplayer/gui/app.rb', line 68

def show_about_box
  Wx::about_box(@about)
end

#stop_download!Object



47
48
49
# File 'lib/iplayer/gui/app.rb', line 47

def stop_download!
  set_flag(:stop_download)
end