Class: MetalArchives::Parsers::Release
- Defined in:
- lib/metal_archives/parsers/release.rb
Overview
Release parser
Constant Summary collapse
- TYPE_TO_QUERY =
{ full_length: 1, live: 2, demo: 3, single: 4, ep: 5, video: 6, boxed_set: 7, split: 8, compilation: 10, split_video: 12, collaboration: 13, }.freeze
- TYPE_TO_SYM =
{ "Full-length" => :full_length, "Live album" => :live, "Demo" => :demo, "Single" => :single, "EP" => :ep, "Video" => :video, "Boxed set" => :boxed_set, "Split" => :split, "Compilation" => :compilation, "Split video" => :split_video, "Collaboration" => :collaboration, }.freeze
- FORMAT_TO_QUERY =
{ cd: "CD", cassette: "Cassette", vinyl: "Vinyl*", vhs: "VHS", dvd: "DVD", "2dvd": "2DVD", digital: "Digital", blu_ray: "Blu-ray*", other: "Other", unknown: "Unknown", }.freeze
- FORMAT_TO_SYM =
{ "CD" => :cd, "Cassette" => :cassette, "VHS" => :vhs, "DVD" => :dvd, "2DVD" => :"2dvd", "Digital" => :digital, "Other" => :other, "Unknown" => :unknown, }.freeze
Class Method Summary collapse
-
.map_params(query) ⇒ Object
Map attributes to MA attributes.
-
.parse_html(response) ⇒ Object
Parse main HTML page.
Methods inherited from Parser
Class Method Details
.map_params(query) ⇒ Object
Map attributes to MA attributes
Returns Hash
params
-
Hash
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/metal_archives/parsers/release.rb', line 73 def map_params(query) { bandName: query[:band_name] || "", releaseTitle: query[:title] || "", releaseYearFrom: query[:from_year] || "", releaseMonthFrom: query[:from_month] || "", releaseYearTo: query[:to_year] || "", releaseMonthTo: query[:to_month] || "", country: map_countries(query[:country]) || "", location: query[:location] || "", releaseLabelName: query[:label_name] || "", releaseCatalogNumber: query[:catalog_id] || "", releaseIdentifiers: query[:identifier] || "", releaseRecordingInfo: query[:recording_info] || "", releaseDescription: query[:version_description] || "", releaseNotes: query[:notes] || "", genre: query[:genre] || "", releaseType: map_types(query[:types]), releaseFormat: map_formats(query[:formats]), } end |
.parse_html(response) ⇒ Object
Parse main HTML page
Returns Hash
- Raises
-
MetalArchives::Errors::ParserError when parsing failed. Please report this error.
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/metal_archives/parsers/release.rb', line 103 def parse_html(response) # Set default props props = { title: nil, band: nil, type: nil, date_released: nil, catalog_id: nil, identifier: nil, version_description: nil, format: nil, limitation: nil, } doc = Nokogiri::HTML response props[:title] = sanitize doc.css("#album_info .album_name a").first.content # Band band_doc = doc.css("#album_info .band_name a").first id = Integer(band_doc.attr("href").split("/").last) props[:band] = MetalArchives::Band.find(id) doc.css("#album_info dl").each do |dl| dl.search("dt").each do |dt| content = sanitize dt.next_element.content next if content == "N/A" case sanitize(dt.content) when "Type:" props[:type] = map_type content when "Release date:" props[:date_released] = Parsers::Date.parse(content) when "Catalog ID:" props[:catalog_id] = content when "Identifier:" props[:identifier] = content when "Version desc.:" props[:version_description] = content when "Label:" # TODO: label when "Format:" props[:format] = map_format content when "Limitation:" props[:limitation] = content.to_i when "Reviews:" next if content == "None yet" # TODO: reviews else raise Errors::ParserError, "Unknown token: #{dt.content}" end end end props rescue StandardError => e e.backtrace.each { |b| MetalArchives.config.logger.error b } raise Errors::ParserError, e end |