<commit_before>require 'uri'

#TODO:
#Rating SCORE IS NOT ROUNDING TO TWO DECIMAL PLACES!!!!

class AnimesController < ApplicationController

	def index
	end

	def search
		@anime = Anime.new
	end

	def create
    search_string = (params["anime"]["title"] || params["anime"])
  	@search_input = search_string.gsub(" ", "-").downcase

    @anime = get_anime_by_db(@search_input)
    
    if @anime    
      @video_ids = get_youtube_ids(@anime)
      render "show"
    else
      get_anime(@search_input)

      if @response.headers[:status] == "200 OK"
        @anime = Anime.create(title: @response.body["title"], 
          description: @response.body["synopsis"], 
          score: @response.body["community_rating"],
          img_url: @response.body["cover_image"],
          show_type: @response.body["show_type"],
          starting_date: @response.body["started_airing"],
          end_date: @response.body["finished_airing"],
          eps_length: @response.body["episode_length"],
          eps_count: @response.body["episode_count"],
          show_status: @response.body["status"],
          age_rating:  @response.body["age_rating"],
          humm_id: @response.body["id"],
          slug: @response.body["slug"])

        @video_ids = get_youtube_ids(@anime)

        render "show"
      else
        @anime = Anime.new
        @error = "No results found for \"#{params["anime"]["title"]}\"."

        render "search"
  	  end
    end
	end

	def random
		@anime = Anime.discover

    @anime.genres.each do |genre|
      if genre.name == "Hentai" || genre.name == "Yuri" || genre.name == "Yaoi"
        @anime = nil
        random
      end
    end
    @video_ids = get_youtube_ids(@anime)
		render "show"
	end

	def show
	
	end

  def get_anime_by_db(search_input)
    @anime = Anime.find_by_slug(search_input)
  end


  def get_anime(search_input)
    @response = Unirest.get "https://hummingbirdv1.p.mashape.com/anime/#{search_input}",
    headers:{
      "X-Mashape-Key" => ENV["HUMM_API_KEY"],
      "Accept" => "application/json"
    }
  end

  def animes_in_genre
    @genre = params["genre"]
    @animes_in_genre_array = Genre.find_by('name' => params['genre']).animes
    @animes_in_genre_array = @animes_in_genre_array.paginate(:page => params[:page], :per_page => 100)
    @message = "No animes in this genre."
    render "animes_in_genre"
  end

  def add_to_watch_list
    @anime = Anime.find_by(:title => params['save_this_anime'])
    SavedAnime.create(:anime_id => @anime.id, :user_id => current_user.id)
    @video_ids = get_youtube_ids(@anime)
    render :show
  end

  def watchlist
    @animes = current_user.animes
    render :watchlist
  end


  def destroy
    @saved_anime_deleted = SavedAnime.find_by(:anime_id => params["id"])
    @saved_anime_deleted.destroy
    redirect_to "/watchlist"
  end

  def get_youtube_ids(anime)
    @video_ids = []

    list = YoutubeLoad.new.search("#{anime.title}")
    list[0..5].each do |listing|

        @video_ids << listing
    end
    return @video_ids
  end<commit_msg>tookout extra iteration<commit_after>require 'uri'

#TODO:
#Rating SCORE IS NOT ROUNDING TO TWO DECIMAL PLACES!!!!

class AnimesController < ApplicationController

	def index
	end

	def search
		@anime = Anime.new
	end

	def create
    search_string = (params["anime"]["title"] || params["anime"])
  	@search_input = search_string.gsub(" ", "-").downcase

    @anime = get_anime_by_db(@search_input)
    
    if @anime    
      @video_ids = get_youtube_ids(@anime)
      render "show"
    else
      get_anime(@search_input)

      if @response.headers[:status] == "200 OK"
        @anime = Anime.create(title: @response.body["title"], 
          description: @response.body["synopsis"], 
          score: @response.body["community_rating"],
          img_url: @response.body["cover_image"],
          show_type: @response.body["show_type"],
          starting_date: @response.body["started_airing"],
          end_date: @response.body["finished_airing"],
          eps_length: @response.body["episode_length"],
          eps_count: @response.body["episode_count"],
          show_status: @response.body["status"],
          age_rating:  @response.body["age_rating"],
          humm_id: @response.body["id"],
          slug: @response.body["slug"])

        @video_ids = get_youtube_ids(@anime)

        render "show"
      else
        @anime = Anime.new
        @error = "No results found for \"#{params["anime"]["title"]}\"."

        render "search"
  	  end
    end
	end

	def random
		@anime = Anime.discover

    @anime.genres.each do |genre|
      if genre.name == "Hentai" || genre.name == "Yuri" || genre.name == "Yaoi"
        @anime = nil
        random
      end
    end
    @video_ids = get_youtube_ids(@anime)
		render "show"
	end

	def show
	
	end

  def get_anime_by_db(search_input)
    @anime = Anime.find_by_slug(search_input)
  end


  def get_anime(search_input)
    @response = Unirest.get "https://hummingbirdv1.p.mashape.com/anime/#{search_input}",
    headers:{
      "X-Mashape-Key" => ENV["HUMM_API_KEY"],
      "Accept" => "application/json"
    }
  end

  def animes_in_genre
    @genre = params["genre"]
    @animes_in_genre_array = Genre.find_by('name' => params['genre']).animes
    @animes_in_genre_array = @animes_in_genre_array.paginate(:page => params[:page], :per_page => 100)
    @message = "No animes in this genre."
    render "animes_in_genre"
  end

  def add_to_watch_list
    @anime = Anime.find_by(:title => params['save_this_anime'])
    SavedAnime.create(:anime_id => @anime.id, :user_id => current_user.id)
    @video_ids = get_youtube_ids(@anime)
    render :show
  end

  def watchlist
    @animes = current_user.animes
    render :watchlist
  end


  def destroy
    @saved_anime_deleted = SavedAnime.find_by(:anime_id => params["id"])
    @saved_anime_deleted.destroy
    redirect_to "/watchlist"
  end

  def get_youtube_ids(anime)
    @video_ids = []
    list = YoutubeLoad.new.search("#{anime.title}")
    @video_ids = list
    return @video_ids
  end
{'fraction_non_alphanumeric': 0.13604094436189532, 'fraction_numerical': 0.0026415717351824337, 'mean_word_length': 3.0279255319148937, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 21, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4608603', 'n_tokens_mistral': 2198, 'n_tokens_neox': 2125, 'n_words': 393}