Class: Episode

Inherits:
Struct
  • Object
show all
Includes:
Comparable
Defined in:
lib/gst-kitchen/episode.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(podcast = nil, *args) ⇒ Episode

Returns a new instance of Episode.



68
69
70
71
# File 'lib/gst-kitchen/episode.rb', line 68

def initialize(podcast=nil, *args)
  @podcast = podcast
  super(*args)
end

Instance Attribute Details

#auphonic_uuidObject

Returns the value of attribute auphonic_uuid

Returns:

  • (Object)

    the current value of auphonic_uuid



1
2
3
# File 'lib/gst-kitchen/episode.rb', line 1

def auphonic_uuid
  @auphonic_uuid
end

#chaptersObject

Returns the value of attribute chapters

Returns:

  • (Object)

    the current value of chapters



1
2
3
# File 'lib/gst-kitchen/episode.rb', line 1

def chapters
  @chapters
end

#lengthObject

Returns the value of attribute length

Returns:

  • (Object)

    the current value of length



1
2
3
# File 'lib/gst-kitchen/episode.rb', line 1

def length
  @length
end

#mediaObject

Returns the value of attribute media

Returns:

  • (Object)

    the current value of media



1
2
3
# File 'lib/gst-kitchen/episode.rb', line 1

def media
  @media
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



1
2
3
# File 'lib/gst-kitchen/episode.rb', line 1

def name
  @name
end

#numberObject

Returns the value of attribute number

Returns:

  • (Object)

    the current value of number



1
2
3
# File 'lib/gst-kitchen/episode.rb', line 1

def number
  @number
end

#podcastObject

Returns the value of attribute podcast.



4
5
6
# File 'lib/gst-kitchen/episode.rb', line 4

def podcast
  @podcast
end

#published_atObject

Returns the value of attribute published_at

Returns:

  • (Object)

    the current value of published_at



1
2
3
# File 'lib/gst-kitchen/episode.rb', line 1

def published_at
  @published_at
end

#subtitleObject

Returns the value of attribute subtitle

Returns:

  • (Object)

    the current value of subtitle



1
2
3
# File 'lib/gst-kitchen/episode.rb', line 1

def subtitle
  @subtitle
end

#summaryObject

Returns the value of attribute summary

Returns:

  • (Object)

    the current value of summary



1
2
3
# File 'lib/gst-kitchen/episode.rb', line 1

def summary
  @summary
end

Class Method Details

.extract_episode_data_from_auphonic(podcast, production) ⇒ Object



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
# File 'lib/gst-kitchen/episode.rb', line 38

def extract_episode_data_from_auphonic(podcast, production)
  data = production.meta

   = {
    auphonic_uuid: data["data"]["uuid"],
    number: extract_episode_number(podcast.handle, data["data"]["metadata"]["title"]),
    length: data["data"]["length"],
    name: extract_name(podcast.handle, data["data"]["metadata"]["title"]),
    subtitle: data["data"]["metadata"]["subtitle"].strip,
    summary: data["data"]["metadata"]["summary"].strip,
  }

  [:media] = data["data"]["output_files"].each_with_object({}) do |item, obj|
    obj[item["format"]] = {
      "size" => item["size"],
      "file_ext" => item["ending"]
    }
  end

  [:chapters] = if data["data"]["chapters"]
    [:chapters] = data["data"]["chapters"].map do |chapter|
      Chapter.new(chapter["start"], chapter["title"])
    end.sort
  end

  
end

.extract_episode_number(handle, title) ⇒ Object



30
31
32
# File 'lib/gst-kitchen/episode.rb', line 30

def extract_episode_number(handle, title)
  title.match(/#{handle}(\d{3})/) { |match| match[1].to_i }
end

.extract_name(handle, title) ⇒ Object



34
35
36
# File 'lib/gst-kitchen/episode.rb', line 34

def extract_name(handle, title)
  title.match(/#{handle}\d{3} ?- ?(.*)$/) { |match| match[1] }
end

.from_auphonic(podcast, production) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/gst-kitchen/episode.rb', line 7

def from_auphonic(podcast, production)
   = extract_episode_data_from_auphonic(podcast, production)

  episode = self.new podcast
  episode.number = [:number]
  episode.name   = [:name]
  episode.subtitle = [:subtitle]
  episode.length = [:length].round
  episode.auphonic_uuid = [:auphonic_uuid]
  episode.published_at = Time.now
  episode.summary = [:summary]
  episode.media = [:media]
  episode.chapters = [:chapters]

  episode
end

.from_yaml(podcast, yaml_file) ⇒ Object



24
25
26
27
28
# File 'lib/gst-kitchen/episode.rb', line 24

def from_yaml(podcast, yaml_file)
  episode = YAML.load_file(yaml_file)
  episode.podcast = podcast
  episode
end

Instance Method Details

#<=>(other) ⇒ Object



73
74
75
# File 'lib/gst-kitchen/episode.rb', line 73

def <=>(other)
  self.number <=> other.number
end

#durationObject



89
90
91
92
93
94
95
# File 'lib/gst-kitchen/episode.rb', line 89

def duration
  hours = length / (60 * 60)
  minutes = (length - hours * 60 * 60) / 60
  seconds = length % 60

  "#{"%02i" % hours}:#{"%02i" % minutes}:#{"%02i" % seconds}"
end

#handleObject



81
82
83
# File 'lib/gst-kitchen/episode.rb', line 81

def handle
  "#{podcast.handle}#{"%03i" % self.number}"
end

#rfc_2822_dateObject



85
86
87
# File 'lib/gst-kitchen/episode.rb', line 85

def rfc_2822_date
  self.published_at.rfc2822
end

#titleObject



77
78
79
# File 'lib/gst-kitchen/episode.rb', line 77

def title
  "#{handle} - #{name}"
end

#to_sObject



97
98
99
# File 'lib/gst-kitchen/episode.rb', line 97

def to_s
  "#{title} (#{duration}) https://auphonic.com/engine/status/#{auphonic_uuid}"
end

#to_yaml_propertiesObject



101
102
103
# File 'lib/gst-kitchen/episode.rb', line 101

def to_yaml_properties
  super - [:@podcast]
end