Created
November 30, 2010 21:57
-
-
Save ocharles/722499 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strictures; | |
use lib 'lib'; | |
use aliased 'MusicBrainz::Server::Entity::Artist'; | |
use aliased 'MusicBrainz::New::Edit::AddArtist'; | |
# Start out by creating a new artist | |
my $start = Group->new( | |
edits => [ | |
AddArtist->new( | |
artist => Artist->new( | |
name => 'The Beatles', | |
sort_name => 'The Beatles' | |
))]); | |
# When the edit group passes, we will have an artist in the database | |
# that matches above. For now, lets skip the DB and assume that works: | |
my $artist = $start->edits->[0]->artist; | |
# Oops, this doesn't match style guidelines, so lets change that | |
Group->new( | |
edits => [ | |
EditArtist->new( | |
artist => $artist, | |
new_artist => $artist->clone( | |
sort_name => 'Beatles, The' | |
))]); | |
# Again, this will update the database when it passes | |
$artist = $group->edits->[0]->new_artist; | |
# Ok, how about some ARs? | |
# Here we add 2 relationships in a single edit. In this case the URLs | |
# do not have ids, so they will be created by the AddRelationship edit | |
# type. This should lead to a history that not only tracks when things | |
# were added, but also the motivation for the edit. | |
Group->new( | |
edits => [ | |
AddRelationship->new( | |
Relationship->new( | |
source => $artist, | |
target => Url->new(url => 'http://bbc.co.uk') | |
), | |
AddRelationship->new( | |
Relationship->new( | |
source => $artist, | |
target => Url->new(url => 'http://discogs.com') | |
))]); | |
# Now how does adding a release look? | |
# Here we add a release with 1 medium, and 2 tracks. | |
# The 2 tracks create new recordings, and ARS at the same time | |
# We also add a catalog number and label, in this case creating a new label as well | |
my $beatles_ac = ArtistCredit->new( $artist ); | |
Group->new( | |
edits => [ | |
AddRelease->new( | |
title => 'Hello, Goodbye', | |
artist_credit => $beatles_ac, | |
mediums => [ | |
Medium->new( | |
format => MediumFormat->new( name => 'Vinyl' ), | |
tracklist => Tracklist->new( | |
tracks => [ | |
Track->new( | |
name => 'Love Me Do', | |
artist => $beatles_ac, | |
length => '2:23', | |
recording => Recording->new( | |
name => 'Love Me Do', | |
artist => $beatles_ac, | |
relationships => [ | |
# Hand waving a bit here, but you get the idea | |
Relationship->new( | |
source => $this | |
target => $john_lennon)])), | |
Track->new( | |
name => 'I Am the Walrus', | |
artist => $beatles_ac, | |
recording => Recording->new( | |
name => 'I Am the Walrus', | |
artist => $beatles_ac))]))], | |
release_labels => [ | |
ReleaseLabel->new( | |
label => Label->new( | |
label => 'Capitol Records'), | |
catalog_number => 'oops')], | |
date => PartialDate->new( | |
year => 1967, | |
month => 11, | |
day => 27))]); | |
# Though... that catalog number isn't correct. Rather than forcing the | |
# editor to redo all their work, they will reload the edit into the | |
# release editor, and submit a revision of their edit: | |
$group->edits->[0]->new_revision( | |
release_labels => [ | |
ReleaseLabel->new( | |
label => Label->new( | |
label => 'Capitol Records'), | |
catalog_number => '2056')], | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment