Class: MusicMetadataEnrichment::VideosController

Inherits:
ApplicationController show all
Includes:
Applicat::Mvc::Controller::Resource, ArtistConfirmation, BaseController, TrackConfirmation
Defined in:
app/controllers/music_metadata_enrichment/videos_controller.rb

Instance Method Summary collapse

Methods included from ArtistConfirmation

#artist_selection, #build_artist, #confirm_artist, #create_artist, #redirect_after_artist_available, #render_modal_javascript_response, #set_template_name_for_xhr_or_render

Methods included from BaseController

#application_navigation, #navigation_product_name, #navigation_product_path

Instance Method Details

#artist_confirmationObject



40
41
42
# File 'app/controllers/music_metadata_enrichment/videos_controller.rb', line 40

def artist_confirmation
  confirm_artist('new_video')
end

#by_nameObject



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'app/controllers/music_metadata_enrichment/videos_controller.rb', line 90

def by_name
  if params[:artist_name].blank? || params[:name].blank?
    flash[:alert] = I18n.t('music_videos.by_name.artist_name_or_name_blank')
    redirect_to music_videos_path(artist_name: params[:artist_name], name: params[:name]) and return
  end
   
  status = if match = params[:name].match(/\(Live\)|\(Official\)|\(Unofficial\)/i)
    match[0].gsub(/\(|\)/, '').titleize
  else
    nil
  end
  
  name = params[:name].gsub(/\(Live\)|\(Official\)|\(Unofficial\)/i, '')
  
  unless params[:page].present?
    @videos = MusicVideo.by_artist_and_name(params[:artist_name], name)
    @videos = @videos.where(status: status) if status.present?
    
    @video = @videos.first if @videos.count == 1
  end
  
  if @video
    render :show
  else
    if @videos.count == 0
      @videos = MusicVideo.artist_and_name_like(params[:artist_name], name)
      @videos = @videos.where(status: status) if status.present?
    end
    
    @videos = @videos.paginate(per_page: 10, page: params[:page] || 1)
  end
end

#createObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'app/controllers/music_metadata_enrichment/videos_controller.rb', line 69

def create
  build_video
  
  if @video.save
    flash[:notice] = I18n.t('music_videos.create.successful')
    
    if params[:group_id].present?
      redirect_to music_group_path(params[:group_id])
    else
      redirect_to music_video_path(@video)
    end
  else
    render :metadata
  end
end

#create_trackObject



60
61
62
63
# File 'app/controllers/music_metadata_enrichment/videos_controller.rb', line 60

def create_track
  build_track
  track_creation('new_video')
end

#indexObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/controllers/music_metadata_enrichment/videos_controller.rb', line 10

def index
  if request.xhr? 

    if params[:artist_id].present?
      @videos = MusicVideo.where(artist_id: params[:artist_id])
    elsif params[:group_id].present?
      @videos = MusicMetadataEnrichment::Group.find(params[:group_id]).videos
    elsif params[:uploaded_by_the_user] == 'true'
      @videos = MusicVideo.where(user_id: params[:user_id])
    elsif params[:user_id].present?
      @videos = User.by_slug_or_id(params[:user_id]).music_videos
    end
    
    @videos = @videos.order('created_at DESC').paginate(per_page: 5, page: params[:page] || 1)
    @video_likes = MusicVideo.likes_or_dislikes_for(current_user, @videos.map(&:id)) unless !user_signed_in? || @videos.none?
    
    render partial: 'music_metadata_enrichment/videos/collection', locals: { paginate: true }
  end
end

#metadataObject



65
66
67
# File 'app/controllers/music_metadata_enrichment/videos_controller.rb', line 65

def 
  build_video
end

#newObject



30
31
32
33
34
35
36
37
38
# File 'app/controllers/music_metadata_enrichment/videos_controller.rb', line 30

def new
  if params[:artist_id].present?
    redirect_to track_name_music_videos_path(music_track: { artist_id: params[:artist_id]})
  elsif params[:track_id].present?
    redirect_to (music_video: { track_id: params[:track_id]})  
  else
    build_artist
  end
end

#resourceObject



123
124
125
# File 'app/controllers/music_metadata_enrichment/videos_controller.rb', line 123

def resource
  @video
end

#select_artistObject



44
45
46
# File 'app/controllers/music_metadata_enrichment/videos_controller.rb', line 44

def select_artist
  artist_selection('new_video')
end

#showObject



85
86
87
88
# File 'app/controllers/music_metadata_enrichment/videos_controller.rb', line 85

def show
  @video = MusicVideo.find(params[:id])
  @video_likes = MusicVideo.likes_or_dislikes_for(current_user, [@video.id]) if user_signed_in?
end

#track_confirmationObject



52
53
54
55
56
57
58
# File 'app/controllers/music_metadata_enrichment/videos_controller.rb', line 52

def track_confirmation
  build_track
  
  @tracks = MusicTrack.search_on_musicbrainz(@track.artist.mbid, @track.name)
  
  track_creation('new_video', @track.name) if @tracks.none?
end

#track_nameObject



48
49
50
# File 'app/controllers/music_metadata_enrichment/videos_controller.rb', line 48

def track_name
  build_track
end