voluntary_music_metadata_enrichment 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +23 -0
- data/app/assets/javascripts/voluntary_music_metadata_enrichment/application.js +5 -0
- data/app/assets/javascripts/voluntary_music_metadata_enrichment/groups/show.js.coffee +14 -0
- data/app/assets/javascripts/voluntary_music_metadata_enrichment/library/index.js.coffee +19 -0
- data/app/assets/javascripts/voluntary_music_metadata_enrichment/library/year_in_review_releases/index_view.js.coffee +32 -0
- data/app/assets/javascripts/voluntary_music_metadata_enrichment/library/year_in_review_releases/new_view.js.coffee +31 -0
- data/app/assets/javascripts/voluntary_music_metadata_enrichment/library/year_in_review_tracks/index_view.js.coffee +32 -0
- data/app/assets/javascripts/voluntary_music_metadata_enrichment/library/year_in_review_tracks/new_view.js.coffee +31 -0
- data/app/assets/javascripts/voluntary_music_metadata_enrichment/library/years_in_review/index_view.js.coffee +36 -0
- data/app/assets/javascripts/voluntary_music_metadata_enrichment/tracks/show.js.coffee +2 -0
- data/app/assets/javascripts/voluntary_music_metadata_enrichment/videos/metadata.js.coffee +6 -0
- data/app/controllers/concerns/music_metadata_enrichment/artist_confirmation.rb +207 -0
- data/app/controllers/concerns/music_metadata_enrichment/base_controller.rb +17 -0
- data/app/controllers/concerns/music_metadata_enrichment/track_confirmation.rb +57 -0
- data/app/controllers/library/music/artists_controller.rb +26 -0
- data/app/controllers/library/music/year_in_review_releases_controller.rb +110 -0
- data/app/controllers/library/music/year_in_review_tracks_controller.rb +110 -0
- data/app/controllers/library/music/years_in_review_controller.rb +41 -0
- data/app/controllers/library/music_controller.rb +14 -0
- data/app/controllers/music_metadata_enrichment/application_controller.rb +11 -0
- data/app/controllers/music_metadata_enrichment/artists_controller.rb +93 -0
- data/app/controllers/music_metadata_enrichment/group_artist_connections_controller.rb +63 -0
- data/app/controllers/music_metadata_enrichment/groups_controller.rb +40 -0
- data/app/controllers/music_metadata_enrichment/releases_controller.rb +207 -0
- data/app/controllers/music_metadata_enrichment/tracks_controller.rb +82 -0
- data/app/controllers/music_metadata_enrichment/videos_controller.rb +133 -0
- data/app/controllers/product/music_metadata_enrichment_controller.rb +6 -0
- data/app/models/concerns/year_in_review_music_entry.rb +12 -0
- data/app/models/music_artist.rb +155 -0
- data/app/models/music_library_artist.rb +10 -0
- data/app/models/music_metadata_enrichment/group.rb +136 -0
- data/app/models/music_metadata_enrichment/group_artist_connection.rb +15 -0
- data/app/models/music_release.rb +278 -0
- data/app/models/music_track.rb +255 -0
- data/app/models/music_video.rb +87 -0
- data/app/models/product/music_metadata_enrichment.rb +2 -0
- data/app/models/year_in_review_music.rb +233 -0
- data/app/models/year_in_review_music_release.rb +24 -0
- data/app/models/year_in_review_music_track.rb +28 -0
- data/app/views/library/music/artists/destroy.js.erb +1 -0
- data/app/views/library/music/index.html.erb +46 -0
- data/app/views/library/music/year_in_review_releases/_collection.html.erb +51 -0
- data/app/views/library/music/year_in_review_releases/_form.html.erb +18 -0
- data/app/views/library/music/year_in_review_releases/_multiple_form.html.erb +44 -0
- data/app/views/library/music/year_in_review_releases/create.js.erb +11 -0
- data/app/views/library/music/year_in_review_releases/destroy.js.erb +2 -0
- data/app/views/library/music/year_in_review_releases/export.html.erb +13 -0
- data/app/views/library/music/year_in_review_releases/index.html.erb +22 -0
- data/app/views/library/music/year_in_review_releases/multiple_new.html.erb +1 -0
- data/app/views/library/music/year_in_review_releases/multiple_new.js.erb +7 -0
- data/app/views/library/music/year_in_review_releases/new.html.erb +1 -0
- data/app/views/library/music/year_in_review_tracks/_collection.html.erb +52 -0
- data/app/views/library/music/year_in_review_tracks/_form.html.erb +18 -0
- data/app/views/library/music/year_in_review_tracks/_multiple_form.html.erb +46 -0
- data/app/views/library/music/year_in_review_tracks/create.js.erb +11 -0
- data/app/views/library/music/year_in_review_tracks/destroy.js.erb +2 -0
- data/app/views/library/music/year_in_review_tracks/export.html.erb +13 -0
- data/app/views/library/music/year_in_review_tracks/index.html.erb +22 -0
- data/app/views/library/music/year_in_review_tracks/multiple_new.html.erb +1 -0
- data/app/views/library/music/year_in_review_tracks/multiple_new.js.erb +7 -0
- data/app/views/library/music/year_in_review_tracks/new.html.erb +1 -0
- data/app/views/library/music/years_in_review/_collection.html.erb +52 -0
- data/app/views/library/music/years_in_review/create.js.erb +6 -0
- data/app/views/library/music/years_in_review/index.html.erb +18 -0
- data/app/views/library/music/years_in_review/show.html.erb +20 -0
- data/app/views/music_metadata_enrichment/artists/_collection.html.erb +68 -0
- data/app/views/music_metadata_enrichment/artists/by_name.html.erb +3 -0
- data/app/views/music_metadata_enrichment/artists/index.html.erb +7 -0
- data/app/views/music_metadata_enrichment/artists/name_confirmation.html.erb +1 -0
- data/app/views/music_metadata_enrichment/artists/new.html.erb +1 -0
- data/app/views/music_metadata_enrichment/artists/show.html.erb +24 -0
- data/app/views/music_metadata_enrichment/group_artist_connections/import.html.erb +6 -0
- data/app/views/music_metadata_enrichment/group_artist_connections/index.html.erb +0 -0
- data/app/views/music_metadata_enrichment/group_artist_connections/name_confirmation.html.erb +1 -0
- data/app/views/music_metadata_enrichment/group_artist_connections/new.html.erb +1 -0
- data/app/views/music_metadata_enrichment/groups/index.html.erb +0 -0
- data/app/views/music_metadata_enrichment/groups/new.html.erb +7 -0
- data/app/views/music_metadata_enrichment/groups/show.html.erb +31 -0
- data/app/views/music_metadata_enrichment/releases/_collection.html.erb +53 -0
- data/app/views/music_metadata_enrichment/releases/announce.html.erb +10 -0
- data/app/views/music_metadata_enrichment/releases/artist_confirmation.html.erb +1 -0
- data/app/views/music_metadata_enrichment/releases/by_name.html.erb +24 -0
- data/app/views/music_metadata_enrichment/releases/export.html.erb +17 -0
- data/app/views/music_metadata_enrichment/releases/index.html.erb +8 -0
- data/app/views/music_metadata_enrichment/releases/name.html.erb +9 -0
- data/app/views/music_metadata_enrichment/releases/name_confirmation.html.erb +33 -0
- data/app/views/music_metadata_enrichment/releases/new.html.erb +1 -0
- data/app/views/music_metadata_enrichment/releases/show.html.erb +50 -0
- data/app/views/music_metadata_enrichment/shared/_artist_confirmation_form.html.erb +41 -0
- data/app/views/music_metadata_enrichment/shared/_new_artist_form.html.erb +10 -0
- data/app/views/music_metadata_enrichment/shared/_new_track_form.html.erb +9 -0
- data/app/views/music_metadata_enrichment/shared/_track_confirmation_form.html.erb +29 -0
- data/app/views/music_metadata_enrichment/tracks/_spotify_track_player.html.erb +3 -0
- data/app/views/music_metadata_enrichment/tracks/artist_confirmation.html.erb +1 -0
- data/app/views/music_metadata_enrichment/tracks/by_name.html.erb +26 -0
- data/app/views/music_metadata_enrichment/tracks/index.html.erb +8 -0
- data/app/views/music_metadata_enrichment/tracks/name.html.erb +1 -0
- data/app/views/music_metadata_enrichment/tracks/name_confirmation.html.erb +1 -0
- data/app/views/music_metadata_enrichment/tracks/new.html.erb +1 -0
- data/app/views/music_metadata_enrichment/tracks/show.html.erb +21 -0
- data/app/views/music_metadata_enrichment/videos/_collection.html.erb +25 -0
- data/app/views/music_metadata_enrichment/videos/artist_confirmation.html.erb +1 -0
- data/app/views/music_metadata_enrichment/videos/by_name.html.erb +3 -0
- data/app/views/music_metadata_enrichment/videos/index.html.erb +8 -0
- data/app/views/music_metadata_enrichment/videos/metadata.html.erb +25 -0
- data/app/views/music_metadata_enrichment/videos/new.html.erb +1 -0
- data/app/views/music_metadata_enrichment/videos/show.html.erb +9 -0
- data/app/views/music_metadata_enrichment/videos/track_confirmation.html.erb +1 -0
- data/app/views/music_metadata_enrichment/videos/track_name.html.erb +1 -0
- data/app/views/product/music_metadata_enrichment/index.html.erb +6 -0
- data/config/locales/en.yml +16 -0
- data/config/locales/resources/music_artists/en.yml +43 -0
- data/config/locales/resources/music_library/en.yml +8 -0
- data/config/locales/resources/music_metadata_enrichment_group_artist_connections/en.yml +19 -0
- data/config/locales/resources/music_metadata_enrichment_groups/en.yml +25 -0
- data/config/locales/resources/music_releases/en.yml +67 -0
- data/config/locales/resources/music_tracks/en.yml +45 -0
- data/config/locales/resources/music_videos/en.yml +56 -0
- data/config/locales/resources/year_in_review_music_releases/en.yml +19 -0
- data/config/locales/resources/year_in_review_music_tracks/en.yml +19 -0
- data/config/locales/resources/years_in_review_music/en.yml +21 -0
- data/config/main_music_metadata_enrichment_navigation.rb +3 -0
- data/config/routes.rb +121 -0
- data/db/migrate/20150106183434_add_product_music_metadata_enrichment.rb +96 -0
- data/db/migrate/20150120091801_create_music_metadata_enrichment_groups.rb +28 -0
- data/db/migrate/20150120221419_create_music_library_artists.rb +12 -0
- data/db/migrate/20150123082224_year_in_review_music_entries.rb +53 -0
- data/lib/tasks/voluntary_music_metadata_enrichment_tasks.rake +4 -0
- data/lib/voluntary_music_metadata_enrichment/ability.rb +27 -0
- data/lib/voluntary_music_metadata_enrichment/concerns/model/user/has_music_library.rb +101 -0
- data/lib/voluntary_music_metadata_enrichment/engine.rb +20 -0
- data/lib/voluntary_music_metadata_enrichment/navigation.rb +49 -0
- data/lib/voluntary_music_metadata_enrichment/version.rb +3 -0
- data/lib/voluntary_music_metadata_enrichment.rb +13 -0
- metadata +525 -0
@@ -0,0 +1,82 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
class MusicMetadataEnrichment::TracksController < ::MusicMetadataEnrichment::ApplicationController
|
3
|
+
include ::MusicMetadataEnrichment::BaseController
|
4
|
+
include Applicat::Mvc::Controller::Resource
|
5
|
+
include ::MusicMetadataEnrichment::ArtistConfirmation
|
6
|
+
|
7
|
+
authorize_resource class: 'MusicTrack', except: [:by_name]
|
8
|
+
|
9
|
+
def index
|
10
|
+
end
|
11
|
+
|
12
|
+
def autocomplete
|
13
|
+
artist = MusicArtist.find(params[:artist_id])
|
14
|
+
render json: (
|
15
|
+
artist.tracks.select('id, name').where("name LIKE ?", "#{params[:term]}%").order(:name).limit(10).map{|r| { id: r.id, value: r.name } }
|
16
|
+
), root: false
|
17
|
+
end
|
18
|
+
|
19
|
+
def new
|
20
|
+
build_artist
|
21
|
+
end
|
22
|
+
|
23
|
+
def artist_confirmation
|
24
|
+
confirm_artist('new_track')
|
25
|
+
end
|
26
|
+
|
27
|
+
def select_artist
|
28
|
+
artist_selection('new_track')
|
29
|
+
end
|
30
|
+
|
31
|
+
def name
|
32
|
+
build_track
|
33
|
+
end
|
34
|
+
|
35
|
+
def name_confirmation
|
36
|
+
build_track
|
37
|
+
|
38
|
+
@tracks = MusicTrack.search_on_musicbrainz(@track.artist.mbid, @track.name)
|
39
|
+
end
|
40
|
+
|
41
|
+
def create
|
42
|
+
build_track
|
43
|
+
track_creation('new_track')
|
44
|
+
end
|
45
|
+
|
46
|
+
def show
|
47
|
+
@track = MusicTrack.find(params[:id])
|
48
|
+
get_variables_for_show
|
49
|
+
end
|
50
|
+
|
51
|
+
def by_name
|
52
|
+
if params[:artist_name].blank? || params[:name].blank?
|
53
|
+
flash[:alert] = I18n.t('music_tracks.by_name.artist_name_or_name_blank')
|
54
|
+
redirect_to music_tracks_path(artist_name: params[:artist_name], name: params[:name]) and return
|
55
|
+
end
|
56
|
+
|
57
|
+
@tracks = MusicTrack.by_artist_and_name(params[:artist_name], params[:name])
|
58
|
+
@track = @tracks.first if params[:page].blank? && @tracks.count == 1
|
59
|
+
|
60
|
+
if @track
|
61
|
+
get_variables_for_show
|
62
|
+
render :show
|
63
|
+
else
|
64
|
+
@tracks = MusicTrack.without_slaves.artist_and_name_like(params[:artist_name], params[:name]) if @tracks.nil? || @tracks.count == 0
|
65
|
+
@tracks = @tracks.paginate(per_page: 10, page: params[:page] || 1)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def resource
|
70
|
+
@track
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
def get_variables_for_show
|
76
|
+
@videos = @track.videos.order_by_status
|
77
|
+
|
78
|
+
unless @videos.none?
|
79
|
+
@video_likes = current_user.likes_or_dislikes.for_targets('MusicVideo', @videos.map(&:id)).index_by(&:target_id)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
class MusicMetadataEnrichment::VideosController < ::MusicMetadataEnrichment::ApplicationController
|
3
|
+
include ::MusicMetadataEnrichment::BaseController
|
4
|
+
include Applicat::Mvc::Controller::Resource
|
5
|
+
include ::MusicMetadataEnrichment::ArtistConfirmation
|
6
|
+
include ::MusicMetadataEnrichment::TrackConfirmation
|
7
|
+
|
8
|
+
authorize_resource class: 'MusicVideo', except: [:by_name]
|
9
|
+
|
10
|
+
def index
|
11
|
+
if request.xhr?
|
12
|
+
|
13
|
+
if params[:artist_id].present?
|
14
|
+
@videos = MusicVideo.where(artist_id: params[:artist_id])
|
15
|
+
elsif params[:group_id].present?
|
16
|
+
@videos = MusicMetadataEnrichment::Group.find(params[:group_id]).videos
|
17
|
+
elsif params[:uploaded_by_the_user] == 'true'
|
18
|
+
@videos = MusicVideo.where(user_id: params[:user_id])
|
19
|
+
elsif params[:user_id].present?
|
20
|
+
@videos = User.find(params[:user_id]).music_videos
|
21
|
+
end
|
22
|
+
|
23
|
+
@videos = @videos.order('created_at DESC').paginate(per_page: 5, page: params[:page] || 1)
|
24
|
+
|
25
|
+
unless @videos.none? || !user_signed_in?
|
26
|
+
@video_likes = current_user.likes_or_dislikes.for_targets('MusicVideo', @videos.map(&:id)).index_by(&:target_id)
|
27
|
+
end
|
28
|
+
|
29
|
+
render partial: 'music_metadata_enrichment/videos/collection', locals: { paginate: true }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def new
|
34
|
+
if params[:artist_id].present?
|
35
|
+
redirect_to track_name_music_videos_path(music_track: { artist_id: params[:artist_id]})
|
36
|
+
elsif params[:track_id].present?
|
37
|
+
redirect_to metadata_music_videos_path(music_video: { track_id: params[:track_id]})
|
38
|
+
else
|
39
|
+
build_artist
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def artist_confirmation
|
44
|
+
confirm_artist('new_video')
|
45
|
+
end
|
46
|
+
|
47
|
+
def select_artist
|
48
|
+
artist_selection('new_video')
|
49
|
+
end
|
50
|
+
|
51
|
+
def track_name
|
52
|
+
build_track
|
53
|
+
end
|
54
|
+
|
55
|
+
def track_confirmation
|
56
|
+
build_track
|
57
|
+
|
58
|
+
@tracks = MusicTrack.search_on_musicbrainz(@track.artist.mbid, @track.name)
|
59
|
+
end
|
60
|
+
|
61
|
+
def create_track
|
62
|
+
build_track
|
63
|
+
track_creation('new_video')
|
64
|
+
end
|
65
|
+
|
66
|
+
def metadata
|
67
|
+
build_video
|
68
|
+
end
|
69
|
+
|
70
|
+
def create
|
71
|
+
build_video
|
72
|
+
|
73
|
+
if @video.save
|
74
|
+
flash[:notice] = I18n.t('music_videos.create.successful')
|
75
|
+
|
76
|
+
if params[:group_id].present?
|
77
|
+
redirect_to music_group_path(params[:group_id])
|
78
|
+
else
|
79
|
+
redirect_to music_video_path(@video)
|
80
|
+
end
|
81
|
+
else
|
82
|
+
render :metadata
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def show
|
87
|
+
@video = MusicVideo.find(params[:id])
|
88
|
+
end
|
89
|
+
|
90
|
+
def by_name
|
91
|
+
if params[:artist_name].blank? || params[:name].blank?
|
92
|
+
flash[:alert] = I18n.t('music_videos.by_name.artist_name_or_name_blank')
|
93
|
+
redirect_to music_videos_path(artist_name: params[:artist_name], name: params[:name]) and return
|
94
|
+
end
|
95
|
+
|
96
|
+
status = if match = params[:name].match(/\(Live\)|\(Official\)|\(Unofficial\)/i)
|
97
|
+
match[0].gsub(/\(|\)/, '').titleize
|
98
|
+
else
|
99
|
+
nil
|
100
|
+
end
|
101
|
+
|
102
|
+
name = params[:name].gsub(/\(Live\)|\(Official\)|\(Unofficial\)/i, '')
|
103
|
+
|
104
|
+
unless params[:page].present?
|
105
|
+
@videos = MusicVideo.by_artist_and_name(params[:artist_name], name)
|
106
|
+
@videos = @videos.where(status: status) if status.present?
|
107
|
+
|
108
|
+
@video = @videos.first if @videos.count == 1
|
109
|
+
end
|
110
|
+
|
111
|
+
if @video
|
112
|
+
render :show
|
113
|
+
else
|
114
|
+
if @videos.count == 0
|
115
|
+
@videos = MusicVideo.artist_and_name_like(params[:artist_name], name)
|
116
|
+
@videos = @videos.where(status: status) if status.present?
|
117
|
+
end
|
118
|
+
|
119
|
+
@videos = @videos.paginate(per_page: 10, page: params[:page] || 1)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def resource
|
124
|
+
@video
|
125
|
+
end
|
126
|
+
|
127
|
+
private
|
128
|
+
|
129
|
+
def build_video
|
130
|
+
@video = MusicVideo.new(params[:music_video])
|
131
|
+
@video.user_id = current_user.id
|
132
|
+
end
|
133
|
+
end
|
@@ -0,0 +1,155 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
class MusicArtist < ActiveRecord::Base
|
3
|
+
has_many :releases, class_name: 'MusicRelease', foreign_key: 'artist_id', dependent: :destroy
|
4
|
+
has_many :tracks, class_name: 'MusicTrack', foreign_key: 'artist_id'
|
5
|
+
has_many :videos, class_name: 'MusicVideo', foreign_key: 'artist_id'
|
6
|
+
|
7
|
+
scope :name_like, ->(name) do
|
8
|
+
where(MusicArtist.arel_table[:name].matches("%#{name}%"))
|
9
|
+
end
|
10
|
+
|
11
|
+
validates :name, presence: true
|
12
|
+
validates :mbid, presence: true, uniqueness: true, length: { is: 36 }
|
13
|
+
|
14
|
+
after_update :synchronize_artist_name
|
15
|
+
after_create :create_bonustracks_release
|
16
|
+
|
17
|
+
attr_accessible :name, :mbid, :disambiguation, :founded_at, :dissolved_at, :listeners, :plays
|
18
|
+
|
19
|
+
state_machine :state, initial: :without_metadata do
|
20
|
+
event :import_metadata do transition :without_metadata => :active; end
|
21
|
+
|
22
|
+
before_transition :without_metadata => :active do |artist, transition|
|
23
|
+
musicbrainz_artist = MusicBrainz::Artist.find(artist.mbid)
|
24
|
+
|
25
|
+
artist.update_attributes(
|
26
|
+
disambiguation: musicbrainz_artist.disambiguation,
|
27
|
+
founded_at: artist.musicbrainz_date_to_iso_date(musicbrainz_artist.begin),
|
28
|
+
dissolved_at: artist.musicbrainz_date_to_iso_date(musicbrainz_artist.end)
|
29
|
+
)
|
30
|
+
|
31
|
+
lastfm = Lastfm.new(LastfmApiKey, LastfmApiSecret)
|
32
|
+
lastfm_artist = lastfm.artist.get_info(mbid: artist.mbid)
|
33
|
+
artist.update_attributes(listeners: lastfm_artist['stats']['listeners'], plays: lastfm_artist['stats']['playcount'])
|
34
|
+
|
35
|
+
offset, count = 0, 100
|
36
|
+
|
37
|
+
begin
|
38
|
+
release_groups = musicbrainz_artist.release_groups(offset: offset)
|
39
|
+
count = release_groups.total_count
|
40
|
+
|
41
|
+
release_groups.select{|r| ['Album', 'EP'].include?(r.type) && r.secondary_types.select{|st| ['Audiobook', 'Compilation', 'Live', 'Remix'].include?(st)}.none? && r.artists.length == 1}.each do |musicbrainz_release_group|
|
42
|
+
releases = musicbrainz_release_group.releases
|
43
|
+
|
44
|
+
next if releases.select{|r| r.status == 'Official' && (r.media.map(&:format).none? || r.media.map(&:format).select{|f| !['DVD-Video', 'DVD'].include?(f) }.any?) }.none?
|
45
|
+
|
46
|
+
release = MusicRelease.create(artist_id: artist.id, artist_name: artist.name, name: musicbrainz_release_group.title)
|
47
|
+
|
48
|
+
next unless release.persisted?
|
49
|
+
|
50
|
+
release.releases = releases
|
51
|
+
release.import_metadata!
|
52
|
+
end
|
53
|
+
|
54
|
+
offset += 100
|
55
|
+
end while offset < count
|
56
|
+
|
57
|
+
#artist.import_bonus_tracks
|
58
|
+
#artist.import_music_videos_from_tapetv
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def import_bonus_tracks
|
63
|
+
offset = 0
|
64
|
+
count = 100
|
65
|
+
bonus_track_names = []
|
66
|
+
|
67
|
+
begin
|
68
|
+
recordings = MusicBrainz::Recording.search(mbid, nil, limit: 100, offset: offset, create_models: true)
|
69
|
+
count = recordings.total_count
|
70
|
+
recordings = recordings.select{|r| !MusicTrack.name_included_in_bonustrack_blacklist?(r.title) && r.disambiguation.blank? }
|
71
|
+
recording_titles = recordings.map{|r| MusicTrack.format_name(r.title).downcase }.uniq
|
72
|
+
voluntary_names = MusicTrack.where("artist_id = :artist_id AND LOWER(name) IN(:name)", artist_id: id, name: recording_titles).map{|t| t.name.downcase }
|
73
|
+
|
74
|
+
recordings.select{|r| !voluntary_names.include?(MusicTrack.format_name(r.title).downcase) }.each do |recording|
|
75
|
+
next if bonus_track_names.include? MusicTrack.format_name(recording.title).downcase
|
76
|
+
|
77
|
+
track = MusicTrack.new(artist: self, name: MusicTrack.format_name(recording.title))
|
78
|
+
track.artist_mbid = mbid
|
79
|
+
|
80
|
+
if track.is_bonus_track?
|
81
|
+
track.create_bonus_track(recording.id)
|
82
|
+
bonus_track_names << track.name.downcase
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
offset += 100
|
87
|
+
end while offset < count
|
88
|
+
end
|
89
|
+
|
90
|
+
def import_music_videos_from_tapetv
|
91
|
+
tapetv_videos, page = [], 1
|
92
|
+
|
93
|
+
begin
|
94
|
+
response = nil
|
95
|
+
|
96
|
+
begin
|
97
|
+
response = JSON.parse(HTTParty.get("http://www.tape.tv/#{name.split(' ').join('-').downcase}/videos.json?page=#{page}&page_size=8").body)
|
98
|
+
rescue JSON::ParserError
|
99
|
+
end
|
100
|
+
|
101
|
+
break if response.nil?
|
102
|
+
|
103
|
+
tapetv_videos += response.select{|v| !v['title'].match(/\(/) && !v['title'].match(/live/i) }.map{|v| { name: v['title'].gsub(/\(Video\)/, '').strip, url: v['share_url'] } }
|
104
|
+
sleep 5
|
105
|
+
|
106
|
+
break if response.length != 8
|
107
|
+
|
108
|
+
page += 1
|
109
|
+
end while !response.nil? && response.length > 0
|
110
|
+
|
111
|
+
return if tapetv_videos.empty?
|
112
|
+
|
113
|
+
tracks.where('LOWER(name) IN(?)', tapetv_videos.map{|v| MusicTrack.format_name(v[:name]).downcase }).each do |track|
|
114
|
+
tapetv_video = tapetv_videos.select do |v|
|
115
|
+
MusicTrack.format_name(v[:name]).downcase == track.name.downcase ||
|
116
|
+
MusicTrack.format_name(v[:name]).downcase.gsub('ß', 'ss') == track.name.downcase.gsub('ß', 'ss')
|
117
|
+
end.first
|
118
|
+
|
119
|
+
MusicVideo.create(status: 'Official', track_id: track.id, url: tapetv_video[:url]) unless tapetv_video.nil?
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def bonus_tracks_release
|
124
|
+
releases.where(name: '[Bonus Tracks]').first
|
125
|
+
end
|
126
|
+
|
127
|
+
def musicbrainz_date_to_iso_date(date)
|
128
|
+
return date if date.blank?
|
129
|
+
|
130
|
+
splitted_date = date.split('-')
|
131
|
+
|
132
|
+
if splitted_date.length == 1
|
133
|
+
"#{splitted_date.first}-01-01"
|
134
|
+
elsif splitted_date.length == 2
|
135
|
+
"#{splitted_date.first}-#{splitted_date.last}-01"
|
136
|
+
else
|
137
|
+
date
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
private
|
142
|
+
|
143
|
+
def create_bonustracks_release
|
144
|
+
release = releases.create(name: '[Bonus Tracks]')
|
145
|
+
release.update_attribute(:state, 'active')
|
146
|
+
end
|
147
|
+
|
148
|
+
def synchronize_artist_name
|
149
|
+
return unless name_changed?
|
150
|
+
|
151
|
+
[MusicRelease, MusicTrack, MusicVideo].each do |klass|
|
152
|
+
klass.where('artist_id = ?', id).update_all ['artist_name = ?', name]
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
class MusicLibraryArtist < ActiveRecord::Base
|
3
|
+
belongs_to :user
|
4
|
+
belongs_to :artist, class_name: 'MusicArtist'
|
5
|
+
|
6
|
+
validates :user_id, presence: true
|
7
|
+
validates :artist_id, presence: true, uniqueness: { scope: :user_id }
|
8
|
+
|
9
|
+
attr_accessible :user_id, :artist_id, :plays
|
10
|
+
end
|
@@ -0,0 +1,136 @@
|
|
1
|
+
module MusicMetadataEnrichment
|
2
|
+
class Group < ActiveRecord::Base
|
3
|
+
self.table_name = 'music_metadata_enrichment_groups'
|
4
|
+
|
5
|
+
has_many :artist_connections, class_name: 'MusicMetadataEnrichment::GroupArtistConnection', foreign_key: 'group_id', dependent: :destroy
|
6
|
+
has_many :artists, class_name: 'MusicArtist', through: :artist_connections
|
7
|
+
has_many :releases, class_name: 'MusicRelease', through: :artists
|
8
|
+
has_many :videos, class_name: 'MusicVideo', through: :artists
|
9
|
+
|
10
|
+
validates :name, presence: true, uniqueness: { case_sensitive: false }
|
11
|
+
validate :registered_on_lastfm
|
12
|
+
|
13
|
+
attr_accessible :name, :artist_connections_text
|
14
|
+
|
15
|
+
attr_accessor :artist_connections_text
|
16
|
+
|
17
|
+
def import_artist_connections
|
18
|
+
artist_names_without_mbid = []
|
19
|
+
artist_names = artist_connections_text.split("\n").map(&:strip)
|
20
|
+
|
21
|
+
artist_names.each do |artist_name|
|
22
|
+
lastfm = Lastfm.new(LastfmApiKey, LastfmApiSecret)
|
23
|
+
lastfm_artist = lastfm.artist.get_info(artist: artist_name)
|
24
|
+
|
25
|
+
if lastfm_artist['mbid'].blank?
|
26
|
+
artist_names_without_mbid << lastfm_artist['name']
|
27
|
+
|
28
|
+
next
|
29
|
+
end
|
30
|
+
|
31
|
+
artist = MusicArtist.where(mbid: lastfm_artist['mbid']).first
|
32
|
+
|
33
|
+
unless artist
|
34
|
+
musicbrainz_artist = MusicBrainz::Artist.find(lastfm_artist['mbid'])
|
35
|
+
|
36
|
+
if musicbrainz_artist
|
37
|
+
artist = MusicArtist.where(mbid: musicbrainz_artist.id).first
|
38
|
+
artist = MusicArtist.create(name: lastfm_artist['name'], mbid: musicbrainz_artist.id) unless artist
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
next unless artist
|
43
|
+
|
44
|
+
if artist_connections.where(artist_id: artist.id).none?
|
45
|
+
MusicMetadataEnrichment::GroupArtistConnection.create(group_id: id, artist_id: artist.id)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
artist_names_without_mbid
|
50
|
+
end
|
51
|
+
|
52
|
+
def import_artists_of_group_members(options = {})
|
53
|
+
last_page = options[:last_page]
|
54
|
+
last_user_name_from_last_run = options[:last_user_name_from_last_run]
|
55
|
+
library_start_page = options[:library_start_page]
|
56
|
+
|
57
|
+
user_names, page, last_user_name, last_user_name_from_last_run_reached, i = [], nil, nil, false, 1
|
58
|
+
|
59
|
+
lastfm = Lastfm.new(LastfmApiKey, LastfmApiSecret)
|
60
|
+
|
61
|
+
1000.times do |page|
|
62
|
+
page +=1
|
63
|
+
|
64
|
+
if last_page.present? && page == last_page
|
65
|
+
i = (page * 50) + 1
|
66
|
+
elsif last_page.present? && page < last_page
|
67
|
+
next
|
68
|
+
end
|
69
|
+
|
70
|
+
puts "GROUP MEMBERS PAGE: #{page}"
|
71
|
+
|
72
|
+
lastfm_users = nil
|
73
|
+
|
74
|
+
3.times do
|
75
|
+
begin
|
76
|
+
lastfm_users = lastfm.group.get_members(group: 'Dark Electro', page: page)
|
77
|
+
|
78
|
+
break
|
79
|
+
rescue Lastfm::ApiError
|
80
|
+
puts "GROUP MEMBERS PAGE: #{page} ... TRY AGAIN"
|
81
|
+
sleep 30
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
if lastfm_users.select{|u| !user_names.include?(u['name'])}.none?
|
86
|
+
# over last page
|
87
|
+
break
|
88
|
+
end
|
89
|
+
|
90
|
+
lastfm_users.each do |lastfm_user|
|
91
|
+
if user_names.include?(lastfm_user['name'])
|
92
|
+
next
|
93
|
+
else
|
94
|
+
user_names << lastfm_user['name']
|
95
|
+
end
|
96
|
+
|
97
|
+
if lastfm_user['name'] == last_user_name_from_last_run
|
98
|
+
last_user_name_from_last_run_reached = true
|
99
|
+
elsif last_user_name_from_last_run.present? && !last_user_name_from_last_run_reached
|
100
|
+
i += 1
|
101
|
+
next
|
102
|
+
end
|
103
|
+
|
104
|
+
last_user_name = lastfm_user['name']
|
105
|
+
puts "USER #{i}: #{last_user_name} (GROUP MEMBERS PAGE: #{page})"
|
106
|
+
user = User.new
|
107
|
+
user.lastfm_user_name = lastfm_user['name']
|
108
|
+
|
109
|
+
if lastfm_user['name'] == last_user_name_from_last_run && !library_start_page.nil?
|
110
|
+
user.import_music_artists(lastfm, library_start_page)
|
111
|
+
else
|
112
|
+
user.import_music_artists(lastfm)
|
113
|
+
end
|
114
|
+
|
115
|
+
i += 1
|
116
|
+
end
|
117
|
+
|
118
|
+
[page, last_user_name]
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
private
|
123
|
+
|
124
|
+
def registered_on_lastfm
|
125
|
+
return if name.blank?
|
126
|
+
|
127
|
+
lastfm = Lastfm.new(LastfmApiKey, LastfmApiSecret)
|
128
|
+
|
129
|
+
begin
|
130
|
+
lastfm.group.get_members(group: name)
|
131
|
+
rescue Lastfm::ApiError
|
132
|
+
errors[:name] << I18n.t('activerecord.errors.models.music_metadata_enrichment_group.attributes.name.not_registered_on_lastfm')
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module MusicMetadataEnrichment
|
2
|
+
class GroupArtistConnection < ActiveRecord::Base
|
3
|
+
include Likeable
|
4
|
+
|
5
|
+
self.table_name = 'music_metadata_enrichment_group_artist_connections'
|
6
|
+
|
7
|
+
belongs_to :group, class_name: 'MusicMetadataEnrichment::Group'
|
8
|
+
belongs_to :artist, class_name: 'MusicArtist'
|
9
|
+
|
10
|
+
validates :group_id, presence: true
|
11
|
+
validates :artist_id, presence: true, uniqueness: { scope: :group_id }
|
12
|
+
|
13
|
+
attr_accessible :group_id, :artist_id
|
14
|
+
end
|
15
|
+
end
|