moumar / ruby-mp3info

ruby-mp3info read low-level informations and manipulate tags on mp3 files.
http://rdoc.info/github/moumar/ruby-mp3info/master/frames
223 stars 57 forks source link

Find mp3 file info given its uri by fetching as little as needed #68

Open sashkavalent opened 7 years ago

sashkavalent commented 7 years ago

There can be a case when you need to get info for many mp3 files by their uris and you wouldn't like to download all of them. It seems it's possible to only download info of mp3 files like here https://github.com/sdsykes/fastimage for images. So @moumar if you think it could be useful, I would try to implement it.

taylorthurlow commented 6 years ago

If anyone is looking for a solution to this, I found it easy to grab the first 8kb of a remote file this way, in the case of a dropbox URL - but it should work with some tweaking for any file HTTP request:

response = Faraday.new('https://content.dropboxapi.com').post do |req|
  req.url '/2/files/download'
  req.headers['Authorization'] = "Bearer #{@location.dropbox_token}"
  req.headers['Dropbox-API-Arg'] = { path: e['path_lower'] }.to_json
  req.headers['Content-Type'] = 'application/octet-stream'
  req.headers['Range'] = 'bytes=0-8192'
end

mp3data = Mp3Info.open(StringIO.open(response.body))