Feature Requests: Browse | Submit New | Admin

[#87] method to parse files

Date:
2003-09-17 15:57
Priority:
3
Submitted By:
Fernando Arbeiza (sileno)
Assigned To:
Nobody (None)
Category:
None
State:
Open
Summary:
method to parse files

Detailed description
Hi:

I have begun (at last) to add the commit support to my script.

I am going to do it saving the freedb entry in a file, then starting an
editor and scanning the file after that. I could do it using my own
format and writing the parsing methods (or using REXML), but I think
the format from the freedb database is neat and clear.

I append a little patch with an example of how it can be done. It's just
a quick and dirty solution, so don't expecto too much.

This script is an example of using the library after applying the patch,
and how I am going to solve the edition of the tags:

#########################################
#!/usr/local/bin/ruby -w

require 'freedb'

f = Freedb.new('/dev/cdroms/cdrom0')
f.fetch_net
f.get_result(0) unless f.results.empty?

File.open('test.tmp', 'w') do |file|
    file << f.entry
    file.puts('.')
end

print('Category? ')
$stdout.flush
category = $stdin.gets
system("vim test.tmp")

File.open('test.tmp', 'r') do |file| f.scan(file) end
f.category = category

puts(f.entry)
puts(f.category)
f.close

# End of file
#########################################

The patch adds two new methods: entry and scan

The entry method returns the freedb entry. It is just the submit_body
method whithout error handling. I have not used the raw_response
variable because it does not make sense when there have not been any
match in the database.

The scan method is passed a handler and it scans the file (or whatever
the handler class is). It is just the get_result method without getting
the response from the server. However, this method have three problems
(I said it was a quick and dirty solution):

    * It needs a '.' at the end of the file.

    * It overwrites the category variable (it should not).
 
    * It does not raise an exception (or ignores) when it finds more
    songs than the CD includes (e.g. it finds a TTITLE9= tag on an
    8-song CD).

Regards,

Add A Comment: Notepad

Please login


Followup

No Followups Have Been Posted

Attached Files:

Name Description Download
ruby-freedb-0.5.patch Patch against ruby-freedb-0.5 Download

Changes:

Field Old Value Date By
File Added10: ruby-freedb-0.5.patch2003-09-17 15:57sileno