<commit_before>-- libquvi-scripts
-- Copyright (C) 2013  <NAME> <<EMAIL>>
-- Copyright (C) 2012  <NAME> <<EMAIL>>
--
-- This file is part of libquvi-scripts <http://quvi.sourceforge.net/>.
--
-- This program is free software: you can redistribute it and/or
-- modify it under the terms of the GNU Affero General Public
-- License as published by the Free Software Foundation, either
-- version 3 of the License, or (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-- GNU Affero General Public License for more details.
--
-- You should have received a copy of the GNU Affero General
-- Public License along with this program.  If not, see
-- <http://www.gnu.org/licenses/>.
--

-- Identify the script.
function ident(self)
    package.path = self.script_dir .. '/?.lua'
    local C      = require 'quvi/const'
    local r      = {}
    r.domain     = "city%.lego%.com"
    r.formats    = "default"
    r.categories = C.proto_http
    local U      = require 'quvi/util'
    r.handles    = U.handles(self.page_url, {r.domain}, {"/.+/movies/.+$"})
      -- http://city.lego.com/en-gb/movies/mini-movies/gold-run/
    return r
end

-- Query available formats.
function query_formats(self)
    self.formats  = "default"
    return self
end

-- Parse video URL.
function parse(self)
    self.host_id = "lego"

    local p = quvi.fetch(self.page_url)

    local d = p:match('FirstVideoData = {(.-)};')
                or error('no match: FirstVideoData')

    self.title = d:match('"Name":"(.-)"')
                  or error('no match: media title')

    self.id = d:match('"LikeObjectGuid":"(.-)"') -- Lack of a better.
                  or error('no match: media ID')

    self.url = {d:match('"VideoFlash":%{"Url":"(.-)"')
                  or error('no match: media stream URL')}

    -- TODO: return self.thumbnail_url

    return self
end<commit_msg>media/lego.lua: Rewrite ident function<commit_after>-- libquvi-scripts
-- Copyright (C) 2013  <NAME> <<EMAIL>>
-- Copyright (C) 2012  <NAME> <<EMAIL>>
--
-- This file is part of libquvi-scripts <http://quvi.sourceforge.net/>.
--
-- This program is free software: you can redistribute it and/or
-- modify it under the terms of the GNU Affero General Public
-- License as published by the Free Software Foundation, either
-- version 3 of the License, or (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-- GNU Affero General Public License for more details.
--
-- You should have received a copy of the GNU Affero General
-- Public License along with this program.  If not, see
-- <http://www.gnu.org/licenses/>.
--

local Lego = {} -- Utility functions unique to this script

-- Identify the media script.
function ident(qargs)
  return {
    can_parse_url = Lego.can_parse_url(qargs),
    domains = table.concat({'city.lego.com'}, ',')
  }
end

-- Query available formats.
function query_formats(self)
    self.formats  = "default"
    return self
end

-- Parse video URL.
function parse(self)
    self.host_id = "lego"

    local p = quvi.fetch(self.page_url)

    local d = p:match('FirstVideoData = {(.-)};')
                or error('no match: FirstVideoData')

    self.title = d:match('"Name":"(.-)"')
                  or error('no match: media title')

    self.id = d:match('"LikeObjectGuid":"(.-)"') -- Lack of a better.
                  or error('no match: media ID')

    self.url = {d:match('"VideoFlash":%{"Url":"(.-)"')
                  or error('no match: media stream URL')}

    -- TODO: return self.thumbnail_url

    return self
end

--
-- Utility functions.
--

function Lego.can_parse_url(qargs)
  local U = require 'socket.url'
  local t = U.parse(qargs.input_url)
  if t and t.scheme and t.scheme:lower():match('^http$')
       and t.host   and t.host:lower():match('^city%.lego%.com$')
       and t.path   and t.path:lower():match('/%w+%-%w+/movies/')
  then
    return true
  else
    return false
  end
end
{'fraction_non_alphanumeric': 0.1415492957746479, 'fraction_numerical': 0.004225352112676056, 'mean_word_length': 2.689177489177489, 'pattern_counts': {'":': 8, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5246384', 'n_tokens_mistral': 1362, 'n_tokens_neox': 1301, 'n_words': 447}