Module: Jekyll::Podcast::PodcastData

Defined in:
lib/jekyll/podcast/podcast_data.rb

Overview

Calculate the total count and duration of all podcast episodes

Class Method Summary collapse

Class Method Details

.episodesObject



12
13
14
# File 'lib/jekyll/podcast/podcast_data.rb', line 12

def episodes
  Dir.children(episodes_dir).select { |x| x.end_with?('.mp3') }
end

.episodes_dirObject



8
9
10
# File 'lib/jekyll/podcast/podcast_data.rb', line 8

def episodes_dir
  Jekyll::Podcast::Utils.episodes_dir(@site)
end

.podcast_dataObject



29
30
31
32
33
34
# File 'lib/jekyll/podcast/podcast_data.rb', line 29

def podcast_data
  result = Jekyll::Podcast::Utils.duration(total_duration_in_seconds)
  result[:count] = episodes.length
  result[:size] = total_size_in_megabytes
  result
end

.podcast_data_log_entry(site) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/jekyll/podcast/podcast_data.rb', line 36

def podcast_data_log_entry(site)
  @site = site
  if Dir.exist?(episodes_dir)
    format(
      '%<count>d episodes; %<size>s;' \
      '%<days>d d %<hours>d h %<minutes>d min %<seconds>0.3f s',
      podcast_data
    )
  else
    "No episodes directory found at #{episodes_dir}"
  end
end

.total_duration_in_secondsObject



16
17
18
19
20
# File 'lib/jekyll/podcast/podcast_data.rb', line 16

def total_duration_in_seconds
  episodes.sum do |mp3|
    Mp3Info.open(File.join(episodes_dir, mp3), &:length)
  end
end

.total_size_in_megabytesObject



22
23
24
25
26
27
# File 'lib/jekyll/podcast/podcast_data.rb', line 22

def total_size_in_megabytes
  size_in_bytes = episodes.sum do |mp3|
    File.size(File.join(episodes_dir, mp3))
  end
  "#{(size_in_bytes / 1_000_000.0).round(1)} MB"
end