Sha256: 499d1a4ce8e6dbf2e0e7d0c1ec97cd17bb54ce0a21b24a359539f912326d47e4

Contents?: true

Size: 930 Bytes

Versions: 1

Compression:

Stored size: 930 Bytes

Contents

module Imuze
  class GetMusic < Struct.new(:token, :mp3_uri, :options)
    include Methadone::CLILogging
    include Methadone::SH
    require 'uri'
    require 'net/http'
    require 'json'

    def self.call(*args)
      new(*args).call
    end

    def call
      download? ? command_download : command_play
    end

    private

    def command_play
      command = %Q(curl "http:#{mp3_uri}"  -s -H "Content-Type: application/json"  -H "Authorization: #{token}" | mpg123 - 2> /dev/null)
      sh command do |stdout, stderr|
        puts 'We hope you liked it !'
      end
    end

    def command_download
      command = %Q(wget "http:#{mp3_uri}" -O #{mp3_id}.mp3)
      sh command do |stdout, stderr|
        puts 'We hope you liked it !'
      end
    end

    def download?
      options.nil? ? false : options[:download]
    end

    def mp3_id
      puts mp3_uri.split('/')
      mp3_uri.split('/')[4]
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
imuzer-0.0.3 lib/imuze/get_music.rb