Class: TimeFree

Inherits:
RadikoPremium show all
Defined in:
lib/rbtune/timefree.rb

Instance Attribute Summary

Attributes inherited from Radiko

#authtoken

Attributes inherited from Radio

#area_en, #area_id, #area_ja, #ext, #outdir

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RadikoPremium

#close, #headers, #login, set_authentication, #stations_uri

Methods inherited from Radiko

#authenticate1, #authenticate2, #fetch_file, #keyfile, #open, #parse_stations, #playerfile, #playerurl, #read_partialkey, #stations_uri, #swfextract

Methods inherited from Radio

#agent, bands, channels, #close, #convert, #convert_ffmpeg, #datetime, db, #fetch_stations, find, inherited, #initialize, #login, #make_recfile, #make_tmpfile, match, #open, #out_ext, #play, search, #tune

Constructor Details

This class inherits a constructor from Radio

Class Method Details

.stationsObject



15
16
17
# File 'lib/rbtune/timefree.rb', line 15

def self.stations
  []
end

Instance Method Details

#channel_to_uri(from, to) ⇒ Object



38
39
40
# File 'lib/rbtune/timefree.rb', line 38

def channel_to_uri(from, to)
  %Q(https://radiko.jp/v2/api/ts/playlist.m3u8?l=15&station_id=#{@channel}&ft=#{from}&to=#{to})
end

#create_player(uri) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/rbtune/timefree.rb', line 43

def create_player(uri)
  ffmpeg = FFMpeg.new
  ffmpeg['loglevel'] = 'info'
  ffmpeg['headers']  = %Q("X-Radiko-AuthToken: #{authtoken}")
  ffmpeg['i']        = %Q("#{uri}")
  ffmpeg['acodec']   = 'copy' # acodecオプションはiオプションのあとに置かないとエラー
  ffmpeg
end

#record(filename, starttime, sec) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/rbtune/timefree.rb', line 19

def record(filename, starttime, sec)
  endtime = starttime + sec/60/60/24

  from = starttime.timefree
  to   = endtime.timefree
  # pp [@channel, from, to]
  uri = channel_to_uri from, to
  player = create_player uri
  dt = datetime starttime
  recfile = make_recfile filename, dt
  stdout, stderr, status = player.rec recfile, nil
  case stderr
  when /400 Bad Request/
    raise HTTPBadRequestException
  when /403 Forbidden/
    raise HTTPForbiddenException
  end
end