Use magic encoding to ret rid of "invalid multibyte chat (US-ASCII)" errors. track_search is now renamed recording_search. recording_search now works (I mixed up the inputs).
This commit is contained in:
committed by
Diego d'Ursel
parent
813b6f0383
commit
2d4c1c42fd
@@ -1,2 +1,3 @@
|
||||
# -*- encoding : utf-8 -*-
|
||||
require "musicbrainz"
|
||||
MB = MusicBrainz
|
||||
|
||||
+7
-1
@@ -1,3 +1,7 @@
|
||||
# -*- encoding : utf-8 -*-
|
||||
#!/bin/env ruby
|
||||
# encoding: utf-8
|
||||
|
||||
require "digest/sha1"
|
||||
require "fileutils"
|
||||
require "date"
|
||||
@@ -20,6 +24,7 @@ require "musicbrainz/models/artist"
|
||||
require "musicbrainz/models/release_group"
|
||||
require "musicbrainz/models/release"
|
||||
require "musicbrainz/models/track"
|
||||
require "musicbrainz/models/recording"
|
||||
|
||||
require "musicbrainz/bindings/artist"
|
||||
require "musicbrainz/bindings/artist_search"
|
||||
@@ -32,7 +37,8 @@ require "musicbrainz/bindings/release_group_releases"
|
||||
require "musicbrainz/bindings/release"
|
||||
require "musicbrainz/bindings/release_tracks"
|
||||
require "musicbrainz/bindings/track"
|
||||
require "musicbrainz/bindings/track_search"
|
||||
require "musicbrainz/bindings/recording"
|
||||
require "musicbrainz/bindings/recording_search"
|
||||
|
||||
module MusicBrainz
|
||||
GH_PAGE_URL = "http://git.io/brainz"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# encoding: UTF-8
|
||||
# -*- encoding : utf-8 -*-
|
||||
module MusicBrainz
|
||||
module Bindings
|
||||
module Artist
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
# -*- encoding : utf-8 -*-
|
||||
module MusicBrainz
|
||||
module Bindings
|
||||
module ArtistReleaseGroups
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# encoding: UTF-8
|
||||
# -*- encoding : utf-8 -*-
|
||||
module MusicBrainz
|
||||
module Bindings
|
||||
module ArtistSearch
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
# -*- encoding : utf-8 -*-
|
||||
module MusicBrainz
|
||||
module Bindings
|
||||
module Recording
|
||||
def parse(xml)
|
||||
xml = xml.xpath('./recording') unless xml.xpath('./recording').empty?
|
||||
{
|
||||
id: (xml.attribute('id').value rescue nil),
|
||||
mbid: (xml.attribute('id').value rescue nil), # Old shit
|
||||
title: (xml.xpath('./title').text.gsub(/[`’]/, "'") rescue nil),
|
||||
artist: (xml.xpath('./artist-credit/name-credit/artist/name').text rescue nil),
|
||||
releases: (xml.xpath('./release-list/release/title').map{ |xml| xml.text } rescue []),
|
||||
score: (xml.attribute('score').value.to_i rescue nil)
|
||||
}
|
||||
end
|
||||
|
||||
extend self
|
||||
end
|
||||
end
|
||||
end
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
# encoding: UTF-8
|
||||
# -*- encoding : utf-8 -*-
|
||||
module MusicBrainz
|
||||
module Bindings
|
||||
module TrackSearch
|
||||
module RecordingSearch
|
||||
def parse(xml)
|
||||
xml.xpath('./recording-list/recording').map do |xml|
|
||||
{
|
||||
@@ -1,3 +1,4 @@
|
||||
# -*- encoding : utf-8 -*-
|
||||
module MusicBrainz
|
||||
module Bindings
|
||||
module Release
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
# -*- encoding : utf-8 -*-
|
||||
module MusicBrainz
|
||||
module Bindings
|
||||
module ReleaseGroup
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
# -*- encoding : utf-8 -*-
|
||||
module MusicBrainz
|
||||
module Bindings
|
||||
module ReleaseGroupReleases
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# encoding: UTF-8
|
||||
# -*- encoding : utf-8 -*-
|
||||
module MusicBrainz
|
||||
module Bindings
|
||||
module ReleaseGroupSearch
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
# -*- encoding : utf-8 -*-
|
||||
module MusicBrainz
|
||||
module Bindings
|
||||
module ReleaseTracks
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
# -*- encoding : utf-8 -*-
|
||||
module MusicBrainz
|
||||
module Bindings
|
||||
module Track
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
# -*- encoding : utf-8 -*-
|
||||
module MusicBrainz
|
||||
class Client
|
||||
include ClientModules::TransparentProxy
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
# -*- encoding : utf-8 -*-
|
||||
module MusicBrainz
|
||||
module ClientModules
|
||||
module CachingProxy
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
# -*- encoding : utf-8 -*-
|
||||
module MusicBrainz
|
||||
module ClientModules
|
||||
module FailsafeProxy
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
# -*- encoding : utf-8 -*-
|
||||
module MusicBrainz
|
||||
module ClientModules
|
||||
module TransparentProxy
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
# -*- encoding : utf-8 -*-
|
||||
module MusicBrainz
|
||||
class Configuration
|
||||
attr_accessor :app_name, :app_version, :contact,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
# -*- encoding : utf-8 -*-
|
||||
module MusicBrainz
|
||||
module Deprecated
|
||||
module ProxyConfig
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
# -*- encoding : utf-8 -*-
|
||||
module MusicBrainz
|
||||
class Middleware < Faraday::Middleware
|
||||
def call(env)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
# -*- encoding : utf-8 -*-
|
||||
module MusicBrainz
|
||||
class Artist < BaseModel
|
||||
field :id, String
|
||||
|
||||
@@ -24,15 +24,16 @@ module MusicBrainz
|
||||
MusicBrainz.client
|
||||
end
|
||||
|
||||
def search(hash, resource=nil)
|
||||
def find(hash)
|
||||
underscored_name = underscore_name.to_sym
|
||||
client.load(underscored_name, hash, { binding: underscored_name, create_model: underscored_name })
|
||||
end
|
||||
|
||||
def search(hash)
|
||||
hash = escape_strings(hash)
|
||||
query_val = build_query(hash)
|
||||
underscore_name = self.name[13..-1].underscore
|
||||
if resource # only needed since "track" is really a "recording", ugly
|
||||
client.load(resource, { query: query_val, limit: 10 }, { binding: underscore_name.insert(-1,"_search").to_sym })
|
||||
else
|
||||
client.load(underscore_name.to_sym, { query: query_val, limit: 10 }, { binding: underscore_name.insert(-1,"_search").to_sym })
|
||||
end
|
||||
underscored_name = underscore_name
|
||||
client.load(underscored_name.to_sym, { query: query_val, limit: 10 }, { binding: underscored_name.insert(-1,"_search").to_sym })
|
||||
end
|
||||
|
||||
class ::String
|
||||
@@ -57,6 +58,10 @@ module MusicBrainz
|
||||
hash
|
||||
end
|
||||
|
||||
def underscore_name
|
||||
self.name[13..-1].underscore
|
||||
end
|
||||
|
||||
# these probably should be private... but I'm not sure how to get it to work in a module...
|
||||
# private_class_method :build_query, :escape_strings
|
||||
end
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
module MusicBrainz
|
||||
class Recording < BaseModel
|
||||
field :id, Integer
|
||||
field :mbid, Integer
|
||||
field :title, String
|
||||
field :artist, String
|
||||
field :releases, String
|
||||
field :score, Integer
|
||||
|
||||
class << self
|
||||
def find(id)
|
||||
super({ id: id })
|
||||
end
|
||||
|
||||
def search(track_name, artist_name)
|
||||
super({recording: track_name, artist: artist_name})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,3 +1,4 @@
|
||||
# -*- encoding : utf-8 -*-
|
||||
module MusicBrainz
|
||||
class Release < BaseModel
|
||||
field :id, String
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
# -*- encoding : utf-8 -*-
|
||||
module MusicBrainz
|
||||
class ReleaseGroup < BaseModel
|
||||
field :id, String
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
# -*- encoding : utf-8 -*-
|
||||
module MusicBrainz
|
||||
class Track < BaseModel
|
||||
field :position, Integer
|
||||
@@ -12,11 +13,6 @@ module MusicBrainz
|
||||
create_model: :track
|
||||
})
|
||||
end
|
||||
|
||||
def search(artist_name, track_name)
|
||||
# this model really should be named "recording" I'd rename, but I don't want to break anything
|
||||
super({recording: track_name, artist: artist_name}, "recording")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
# -*- encoding : utf-8 -*-
|
||||
module MusicBrainz
|
||||
VERSION = "0.7.7"
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user