<commit_before>local BD = require("ui/bidi")
local ButtonDialog = require("ui/widget/buttondialog")
local ButtonDialogTitle = require("ui/widget/buttondialogtitle")
local Cache = require("cache")
local CacheItem = require("cacheitem")
local ConfirmBox = require("ui/widget/confirmbox")
local DocumentRegistry = require("document/documentregistry")
local InfoMessage = require("ui/widget/infomessage")
local Menu = require("ui/widget/menu")
local MultiInputDialog = require("ui/widget/multiinputdialog")
local InputDialog = require("ui/widget/inputdialog")
local NetworkMgr = require("ui/network/manager")
local OPDSParser = require("opdsparser")
local Screen = require("device").screen
local UIManager = require("ui/uimanager")
local http = require('socket.http')
local lfs = require("libs/libkoreader-lfs")
local logger = require("logger")
local ltn12 = require('ltn12')
local mime = require('mime')
local socket = require('socket')
local url = require('socket.url')
local util = require("util")
local _ = require("gettext")
local T = require("ffi/util").template

local CatalogCacheItem = CacheItem:new{
    size = 1024,  -- fixed size for catalog item
}

-- cache catalog parsed from feed xml
local CatalogCache = Cache:new{
    max_memsize = 20*1024, -- keep only 20 cache items
    current_memsize = 0,
    cache = {},
    cache_order = {},
}

local OPDSBrowser = Menu:extend{
    opds_servers = {},
    calibre_name = _("Local calibre library"),

    catalog_type = "application/atom%+xml",
    search_type = "application/opensearchdescription%+xml",
    acquisition_rel = "^http://opds%-spec%.org/acquisition",
    image_rel = "http://opds-spec.org/image",
    thumbnail_rel = "http://opds-spec.org/image/thumbnail",

    width = Screen:getWidth(),
    height = Screen:getHeight(),
    no_title = false,
    parent = nil,
}

