<commit_before>console.clear = -> #doNothing
console.log = -> #doNothing


# ===
#  jQuery Plugins
# -
$.extend
  urlParams: (url) ->
    match = null
    pl = /\+/g
    search = /([^&=]+)=?([^&]*)/g
    decode = (s) ->
      decodeURIComponent(s.replace(pl, " "))
    query = url
    params = {}
    while match = search.exec(query)
      params[decode(match[1])] = decode(match[2])
    params

# ===
#  Backbone.js App
# -
window.App =
  Models: {}
  Views: {}
  Collections: {}
  Router: {}
  Live: {}
  Config:
    movieSearchURL: "https://www.google.com/uds/GwebSearch?key=notsupplied&v=1.0&safe=off&filter=0&gl=www.google.com&rsz=large&gss=.com&callback=?"
    movieDescriptionURL: "http://api.trakt.tv/movie/summary.json/515a27ba95fbd83f20690e5c22bceaff0dfbde7c"
    movieStreamsURL: "http://whateverorigin.org/get?url=https%3A//docs.google.com/get_video_info%3Fauthuser%3D%26docid%3D##VIDEOID##&callback=?" #TODO &mobile=true when touch detected when modernizr added. 
    catalogURL: "https://yts.re/api/list.json"
    imdbSuggestionsURL: "http://sg.media-imdb.com/suggests/##FIRSTQUERYCHAR##/##QUERY##.json"
    searchQueryTemplate: "intitle:[##QUERY##] [mp4 | avi | mkv] -free -doc -pdf site:docs.google.com/file inurl:[preview OR edit]"
    $catalogContainerDOM: $("#catalogContainer")
    $movieTemplateDOM: $("#movieTemplate")
    $searchTemplateDOM: $("#searchTemplate")
    $indexTemplateDOM: $("#indexTemplate")
    $searchFieldDOM: $("#magic_field")
    $playerTemplateDOM: $("#playerTemplate")




# -
# Catalog
#

#
# Catalog Movie Extended Metadata (MODEL)
#

class App.Models.CatalogMovieExtendedMetadata extends Backbone.Model
  urlRoot: App.Config.movieDescriptionURL
  url: ->
    base = @urlRoot || ""
    "#{base.replace(/([^\/])$/, '$1/')}#{encodeURIComponent(this.id)}?callback=?"


#
# Catalog Movie (MODEL)
#

class App.Models.CatalogMovie extends Backbone.Model

  initialize: (options) ->
    console.log 'Models:CatalogMovie::Initing...', this
    @options = options || {}

    _.bindAll this, 'extendedData', 'setModelExtendedMetadataModelClass', 'extendedMetadataChanged'

  extendedData: ->

    extendedMetadata = new @extendedMetadataModelClass
      id: @get 'ImdbCode'

    _.bindAll this, 'extendedMetadataChanged'

    @listenTo extendedMetadata, 'change', @extendedMetadataChanged
    extendedMetadata.fetch()

  setModelExtendedMetadataModelClass: (modelClass)->
    @extendedMetadataModelClass = modelClass
    @extendedData()

  extendedMetadataChanged: (model) ->
    console.log 'ModelsModels:CatalogMovieExtendedMetadata::extendedMetadataChanged', model
    @set 'extendedMetadata', model



#
# Catalog Movie (VIEW)
#

class App.Views.CatalogMovie extends Backbone.View

  initialize: (options) ->
    console.log 'Views:CatalogMovie::Initing...', this
    @options = options || {}

    @searchBarView = options?.searchBarView

    _.bindAll this, 'template', 'renderUpdate', 'render', 'search', 'searchMovie'

    @listenTo @model, 'change', @renderUpdate

  events:
    'click .search': 'searchMovie'

  searchMovie: (ev)->
    console.log 'Views:CatalogMovie::searchMovie', this, arguments
    ev?.preventDefault()
    movieTitle = @model.get 'MovieTitleFiltered'
    @search movieTitle

  search: (query) ->
    @searchBarView.search query

  template: ->

    extendedMetadata = @model.get 'extendedMetadata'
    console.log 'Views.Model.::template em', extendedMetadata

    plot = if extendedMetadata? then extendedMetadata.get 'overview' else "Loading..."

    people = if extendedMetadata? then extendedMetadata.get 'people'

    directorList = "Loading..."
    if people?.directors?
      directorList = ""
      separator = if people.directors.length > 1  then ", " else ""
      _.each people.directors, (director, i) ->
        separator = " " if i == (people.directors.length-1)
        directorList = "#{directorList}#{director.name}#{separator}"

    trailerURL = if extendedMetadata? then extendedMetadata.get 'trailer' else null

    coverUrl = if extendedMetadata? && extendedMetadata.get('images')?.poster? then extendedMetadata.get('images')?.poster else null

    data =
      rating: @model.get 'MovieRating'
      coverSrc: coverUrl
      smallCoverSrc: @model.get 'CoverImage'
      shortPlot: plot
      trailerURL: trailerURL
      director: directorList
      year: @model.get 'MovieYear'
      title: @model.get 'MovieTitleFiltered'<commit_msg>Movie posters now 300px res version.Way more perfomant<commit_after>console.clear = -> #doNothing
console.log = -> #doNothing


