Class: Icemaker::Playlist

Inherits:
Object
  • Object
show all
Defined in:
lib/icemaker/icemaker.rb

Defined Under Namespace

Classes: Icefile

Class Method Summary collapse

Class Method Details

.collect_filesObject



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/icemaker/icemaker.rb', line 41

def self.collect_files

  @@files = []

  @@icefile.sources.each do |source|

    @@files << (get_entries from: source, and_recurse_into_if: @@icefile.is_recursive)

  end

  @@files.flatten!
  
end

.filter_tracksObject



5
6
7
8
9
10
11
# File 'lib/icemaker/icemaker.rb', line 5

def self.filter_tracks

  @@filtered = ((Query.new with: @@icefile.filters).find in: @@tracks)

  verbalize "#{@@filtered.length} tracks found."

end

.format_for_writingObject



89
90
91
# File 'lib/icemaker/icemaker.rb', line 89

def self.format_for_writing
  @@formatted = @@filtered.map &@@icefile.formatter
end

.get_entries(params) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/icemaker/icemaker.rb', line 67

def self.get_entries(params)

  source = params[:from]
  recurse = params[:and_recurse_into_if]

  entries = []

  if recurse
    entries << Dir[File.join(source, "**", "*")]
  else
    entries << (Dir.entries source).reject! { |x| x == '..' || x == '.' }
    entries.flatten!.map! { |file| "#{source}/#{file}"}
  end

  entries

end

.make {|@@icefile| ... } ⇒ Object

Yields:

  • (@@icefile)


97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/icemaker/icemaker.rb', line 97

def self.make

  @@icefile = Icefile.new

  yield @@icefile

  collect_files
  remove_non_audio_files
  make_tracks_from_files
  filter_tracks
  format_for_writing
  write_playlist

end

.make_tracks_from_filesObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/icemaker/icemaker.rb', line 13

def self.make_tracks_from_files

  @@tracks = []

  @@files.each do |file|

    TagLib::FileRef.open(file) do |info|

      unless info.null?

        @@tracks << {
          file: file,
          title: info.tag.title ? info.tag.title : UNKNOWN_VALUE,
          artist: info.tag.artist ? info.tag.artist : UNKNOWN_VALUE,
          album: info.tag.album ? info.tag.album : UNKNOWN_VALUE,
          genre: info.tag.genre ? info.tag.genre : UNKNOWN_VALUE,
          year: info.tag.year ? info.tag.year : UNKNOWN_VALUE,
          length: info.audio_properties.length ? info.audio_properties.length : 0,
          bitrate: info.audio_properties.bitrate ? info.audio_properties.bitrate : 0,
          channels: info.audio_properties.channels ? info.audio_properties.channels : 0,
          sample_rate: info.audio_properties.sample_rate ? info.audio_properties.sample_rate : 0
        }

      end
    end
  end
end

.remove_non_audio_filesObject



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/icemaker/icemaker.rb', line 55

def self.remove_non_audio_files

  verbalize "#{@@files.length} total files found."

  @@files.reject! { |file|
    !(ALLOWED_MEDIA_EXTENSIONS.include? (File.extname file).downcase) || (File.directory? file )
  }

  verbalize "#{@@files.length} audio files found."

end

.verbalize(some_words) ⇒ Object



93
94
95
# File 'lib/icemaker/icemaker.rb', line 93

def self.verbalize(some_words)
  puts some_words if @@icefile.verbose
end

.write_playlistObject



85
86
87
# File 'lib/icemaker/icemaker.rb', line 85

def self.write_playlist
  File.open(@@icefile.output_to_file, 'w') { |f| f.puts(@@formatted) }
end