class Admin::VideosController

Controlador para la administración de videos de la WebTV

Public Instance Methods

auto_complete_for_video_tag_list_es() click to toggle source

Lista de tags para el auto-complete

# File app/controllers/admin/videos_controller.rb, line 228
def auto_complete_for_video_tag_list_es
  auto_complete_for_tag_list(params[:video][:tag_list_es])
  if @tags.length > 0
    render :inline => "<%= content_tag(:ul, @tags.map {|t| content_tag(:li, t.nombre)}) %>"
  else
    render :nothing => true
  end  
end
create() click to toggle source

Crear un video

# File app/controllers/admin/videos_controller.rb, line 69
def create
  @title = "Crear video"
  @video = Video.new(params[:video])
  
  if @video.save
    flash[:notice] = 'El video se ha guardado correctamente'
    redirect_to admin_video_path(@video)
  else
    render :action => 'new'
  end
end
create_with_subtitles() click to toggle source

Importar el vídeo y subir el fichero con los subtítulos. El vídeo se importa a la webTV de la misma manera de la que se hace desde el rake task. La visibilidad del vídeo en los diferentes idiomas se “decide” a partir de los fichero subidos y el fichero SRT ue se sube ya tiene indicado a qúé idioma pertenece.

# File app/controllers/admin/videos_controller.rb, line 105
def create_with_subtitles
  if document = Document.find(params[:video][:document_id])
    flv_url = params[:video].delete(:flv_url)
    video_path = flv_url.sub(/^#{Document::MULTIMEDIA_URL}/, '').sub(/(_es|_eu|_en)*.flv$/, '')
    visibility = lang_visibility(video_path)
    video_params = {:video_path => video_path,
                    :show_in_es => visibility[:es], 
                    :show_in_eu => visibility[:eu], 
                    :show_in_en => visibility[:en],
                    :title_es => document.title_es, 
                    :title_eu => document.title_eu || document.title_es, 
                    :title_en => document.title_en || document.title_es, 
                    :published_at => document.published_at}
    
    @video = document.webtv_videos.build(params[:video].merge(video_params))
    if @video.save
      flash[:notice] = t('sadmin.subtitles.video_con_subtitulos_creado')
    else
      logger.error "ERROR admin/videos/create_with_subtitles: #{@video.errors.inspect}"
      flash[:error] = t('sadmin.subtitles.video_con_subtitulos_no_creado')
    end
    redirect_to sadmin_news_subtitles_path(:news_id => document.id)
  else
    flash[:error] = t('sadmin.subtitles.no_hemos_encontrado_el_documento')
    redirect_to default_url_for_user
  end
end
delete_subtitles() click to toggle source

Eliminar el SRT para un idioma concreto

# File app/controllers/admin/videos_controller.rb, line 152
def delete_subtitles
  @video = Video.find(params[:id])
  
  unless @video.document
    flash[:error] = t('sadmin.subtitles.solo_se_pueden_gestionar_videos_con_documento')
    redirect_to admin_video_path(@video) and return
  end
  
  lang = params[:lang]
  if s = @video.respond_to?("subtitles_#{lang}")
    @video.send("subtitles_#{lang}=", nil) 
    if @video.save
      flash[:notice] = t('sadmin.subtitles.fichero_eliminado')
    else
      logger.error "ERROR admin/videos.delete_subtitles: #{@video.errors.inspect}"
      flash[:error] = t('sadmin.subtitles.fichero_no_eliminado')
    end
  end
  
  redirect_to sadmin_news_subtitles_path(:news_id => @video.document_id)
end
destroy() click to toggle source

Eliminar un video

# File app/controllers/admin/videos_controller.rb, line 182
def destroy
  @video = Video.find(params[:id])
  if @video.destroy
    flash[:notice] = "El video ha sido eliminado"
    redirect_to admin_videos_path
  else
    flash[:error] = "No hemos podido eliminar el video"
    redirect_to admin_video_path(@video)
  end
end
edit() click to toggle source

Modificar un video

# File app/controllers/admin/videos_controller.rb, line 82
def edit
  @title = "Modificar video"
  @video = Video.find(params[:id])
end
find_video() click to toggle source

Buscar el video en la ruta especificada

# File app/controllers/admin/videos_controller.rb, line 194
def find_video
  v = Video.new(:video_path => params[:video_path])
  if !v.valid? && v.errors.on("video_path")
    render :update do |page|
      page.replace_html :find_video, :text => "<span style='color:red'>Directorio incorrecto.<br/> #{v.errors.on('video_path')}</span>"
    end
  else        
    logger.info "Buscando videos en #{Video::VIDEO_PATH + params[:video_path] + '*.flv'}"
    found_videos = Video.videos_in_dir(params[:video_path])
    if found_videos.length > 0
      found_preview_photo = File.exists?("#{Video::VIDEO_PATH + params[:video_path]}.jpg")
      render :update do |page|
        page.replace_html :find_video, :text => "<span style='color:green'>#{found_videos.length} videos encontrados</span>"
        if found_preview_photo
          page.insert_html :bottom, :find_video, :text => ". <span style='color:green'>Foto para el preview encontrada</span>"
        else
          page.insert_html :bottom, :find_video, :text => ". <span style='color:red'>Foto para el preview NO encontrada</span>"
        end
      end
    else
      if File.exists?("#{Video::VIDEO_PATH + params[:video_path]}.jpg")
        render :update do |page|
          page.replace_html :find_video, :text => "<span style='color:green'>1 imagen encontrada</span>"
        end
      else
        render :update do |page|
          page.replace_html :find_video, :text => "<span style='color:red'>video NO encontrado</span>"
        end
      end
    end
  end
end
index() click to toggle source

Listado de videos

# File app/controllers/admin/videos_controller.rb, line 31
def index
  @sort_order = params[:sort] ||  "update"
  
  case @sort_order
  when "update"
    order = "featured DESC, updated_at DESC, title_es, published_at DESC"
  when "publish"
    order = "featured DESC, published_at DESC, title_es, updated_at DESC"
  when "title"
    order = "featured DESC, lower(tildes(title_es)), published_at DESC, updated_at DESC"
  end
  
  conditions = []
  if params[:q].present?
    conditions << "lower(tildes(coalesce(title_es, '') || ' ' || coalesce(title_eu, ''))) like '%#{params[:q].tildes.downcase}%'"
  end   

  @videos = Video.paginate :page => params[:page], :per_page => 20, 
    :order => order,
    :conditions => conditions.join(' AND ')

  @title = "Videos"
  
end
new() click to toggle source

Formulario de nuevo video

# File app/controllers/admin/videos_controller.rb, line 63
def new
  @title = "Nuevo video"
  @video = Video.new
end
publish() click to toggle source

/Subtítulos

# File app/controllers/admin/videos_controller.rb, line 175
def publish
  @video = Video.find(params[:id])
  @video.update_attributes(:published_at => Time.zone.now)
  redirect_to :back
end
show() click to toggle source

Vista de un video

# File app/controllers/admin/videos_controller.rb, line 57
def show
  @video = Video.find(params[:id])
  @title = @video.title
end
update() click to toggle source

Actualizar un video

# File app/controllers/admin/videos_controller.rb, line 88
def update
  @video = Video.find(params[:id])
  
  if @video.update_attributes(params[:video])
    flash[:notice] = 'El documento se ha guardado correctamente'
    redirect_to admin_video_path(@video)
  else
    render :action => params[:return_to] || 'edit'
  end
end
update_subtitles() click to toggle source

Subir/sustituir el fichero con los subtítulos en un idioma

# File app/controllers/admin/videos_controller.rb, line 134
def update_subtitles
  @video = Video.find(params[:id])
  
  unless @video.document
    flash[:error] = t('sadmin.subtitles.solo_se_pueden_subir_subtitulos_para_documento')
    redirect_to admin_video_path(@video) and return
  end
  
  if @video.update_attributes(params[:video])
    flash[:notice] = t('sadmin.subtitles.fichero_guardado')
  else
    logger.error "ERROR admin/videos/update_subtitles: #{@video.errors.inspect}"
    flash[:error] = t('sadmin.subtitles.fichero_no_guardado')
  end
  redirect_to sadmin_news_subtitles_path(:news_id => @video.document_id)
end