# ===
#  jQuery Plugins
# -
$.extend
  urlParams: (url) ->
    match = null
    pl = /\+/g
    search = /([^&=]+)=?([^&]*)/g
    decode = (s) ->
      decodeURIComponent(s.replace(pl, " "))
    query = url
    params = {}
    while match = search.exec(query)
      params[decode(match[1])] = decode(match[2])
    params

# ===
#  Backbone.js App
# -
window.App =
  Models: {}
  Views: {}
  Collections: {}
  Router: {}
  Live: {}
  Config:
    movieSearchURL: "https://www.google.com/uds/GwebSearch?key=notsupplied&v=1.0&safe=off&filter=0&gl=www.google.com&rsz=large&gss=.com&callback=?"
    movieDescriptionURL: "http://api.trakt.tv/movie/summary.json/515a27ba95fbd83f20690e5c22bceaff0dfbde7c"
    movieStreamsURL: "http://whateverorigin.org/get?url=https%3A//docs.google.com/get_video_info%3Fauthuser%3D%26docid%3D##VIDEOID##&callback=?" #TODO &mobile=true when touch detected when modernizr added. 
    catalogURL: "https://yts.re/api/list.json"
    imdbSuggestionsURL: "http://sg.media-imdb.com/suggests/##FIRSTQUERYCHAR##/##QUERY##.json"
    searchQueryTemplate: "intitle:[##QUERY##] [mp4 | avi | mkv] -free -doc -pdf site:docs.google.com/file inurl:[preview OR edit]"
    $catalogContainerDOM: $("#catalogContainer")
    $movieTemplateDOM: $("#movieTemplate")
    $searchTemplateDOM: $("#searchTemplate")
    $indexTemplateDOM: $("#indexTemplate")
    $searchFieldDOM: $("#magic_field")
    $playerTemplateDOM: $("#playerTemplate")




# -
# Catalog
#

#
# Catalog Movie Extended Metadata (MODEL)
#

class App.Models.CatalogMovieExtendedMetadata extends Backbone.Model
  urlRoot: App.Config.movieDescriptionURL
  url: ->
    base = @urlRoot || ""
    "#{base.replace(/([^\/])$/, '$1/')}#{encodeURIComponent(this.id)}?callback=?"
    
  parse: (res) ->
    res.poster300 = res?.poster?.replace(/(\.(\w+))$/i,'-300$1')
    res

#
# Catalog Movie (MODEL)
#

class App.Models.CatalogMovie extends Backbone.Model

  initialize: (options) ->
    console.log 'Models:CatalogMovie::Initing...', this
    @options = options || {}

    _.bindAll this, 'extendedData', 'setModelExtendedMetadataModelClass', 'extendedMetadataChanged'

  extendedData: ->

    extendedMetadata = new @extendedMetadataModelClass
      id: @get 'ImdbCode'

    _.bindAll this, 'extendedMetadataChanged'

    @listenTo extendedMetadata, 'change', @extendedMetadataChanged
    extendedMetadata.fetch()

  setModelExtendedMetadataModelClass: (modelClass)->
    @extendedMetadataModelClass = modelClass
    @extendedData()

  extendedMetadataChanged: (model) ->
    console.log 'ModelsModels:CatalogMovieExtendedMetadata::extendedMetadataChanged', model
    @set 'extendedMetadata', model



#
# Catalog Movie (VIEW)
#

class App.Views.CatalogMovie extends Backbone.View

  initialize: (options) ->
    console.log 'Views:CatalogMovie::Initing...', this
    @options = options || {}

    @searchBarView = options?.searchBarView

    _.bindAll this, 'template', 'renderUpdate', 'render', 'search', 'searchMovie'

    @listenTo @model, 'change', @renderUpdate

  events:
    'click .search': 'searchMovie'

  searchMovie: (ev)->
    console.log 'Views:CatalogMovie::searchMovie', this, arguments
    ev?.preventDefault()
    movieTitle = @model.get 'MovieTitleFiltered'
    @search movieTitle

  search: (query) ->
    @searchBarView.search query

  template: ->

    extendedMetadata = @model.get 'extendedMetadata'
    console.log 'Views.Model.::template em', extendedMetadata

    plot = if extendedMetadata? then extendedMetadata.get 'overview' else "Loading..."

    people = if extendedMetadata? then extendedMetadata.get 'people'

    directorList = "Loading..."
    if people?.directors?
      directorList = ""
      separator = if people.directors.length > 1  then ", " else ""
      _.each people.directors, (director, i) ->
        separator = " " if i == (people.directors.length-1)
        directorList = "#{directorList}#{director.name}#{separator}"

    trailerURL = if extendedMetadata? then extendedMetadata.get 'trailer' else null

    coverUrl = if extendedMetadata? then extendedMetadata.get('poster300') else ""
      
    data =
      rating: @model.get 'MovieRating'
      coverSrc: coverUrl
      smallCoverSrc: @model.get 'CoverImage'
      shortPlot: plot
      trailerURL: trailerURL
      director: directorList
      year: @model.get 'MovieYear'
      title: @model.get 'MovieTitleFiltered'
{'fraction_non_alphanumeric': 0.14899328859060404, 'fraction_numerical': 0.009060402684563758, 'mean_word_length': 3.893814997263273, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 34, 'https://': 4, 'lorem ipsum': 0, 'www.': 4, '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': '7014068', 'n_tokens_mistral': 2965, 'n_tokens_neox': 2777, 'n_words': 547}