Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[plugin.video.archive.org] v1.0.0 #4525

Merged
merged 1 commit into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions plugin.video.archive.org/addon.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="plugin.video.archive.org" name="Internet Archive" version="1.0.0" provider-name="gujal">
<requires>
<import addon="xbmc.python" version="3.0.0"/>
</requires>
<extension point="xbmc.python.pluginsource" library="default.py">
<provides>audio video</provides>
</extension>
<extension point="xbmc.addon.metadata">
<summary lang="en_GB">Internet Archive add-on</summary>
<description lang="en_GB">Watch and listen to media archived by Internet Archive</description>
<disclaimer lang="en_GB">This third party addon is not in any way commissioned or endorsed by Internet Archive</disclaimer>
<language></language>
<platform>all</platform>
<license>GPL-2.0</license>
<forum>https://forum.kodi.tv/showthread.php?tid=180623</forum>
<website>https://archive.org/</website>
<email>gujal at protonmail dot com</email>
<assets>
<icon>icon.png</icon>
<fanart>fanart.jpg</fanart>
<screenshot>resources/images/screenshot-01.jpg</screenshot>
<screenshot>resources/images/screenshot-02.jpg</screenshot>
<screenshot>resources/images/screenshot-03.jpg</screenshot>
</assets>
</extension>
</addon>
4 changes: 4 additions & 0 deletions plugin.video.archive.org/changelog.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
plugin.video.archive.org:
---------------------------
v1.0.0 (20240608)
First Release
22 changes: 22 additions & 0 deletions plugin.video.archive.org/default.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""
Internet Archive Kodi Addon
Copyright (C) 2024 gujal

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 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 General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""

from resources.lib import main

if __name__ == '__main__':
main.Main()
Binary file added plugin.video.archive.org/fanart.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added plugin.video.archive.org/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# XBMC Media Center language file
# Addon Name: Internet Archive
# Addon id: plugin.video.archive.org

msgid ""
msgstr ""
"Project-Id-Version: XBMC-Addons\n"
"Report-Msgid-Bugs-To: [email protected]\n"
"POT-Creation-Date: 2016-11-03 00:21+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: en_GB\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"

msgctxt "Addon Summary"
msgid "Internet Archive add-on"
msgstr ""

msgctxt "Addon Description"
msgid "Watch and listen to media archived by Internet Archive"
msgstr ""

msgctxt "Addon Disclaimer"
msgid "This third party addon is not in any way commissioned or endorsed by Internet Archive"
msgstr ""


msgctxt "#30000"
msgid "Internet Archive"
msgstr ""

msgctxt "#30001"
msgid "Cache Timeout in hours"
msgstr ""

msgctxt "#30002"
msgid "Clear Cache"
msgstr ""

msgctxt "#30003"
msgid "Enable Debug Mode"
msgstr ""

# empty strings from id 30004 to 30100

msgctxt "#30101"
msgid "Popular Collections"
msgstr ""

msgctxt "#30102"
msgid "Search by Title"
msgstr ""

# empty strings from id 30104 to 30200

msgctxt "#30201"
msgid "Cached Data has been cleared"
msgstr ""

msgctxt "#30202"
msgid "Need atleast 3 characters"
msgstr ""

msgctxt "#30203"
msgid "Choose Source"
msgstr ""

msgctxt "#30204"
msgid "Next Page"
msgstr ""
Empty file.
157 changes: 157 additions & 0 deletions plugin.video.archive.org/resources/lib/cache.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
# -*- coding: utf-8 -*-
"""
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU 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 General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""

import hashlib
import json
import pickle
import re
import time
import zlib
import xbmcvfs
import xbmcaddon
from sqlite3 import dbapi2 as db, OperationalError, Binary

cacheFile = xbmcvfs.translatePath(xbmcaddon.Addon().getAddonInfo('profile') + '/cache.db')
cache_table = 'cache'


def get(function, duration, *args, **kwargs):
# type: (function, int, object) -> object or None
"""
Gets cached value for provided function with optional arguments, or executes and stores the result
:param function: Function to be executed
:param duration: Duration of validity of cache in hours
:param args: Optional arguments for the provided function
:param kwargs: Optional keyword arguments for the provided function
"""

key = _hash_function(function, *args, **kwargs)
cache_result = cache_get(key)

if cache_result:
if _is_cache_valid(cache_result['date'], duration):
return pickle.loads(zlib.decompress(cache_result['value']))

fresh_result = function(*args, **kwargs)

if not fresh_result:
# If the cache is old, but we didn't get fresh result, return the
# old cache
if cache_result:
return pickle.loads(zlib.decompress(cache_result['value']))
return None

cache_insert(key, Binary(zlib.compress(pickle.dumps(fresh_result))))
return fresh_result


def remove(function, *args, **kwargs):
key = _hash_function(function, *args, **kwargs)
cursor = _get_connection_cursor()
cursor.execute("DELETE FROM %s WHERE key = ?" % cache_table, [key])
cursor.connection.commit()


def timeout(function, *args, **kwargs):
key = _hash_function(function, *args, **kwargs)
result = cache_get(key)
return int(result['date'])


def cache_get(key):
# type: (str, str) -> dict or None
try:
cursor = _get_connection_cursor()
cursor.execute("SELECT * FROM %s WHERE key = ?" % cache_table, [key])
return cursor.fetchone()
except OperationalError:
return None


def cache_insert(key, value):
# type: (str, str) -> None
cursor = _get_connection_cursor()
now = int(time.time())
cursor.execute(
"CREATE TABLE IF NOT EXISTS %s (key TEXT, value BINARY, date INTEGER, UNIQUE(key))" %
cache_table)
cursor.execute(
"CREATE UNIQUE INDEX if not exists index_key ON %s (key)" % cache_table)
update_result = cursor.execute(
"UPDATE %s SET value=?,date=? WHERE key=?"
% cache_table, (value, now, key))

if update_result.rowcount == 0:
cursor.execute(
"INSERT INTO %s Values (?, ?, ?)"
% cache_table, (key, value, now)
)

cursor.connection.commit()


def cache_clear():
cursor = _get_connection_cursor()

for t in [cache_table, 'rel_list', 'rel_lib']:
try:
cursor.execute("DROP TABLE IF EXISTS %s" % t)
cursor.execute("VACUUM")
cursor.commit()
except BaseException:
pass


def _get_connection_cursor():
conn = _get_connection()
return conn.cursor()


def _get_connection():
conn = db.connect(cacheFile)
conn.row_factory = _dict_factory
return conn


def _dict_factory(cursor, row):
d = {}
for idx, col in enumerate(cursor.description):
d[col[0]] = row[idx]
return d


def _hash_function(function_instance, *args, **kwargs):
return _get_function_name(function_instance) + _generate_md5(*args, **kwargs)


def _get_function_name(function_instance):
return re.sub(
r'.+\smethod\s|.+function\s|\sat\s.+|\sof\s.+',
'',
repr(function_instance))


def _generate_md5(*args, **kwargs):
md5_hash = hashlib.md5()
[md5_hash.update(str(arg).encode()) for arg in args]
md5_hash.update(json.dumps(kwargs).encode())
return md5_hash.hexdigest()


def _is_cache_valid(cached_time, cache_timeout):
now = int(time.time())
diff = now - cached_time
return (cache_timeout * 3600) > diff
Loading
Loading