Class: MusicIds::ISRC
Overview
The ISRC class represents an International Standard Recording Code, and provides simple methods to parse and re-present them.
What is an ISRC?
An ISRC is a globally unique ID for an audio / video recording of a piece of music. (That is, two different recordings of the same song should have different ISRCs)
ISRCs consist of four blocks of information: a two-letter country code, three-character registrant code, two-digit year (see #year), and five-digit designation code. There are two main string representations: the canonical 12-character version, and a 15-character version that inserts hyphens (-) between the blocks.
The first two blocks identify, essentially, a record company / distributor and their country of origin, the last two blocks provide a unique recording number for that company in a particular year.
You can get more details from https://en.wikipedia.org/wiki/International_Standard_Recording_Code and http://www.usisrc.org/
Well-formedness and validity
ISRC's are supposed to be able to be looked up in a global database, so we need to draw a distinction between valid ISRC's, which are ISRC's we have looked up in that database and verified, and well-formed ISRC's, which is to say strings matching the requirements above.
Checking or enforcing validity is beyond the scope of this class. Well-formedness, on the other hand, is easy to check and enforce.
While you don't want to be emitting badly-formed ISRCs, if you handle ISRC's from elsewhere you may well run across bad metadata that you need to preserve, but probably want to be aware of the fact that it's bad.
To help with that there are two parsing modes, strict (the default), and relaxed.
In strict parsing mode, ISRC.parse will raise an error if passed a badly-formed ISRC string. In relaxed mode, it will return an ISRC instance that will return false from #ok? and will return nil from all the component methods like #registrant
Class Method Summary collapse
- .id_blocks ⇒ Object
-
.prefix ⇒ Object
The prefix to use for generating a prefixed string representation of the ISRC (see http://www.ifpi.org/downloads/GRid_Handbook_V2_0_final.pdf §9.2 / §9.3.
Instance Method Summary collapse
-
#as_full ⇒ String
Generate the hyphen-separated full display ISRC string.
-
#country ⇒ String
Return the ISRC's two-letter country code.
-
#designation ⇒ String
Return the ISRC's five-character designation code.
-
#registrant ⇒ String
Return the ISRC's three-character registrant code.
- #to_isrc ⇒ Object
-
#year ⇒ String
Return the ISRC's two-digit year.
Methods included from Id
#==, #as, #as_json, included, #initialize, #ok?, #prefix, #to_s
Class Method Details
.id_blocks ⇒ Object
51 52 53 |
# File 'lib/music_ids/isrc.rb', line 51 def self.id_blocks ['[A-Z]{2}', '[A-Z0-9]{3}', '[0-9]{2}', '[0-9]{5}'] end |
.prefix ⇒ Object
The prefix to use for generating a prefixed string representation of the ISRC (see http://www.ifpi.org/downloads/GRid_Handbook_V2_0_final.pdf §9.2 / §9.3
57 58 59 |
# File 'lib/music_ids/isrc.rb', line 57 def self.prefix @prefix ||= 'ISRC'.freeze end |
Instance Method Details
#as_full ⇒ String
Generate the hyphen-separated full display ISRC string
94 95 96 |
# File 'lib/music_ids/isrc.rb', line 94 def as_full "#{country}-#{registrant}-#{year}-#{designation}" end |
#country ⇒ String
Return the ISRC's two-letter country code
63 64 65 |
# File 'lib/music_ids/isrc.rb', line 63 def country fetch(:@country) { |isrc_string| isrc_string[0,2] } end |
#designation ⇒ String
Return the ISRC's five-character designation code.
84 85 86 |
# File 'lib/music_ids/isrc.rb', line 84 def designation fetch(:@designation) { |isrc_string| isrc_string[7,5] } end |
#registrant ⇒ String
Return the ISRC's three-character registrant code
69 70 71 |
# File 'lib/music_ids/isrc.rb', line 69 def registrant fetch(:@registrant) { |isrc_string| isrc_string[2,3] } end |
#to_isrc ⇒ Object
88 89 90 |
# File 'lib/music_ids/isrc.rb', line 88 def to_isrc self end |
#year ⇒ String
Return the ISRC's two-digit year.
Note that year > 40 is a 19YY year, and 00 to 39 are 20YY years see http://www.ifpi.org/content/library/isrc_handbook.pdf §4.8
78 79 80 |
# File 'lib/music_ids/isrc.rb', line 78 def year fetch(:@year) { |isrc_string| isrc_string[5,2] } end |