function OPDSBrowser:init()
    local servers = G_reader_settings:readSetting("opds_servers")
    if not servers then -- If there are no saved servers, add some defaults
        servers = {
          {
            title = "Project Gutenberg",
            url = "https://m.gutenberg.org/ebooks.opds/?format=opds",
          },
          {
            title = "Project Gutenberg [Searchable]",
            url = "https://m.gutenberg.org/ebooks/search.mobile/?format=opds&query=%s",
            searchable = true,
          },
          {
             title = "Feedbooks",
             url = "https://catalog.feedbooks.com/catalog/public_domain.atom",
          },
          {
             title = "ManyBooks",
             url = "http://manybooks.net/opds/index.php",
          },
          {
             title = "Internet Archive",
             url = "https://bookserver.archive.org/",
          },
          {
             title = "Flibusta (Russian)",
             url = "http://www.flibusta.is/opds",
          },
          {
             title = "Flibusta [Ru] [Searchable]",
             url = "http://www.flibusta.is/opds/search?searchTerm=%s",
             searchable = true,
          },
          {
             title = "textos.info (Spanish)",
             url = "https://www.textos.info/catalogo.atom",
          },
          {
             title = "Gallica (French)",
             url = "https://gallica.bnf.fr/opds",
          },
          {
             title = "Gallica [Fr] [Searchable]",
             url = "https://gallica.bnf.fr/services/engine/search/opds?operation=searchRetrieve&query=(gallica all \"%s\")",
             searchable = true,
          }
        }
        G_reader_settings:saveSetting("opds_servers", servers)
    elseif servers[4] and servers[4].title == "Internet Archive" and servers[4].url == "http://bookserver.archive.org/catalog/"  then
        servers[4].url = "https://bookserver.archive.org"
    end<commit_msg>Add OPDS server from knihi.com (belarusian) (#7263)<commit_after>local BD = require("ui/bidi")
local ButtonDialog = require("ui/widget/buttondialog")
local ButtonDialogTitle = require("ui/widget/buttondialogtitle")
local Cache = require("cache")
local CacheItem = require("cacheitem")
local ConfirmBox = require("ui/widget/confirmbox")
local DocumentRegistry = require("document/documentregistry")
local InfoMessage = require("ui/widget/infomessage")
local Menu = require("ui/widget/menu")
local MultiInputDialog = require("ui/widget/multiinputdialog")
local InputDialog = require("ui/widget/inputdialog")
local NetworkMgr = require("ui/network/manager")
local OPDSParser = require("opdsparser")
local Screen = require("device").screen
local UIManager = require("ui/uimanager")
local http = require('socket.http')
local lfs = require("libs/libkoreader-lfs")
local logger = require("logger")
local ltn12 = require('ltn12')
local mime = require('mime')
local socket = require('socket')
local url = require('socket.url')
local util = require("util")
local _ = require("gettext")
local T = require("ffi/util").template

local CatalogCacheItem = CacheItem:new{
    size = 1024,  -- fixed size for catalog item
}

-- cache catalog parsed from feed xml
local CatalogCache = Cache:new{
    max_memsize = 20*1024, -- keep only 20 cache items
    current_memsize = 0,
    cache = {},
    cache_order = {},
}

local OPDSBrowser = Menu:extend{
    opds_servers = {},
    calibre_name = _("Local calibre library"),

    catalog_type = "application/atom%+xml",
    search_type = "application/opensearchdescription%+xml",
    acquisition_rel = "^http://opds%-spec%.org/acquisition",
    image_rel = "http://opds-spec.org/image",
    thumbnail_rel = "http://opds-spec.org/image/thumbnail",

    width = Screen:getWidth(),
    height = Screen:getHeight(),
    no_title = false,
    parent = nil,
}

function OPDSBrowser:init()
    local servers = G_reader_settings:readSetting("opds_servers")
    if not servers then -- If there are no saved servers, add some defaults
        servers = {
          {
            title = "Project Gutenberg",
            url = "https://m.gutenberg.org/ebooks.opds/?format=opds",
          },
          {
            title = "Project Gutenberg [Searchable]",
            url = "https://m.gutenberg.org/ebooks/search.mobile/?format=opds&query=%s",
            searchable = true,
          },
          {
             title = "Feedbooks",
             url = "https://catalog.feedbooks.com/catalog/public_domain.atom",
          },
          {
             title = "ManyBooks",
             url = "http://manybooks.net/opds/index.php",
          },
          {
             title = "Internet Archive",
             url = "https://bookserver.archive.org/",
          },
          {
             title = "Flibusta (Russian)",
             url = "http://www.flibusta.is/opds",
          },
          {
             title = "Flibusta [Ru] [Searchable]",
             url = "http://www.flibusta.is/opds/search?searchTerm=%s",
             searchable = true,
          },
          {
             title = "textos.info (Spanish)",
             url = "https://www.textos.info/catalogo.atom",
          },
          {
             title = "Gallica (French)",
             url = "https://gallica.bnf.fr/opds",
          },
          {
             title = "Gallica [Fr] [Searchable]",
             url = "https://gallica.bnf.fr/services/engine/search/opds?operation=searchRetrieve&query=(gallica all \"%s\")",
             searchable = true,
          },
          {
             title = "Беларуская палічка",
             url = "https://knihi.com/opds.xml",
          }
        }
        G_reader_settings:saveSetting("opds_servers", servers)
    elseif servers[4] and servers[4].title == "Internet Archive" and servers[4].url == "http://bookserver.archive.org/catalog/"  then
        servers[4].url = "https://bookserver.archive.org"
    end
{'fraction_non_alphanumeric': 0.14259857789269553, 'fraction_numerical': 0.0059469941822883, 'mean_word_length': 2.4972875226039783, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 17, 'lorem ipsum': 0, 'www.': 6, 'xml': 7}, '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': '233724', 'n_tokens_mistral': 2357, 'n_tokens_neox': 2299, 'n_words': 456}