Open sashkavalent opened 7 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))
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.