Class: SimplePvr::Server::BaseController

Inherits:
Sinatra::Base
  • Object
show all
Includes:
ERB::Util
Defined in:
lib/simple_pvr/server/base_controller.rb

Direct Known Subclasses

AppController, SecuredController

Instance Method Summary collapse

Instance Method Details

#channel_with_current_programmes_hash(channel_with_current_programmes) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/simple_pvr/server/base_controller.rb', line 59

def channel_with_current_programmes_hash(channel_with_current_programmes)
  channel = channel_with_current_programmes[:channel]
  current_programme = channel_with_current_programmes[:current_programme]
  upcoming_programmes = channel_with_current_programmes[:upcoming_programmes]

  current_programme_map = current_programme ? programme_summary_hash(current_programme) : nil
  upcoming_programmes_map = programme_summaries_hash(upcoming_programmes)

  {
    id: channel.id,
    name: channel.name,
    hidden: channel.hidden,
    icon_url: channel.icon_url,
    current_programme: channel,
    current_programme: current_programme_map,
    upcoming_programmes: upcoming_programmes_map
  }
end

#programme_hash(programme) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/simple_pvr/server/base_controller.rb', line 20

def programme_hash(programme)
  {
    id: programme.id,
    channel: { id: programme.channel.id, name: programme.channel.name },
    title: programme.title,
    subtitle: programme.subtitle,
    description: programme.description,
    directors: programme.directors.map { |director| director.name },
    presenters: programme.presenters.map { |presenter| presenter.name },
    actors: programme.actors.map { |actor| { role_name: actor.role_name, actor_name: actor.actor_name } },
    categories: programme.categories.map { |category| category.name },
    start_time: programme.start_time,
    is_scheduled: PvrInitializer.scheduler.scheduled?(programme),
    episode_num: programme.episode_num,
    icon_url: programme.icon_url,
    is_outdated: programme.outdated?
  }
end

#programme_summaries_hash(programmes) ⇒ Object



78
79
80
# File 'lib/simple_pvr/server/base_controller.rb', line 78

def programme_summaries_hash(programmes)
  programmes.map {|programme| programme_summary_hash(programme) }
end

#programme_summary_hash(programme) ⇒ Object



82
83
84
85
86
87
88
89
90
# File 'lib/simple_pvr/server/base_controller.rb', line 82

def programme_summary_hash(programme)
  {
    id: programme.id,
    title: programme.title,
    start_time: programme.start_time,
    is_scheduled: PvrInitializer.scheduler.scheduled?(programme),
    is_conflicting: PvrInitializer.scheduler.conflicting?(programme)
  }
end

#recording_hash(show_id, recording) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/simple_pvr/server/base_controller.rb', line 39

def recording_hash(show_id, recording)
  path = PvrInitializer.recording_manager.directory_for_show_and_recording(show_id, recording.id)
  {
    id: recording.id,
    show_id: show_id,
    subtitle: recording.subtitle,
    description: recording.description,
    directors: recording.directors,
    presenters: recording.presenters,
    actors: recording.actors,
    categories: recording.categories,
    start_time: recording.start_time,
    channel_name: recording.channel,
    has_icon: recording.has_icon,
    has_thumbnail: recording.has_thumbnail,
    has_webm: recording.has_webm,
    local_file_url: 'file://' + File.join(path, 'stream.ts')
  }
end

#reload_schedulesObject



16
17
18
# File 'lib/simple_pvr/server/base_controller.rb', line 16

def reload_schedules
  RecordingPlanner.reload
end