<commit_before>require 'tvdbr'

class SeriesController < ApplicationController
  include MustBeLoggedIn
  def show
    @id = params[:series_id]
    
    if Series.where(id: @id).first == nil
      respond_to do |format|
        format.html { redirect_to "/watchlist", notice: "No series with that id found"}
      end
    end

    client = Tvdbr::Client.new(Rails.application.secrets.tvdb_api_key)
    # First check to see if there are any existing episodes in our db for the series
    if Episode.where(series_id: @id).first == nil
      # If not, get the series and then the episodes for the series
      series = client.find_series_by_id(@id)
      episodes = series.episodes
      ActiveRecord::Base.transaction do
        # Create an Episode object for each episode that doesn't exist in the db
        episodes.each do |episode|
          if Episode.where(id: episode.id).first == nil
            Episode.create(id: episode.id, series_id: episode.seriesid, episode_number: episode.episode_number, name: episode.name, season_number: episode.season_number, season_id: episode.seasonid, overview: episode.overview)
          end
        end
      end
    end
    
    @info = Series.where(id: @id).select('name, poster_thumb, banner, overview').first
    # Get the count of seasons and season names (usually numbers)
    @seasons = Episode.where(series_id: @id).uniq.pluck('season_number, season_id')
    @seasons_count = @seasons.length
    # Remove the "0" season and replace with "Specials" as per the TVDB database's naming convention
    @seasons.each do |season|
      if season[0] == 0
        season[0] = "Specials"
      end
    end
    @seasons.sort_by! {|x| [x[0].to_s, x[1].to_s]}
  end
  
  def addAllWatched
    user_id = params[:user_id]
    series_id = params[:series_id]<commit_msg>Fixed order of seasons on series pages<commit_after>require 'tvdbr'

class SeriesController < ApplicationController
  include MustBeLoggedIn
  def show
    @id = params[:series_id]
    
    if Series.where(id: @id).first == nil
      respond_to do |format|
        format.html { redirect_to "/watchlist", notice: "No series with that id found"}
      end
    end

    client = Tvdbr::Client.new(Rails.application.secrets.tvdb_api_key)
    # First check to see if there are any existing episodes in our db for the series
    if Episode.where(series_id: @id).first == nil
      # If not, get the series and then the episodes for the series
      series = client.find_series_by_id(@id)
      episodes = series.episodes
      ActiveRecord::Base.transaction do
        # Create an Episode object for each episode that doesn't exist in the db
        episodes.each do |episode|
          if Episode.where(id: episode.id).first == nil
            Episode.create(id: episode.id, series_id: episode.seriesid, episode_number: episode.episode_number, name: episode.name, season_number: episode.season_number, season_id: episode.seasonid, overview: episode.overview)
          end
        end
      end
    end
    
    @info = Series.where(id: @id).select('name, poster_thumb, banner, overview').first
    # Get the count of seasons and season names (usually numbers)
    @seasons = Episode.where(series_id: @id).uniq.pluck('season_number, season_id')
    @seasons_count = @seasons.length
    @seasons.sort!
    # Remove the "0" season and replace with "Specials" as per the TVDB database's naming convention
    @seasons.each do |season|
      if season[0] == 0
        season[0] = "Specials"
      end
    end
  end
  
  def addAllWatched
    user_id = params[:user_id]
    series_id = params[:series_id]
{'fraction_non_alphanumeric': 0.09480122324159021, 'fraction_numerical': 0.0027800945232137894, 'mean_word_length': 3.088636363636364, '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': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3501374', 'n_tokens_mistral': 1101, 'n_tokens_neox': 1088, 'n_words': 334}