<commit_before>require 'librarix/filter'
require 'librarix/menu'
require 'librarix/the_movie_db'
require 'librarix/helpers'

require 'sinatra/base'
require 'sinatra/content_for'
require 'sinatra/json'

require 'yaml'
require 'slim'
require 'themoviedb'

module Librarix
  class Application < Sinatra::Application
    def initialize(app = nil)
      super

      Librarix::Menu.menu.add 'Home', '/'
      Librarix::Menu.menu.add 'Add a movie', '/search'
    end

    helpers Librarix::TheMovieDB
    helpers Librarix::Menu::Helper
    helpers Librarix::Helpers

    get '/' do
      slim :index, locals: {movies: Librarix::Filter.new(params).movies}
    end

    get '/search' do
      movies = if params['search'].nil?
        Tmdb::Movie.popular.map { |m| Tmdb::Movie.new(m) }
      elsif params['search'] == ''
        []
      else
        Tmdb::Movie.find(params['search'])
      end

      if request.xhr?
        slim :list, layout: false, locals: {movies: movies}
      else
        slim :search, locals: {movies: movies}
      end
    end

    post '/add' do
      id = params[:id].to_i
      movie = Tmdb::Movie.detail(id)

      if movie['status_code'] == 34
      elsif Librarix::Redis::Movie.new(id).added?
      else
        Librarix::Redis::Movie.new(id).add<commit_msg>Add action to get movie infos<commit_after>require 'librarix/filter'
require 'librarix/menu'
require 'librarix/the_movie_db'
require 'librarix/helpers'

require 'sinatra/base'
require 'sinatra/content_for'
require 'sinatra/json'

require 'yaml'
require 'slim'
require 'themoviedb'

module Librarix
  class Application < Sinatra::Application
    def initialize(app = nil)
      super

      Librarix::Menu.menu.add 'Home', '/'
      Librarix::Menu.menu.add 'Add a movie', '/search'
    end

    helpers Librarix::TheMovieDB
    helpers Librarix::Menu::Helper
    helpers Librarix::Helpers

    get '/' do
      slim :index, locals: {movies: Librarix::Filter.new(params).movies}
    end

    get '/movie/:id' do |id|
      movie = Librarix::Redis::Movie.new(id).fetch
      slim :movie, layout: !request.xhr?, locals: {movie: movie}
    end

    get '/search' do
      movies = if params['search'].nil?
        Tmdb::Movie.popular.map { |m| Tmdb::Movie.new(m) }
      elsif params['search'] == ''
        []
      else
        Tmdb::Movie.find(params['search'])
      end

      if request.xhr?
        slim :list, layout: false, locals: {movies: movies}
      else
        slim :search, locals: {movies: movies}
      end
    end

    post '/add' do
      id = params[:id].to_i
      movie = Tmdb::Movie.detail(id)

      if movie['status_code'] == 34
      elsif Librarix::Redis::Movie.new(id).added?
      else
        Librarix::Redis::Movie.new(id).add
{'fraction_non_alphanumeric': 0.13696128560993426, 'fraction_numerical': 0.0014609203798392988, 'mean_word_length': 2.830769230769231, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '1976255', 'n_tokens_mistral': 991, 'n_tokens_neox': 963, 'n_words': 210}