Class: Nehm::TrackManager

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

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ TrackManager

Returns a new instance of TrackManager.



9
10
11
# File 'lib/nehm/track_manager.rb', line 9

def initialize(options)
  setup_environment(options)
end

Instance Method Details

#likes(limit, offset) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/nehm/track_manager.rb', line 24

def likes(limit, offset)
  UI.term "Invalid limit value\nIt should be more than 0" if limit <= 0
  UI.term "Invalid offset value\nIt should be more or equal 0" if offset < 0

  likes = Client.tracks(limit, offset, :likes, @uid)
  return nil if likes.empty?

  filter(likes)
  convert(likes)
end

#posts(limit, offset) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/nehm/track_manager.rb', line 35

def posts(limit, offset)
  UI.term "Invalid limit value\nIt should be more than 0" if limit <= 0
  UI.term "Invalid offset value\nIt should be more or equal 0" if offset < 0

  posts = Client.tracks(limit, offset, :posts, @uid)
  return nil if posts.empty?

  posts.map! { |hash| hash['track'] }
  filter(posts)
  convert(posts)
end

#process_tracks(tracks) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/nehm/track_manager.rb', line 13

def process_tracks(tracks)
  tracks.reverse_each do |track|
    dl(track)
    tag(track)
    track.artwork.suicide
    @playlist.add_track(track) if @playlist
    UI.newline
  end
  UI.success 'Done!'
end

#search(query, limit, offset) ⇒ Object



57
58
59
60
61
62
63
64
65
66
# File 'lib/nehm/track_manager.rb', line 57

def search(query, limit, offset)
  UI.term "Invalid limit value\nIt should be more than 0" if limit <= 0
  UI.term "Invalid offset value\nIt should be more or equal 0" if offset < 0

  found = Client.search(query, limit, offset)
  return nil if found.empty?

  filter(found)
  convert(found)
end

#track_from_url(url) ⇒ Object



47
48
49
50
51
52
53
54
55
# File 'lib/nehm/track_manager.rb', line 47

def track_from_url(url)
  track = [Client.resolve(url)]

  UI.term 'Invalid URL! Please type link to track' if track.first['kind'] != 'track'
  return nil if track.empty?

  filter(track)
  convert(track)
end