scripts

misc scripts and tools
git clone git://git.2f30.org/scripts
Log | Files | Refs

commit 147bee213f658406bf25b7a0ef9151559568ac7b
parent 297f3e27a471283fd36b498aca9fd61cf1500d7b
Author: lostd <lostd@2f30.org>
Date:   Tue,  6 May 2014 21:14:33 +0300

My Bandcamp.com parser

Diffstat:
Abanddump | 65+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 65 insertions(+), 0 deletions(-)

diff --git a/banddump b/banddump @@ -0,0 +1,65 @@ +#!/usr/bin/env ruby + +# generate release metadata info from a bandcamp page + +require 'open-uri' +require 'yaml' + +if ARGV.empty? + puts 'usage: banddump url' + exit +end +url = ARGV[0] + +# convert the album data js struct into json data +def get_album_data_json page + got_in = false + json = '' + page.lines do |l| + if l.match(/^var TralbumData = {$/) + got_in = true + json << '{' + next + end + if got_in + if l.match(/^};$/) + json << '}' + break + end + if l.match(/^\s*\/\/.*/) # js comment + next + end + l = l.gsub('" + "', '') + json << l + end + end + json +end + +page = open(url).read +data = YAML.load(get_album_data_json page) +#puts data.to_yaml + +rel = {} +rel['artist'] = data['artist'] +rel['album'] = data['current']['title'] +rel['year'] = Date.parse(data['current']['new_date']).year +rel['masteryear'] = rel['year'] +rel['genre'] = nil +rel['format'] = 'MP3' +rel['comment'] = "Bandcamp: #{data['id']}" +rel['imgurl'] = data['artFullsizeUrl'] +rel['tracklist'] = [] +data['trackinfo'].each do |s| + trk = {} + trk['pos'] = s['track_num'] + trk['title'] = s['title'] + trk['dl'] = s['file']['mp3-128'] if s['file'] + rel['tracklist'] << trk +end + +puts rel.to_yaml + +# output downloads links as separate document +puts '---' +puts rel['tracklist'].collect {|s| s['dl']}