Skip to content
This repository has been archived by the owner on Aug 9, 2024. It is now read-only.

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ReenigneArcher committed Aug 5, 2023
1 parent 6b14954 commit 45f3615
Show file tree
Hide file tree
Showing 16 changed files with 170 additions and 37 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ jobs:
path: Plugger.bundle

- name: Install Python 2.7
uses: actions/setup-python@v4
with:
python-version: '2.7'
uses: LizardByte/.github/actions/setup_python2@nightly

- name: Set up Python 2.7 Dependencies
working-directory: Plugger.bundle
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/localize.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
branches: [nightly]
paths: # prevents workflow from running unless these files change
- '.github/workflows/localize.yml'
- 'Contents/Scripts/plugger.po'
- 'Contents/Strings/plugger.po'
- 'Contents/Code/**.py'
- 'Contents/Resources/web/templates/**'
workflow_dispatch:
Expand Down Expand Up @@ -43,7 +43,7 @@ jobs:
git diff Contents/Scripts/plugger.po
# set the variable with minimal output, replacing `\t` with ` `
OUTPUT=$(git diff --numstat locale/retroarcher.po | sed -e "s#\t# #g")
OUTPUT=$(git diff --numstat Contents/Strings/plugger.po | sed -e "s#\t# #g")
echo "git_diff=${OUTPUT}" >> $GITHUB_ENV
- name: git reset
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/python-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ jobs:
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '2.7'
uses: LizardByte/.github/actions/setup_python2@nightly

- name: Install python dependencies
shell: bash
Expand All @@ -33,5 +31,6 @@ jobs:
python -m pip --no-python-version-warning --disable-pip-version-check install -r requirements.txt
- name: Test with pytest
shell: bash # our Python 2.7 setup action doesn't support PowerShell
run: |
python -m pytest -v
16 changes: 13 additions & 3 deletions Contents/Code/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,20 @@
else: # the code is running outside of Plex
from plexhints.core_kit import Core # core kit

bundle_identifier = 'dev.lizardbyte.plugger'
# plex constants
app_support_directory = Core.app_support_path
plex_base_url = 'http://127.0.0.1:32400'
plex_token = os.environ.get('PLEXTOKEN')
plugin_directory = os.path.join(app_support_directory, 'Plug-ins')
plugin_logs_directory = os.path.join(app_support_directory, 'Logs', 'PMS Plugin Logs')
plugin_support_directory = os.path.join(app_support_directory, 'Plug-in Support')
plugin_support_caches_directory = os.path.join(plugin_support_directory, 'Caches')
plugin_support_data_directory = os.path.join(plugin_support_directory, 'Data')
plugin_support_databases_directory = os.path.join(plugin_support_directory, 'Databases')
plugin_support_metadata_combination_directory = os.path.join(plugin_support_directory, 'Metadata Combination')
plugin_support_preferences_directory = os.path.join(plugin_support_directory, 'Preferences')
system_plugins_directory = Core.bundled_plugins_path
plex_base_url = 'http://127.0.0.1:32400'
plex_token = os.environ.get('PLEXTOKEN')

# plugger constants
bundle_identifier = 'dev.lizardbyte.plugger'
plugger_data_directory = os.path.join(plugin_support_data_directory, bundle_identifier)
58 changes: 58 additions & 0 deletions Contents/Code/plugin_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# plex debugging
try:
import plexhints # noqa: F401
except ImportError:
pass
else: # the code is running outside of Plex
from plexhints.log_kit import Log # log kit

# local imports
from const import plugger_data_directory, plugin_directory

# servers version newer than 1.13 cannot view plugin routes, maybe we can do something with this later
# https://www.reddit.com/r/PleX/comments/ig64mz/comment/jhk5jbu/?utm_source=share&utm_medium=web2x&context=3


def initialize_install(plugin_data):
# type: (dict) -> bool
"""
Initialize the plugin installation process.
Parses the plugin data for further processing depending on the conditions.
Parameters
----------
plugin_data : dict
The plugin data to process.
Returns
-------
bool
Whether or not the plugin was successfully installed/migrated/updated.
"""
Log.Debug("{}: {}".format("plugger_support_directory", plugger_data_directory))
Log.Debug("{}: {}".format("plugin_directory", plugin_directory))

Log.Debug('Initializing plugin installation process for "{}"'.format(plugin_data['plugin']['full_name']))
for k, v in plugin_data.items():
Log.Debug("{}: {}".format(k, v))
return True


def uninstall_plugin(plugin_name):
# type: (str) -> bool
"""
Uninstall a plugin.
Parameters
----------
plugin_name : str
The name of the plugin to uninstall.
Returns
-------
bool
Whether or not the plugin was successfully uninstalled.
"""
Log.Debug("Uninstalling plugin: {}".format(plugin_name))
return True
10 changes: 7 additions & 3 deletions Contents/Code/webapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from flask_babel import Babel
import polib
import requests
from werkzeug.utils import secure_filename

# local imports
from const import bundle_identifier, plex_base_url, plex_token, plugin_directory, plugin_logs_directory, \
Expand Down Expand Up @@ -208,11 +209,14 @@ def image(img):
>>> image('favicon.ico')
"""
directory = os.path.join(app.static_folder, 'images')
filename = img
filename = os.path.basename(secure_filename(filename=img)) # sanitize the input

if os.path.isfile(os.path.join(directory, filename)):
file_extension = filename.split('.')[-1]
return send_from_directory(directory=directory, filename=filename, mimetype=mime_type_map[file_extension])
file_extension = filename.rsplit('.', 1)[-1]
if file_extension in mime_type_map:
return send_from_directory(directory=directory, filename=filename, mimetype=mime_type_map[file_extension])
else:
return Response(response='Invalid file type', status=400, mimetype='text/plain')
else:
return Response(response='Image not found', status=404, mimetype='text/plain')

Expand Down
2 changes: 1 addition & 1 deletion Contents/DefaultPrefs.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
"id": "enum_locale",
"type": "enum",
"label": "Locale",
"label": "Web UI Locale",
"default": "en",
"values": [
"de",
Expand Down
53 changes: 37 additions & 16 deletions Contents/Resources/web/templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ <h5 class="modal-title" id="logsModalLabel">{{ _('Logs') }}</h5>

{% block content %}
<div class="container px-auto my-5">
<div class="col-lg-12 mx-auto" id="themerr-container" style="min-width: 335px">
<div class="col-lg-12 mx-auto" id="plugger-container" style="min-width: 335px">

<!-- Search section-->
<section class="py-5 offset-anchor" id="Search">
Expand Down Expand Up @@ -177,7 +177,7 @@ <h2 class="fw-bolder">{{ _('Plugins') }}</h2>
{# Install Modal #}
<script>
// selected element placeholder
let selected_element = null
let selected_version = null

// add and remove border function
function add_remove_border(element) {
Expand All @@ -197,7 +197,7 @@ <h2 class="fw-bolder">{{ _('Plugins') }}</h2>

if (new_element !== null) {
add_remove_border(new_element) // add new border
selected_element = new_element
selected_version = new_element

// get asset options placeholder
let install_options_assets_select = document.getElementById('install_options_assets_select')
Expand Down Expand Up @@ -297,18 +297,39 @@ <h2 class="fw-bolder">{{ _('Plugins') }}</h2>

function install_plugin() {
// get the selected download
let selected_download = parseInt(selected_element.getAttribute('plugger-download-index')) // integer
let download_type = selected_element.getAttribute('plugger-download-type') // release or branch
let auto_update = selected_element.getAttribute('plugger-auto-update') // true or false
let selected_download_index = parseInt(selected_version.getAttribute('plugger-download-index')) // integer
let download_type = selected_version.getAttribute('plugger-download-type') // release or branch
let auto_update = JSON.parse(selected_version.getAttribute('plugger-auto-update')) // true or false
let github_id = version_data.getAttribute('data-github_id') // github id
let download_count = parseInt(selected_element.getAttribute('plugger-download-count')) // integer

alert('installing')
alert(selected_download)
alert(download_type)
alert(auto_update)
alert(github_id)
alert(download_count)
let download_asset_count = parseInt(selected_version.getAttribute('plugger-download-asset-count')) // integer

let selected_asset = document.getElementById('install_options_assets_select').value
let destination_directory = document.getElementById('install_options_destination-directory_input')

if (destination_directory.value === '') {
destination_directory = destination_directory.placeholder
} else {
destination_directory = destination_directory.value
}

$.ajax({
async: true,
url: "/api/plugin/install/",
type: "POST",
dataType: "json",
contentType: "application/json",
data: JSON.stringify({
'download_data': {
'auto_update': auto_update,
'destination_directory': destination_directory,
'download_asset_count': download_asset_count,
'download_type': download_type,
'selected_asset': selected_asset,
'selected_download_index': selected_download_index,
},
'plugin': plugger_plugins[github_id],
})
})
}

let installModal = document.getElementById('installModal')
Expand Down Expand Up @@ -491,7 +512,7 @@ <h2 class="fw-bolder">{{ _('Plugins') }}</h2>
for (let download_asset in download['download_assets']) {
download_assets_length++
}
card.setAttribute('plugger-download-count', download_assets_length.toString())
card.setAttribute('plugger-download-asset-count', download_assets_length.toString())

// set default selection
if (download['type'] === 'release' && default_selection_type === null) {
Expand All @@ -508,7 +529,7 @@ <h2 class="fw-bolder">{{ _('Plugins') }}</h2>
// make card selectable and add event listener
card.classList.add('selectable')
card.addEventListener('click', function () {
change_version(selected_element, card, downloads)
change_version(selected_version, card, downloads)
})
}

Expand Down
22 changes: 22 additions & 0 deletions crowdin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
"base_path": "."
"base_url": "https://api.crowdin.com" # optional (for Crowdin Enterprise only)
"preserve_hierarchy": false # flatten tree on crowdin
"pull_request_labels": [
"crowdin",
"l10n"
]

"files": [
{
"source": "/Contents/Strings/*.po",
"translation": "/Contents/Strings/%two_letters_code%/LC_MESSAGES/%original_file_name%",
"languages_mapping": {
"two_letters_code": {
# map non-two letter codes here, left side is crowdin designation, right side is babel designation
"en-GB": "en_GB",
"en-US": "en_US"
}
}
}
]
4 changes: 2 additions & 2 deletions docs/source/about/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ Minimal setup is required to use Plugger. In addition to the installation, a cou
Preferences
-----------

Locale
^^^^^^
Web UI Locale
^^^^^^^^^^^^^

Description
The localization value to use for translations.
Expand Down
2 changes: 1 addition & 1 deletion docs/source/code_docs/webapp.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
:github_url: https://github.com/LizardByte/Plugger/tree/nightly/Contents/Code/youtube_dl_helper.py
:github_url: https://github.com/LizardByte/Plugger/tree/nightly/Contents/Code/webapp.py

.. include:: ../global.rst

Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@

# images
html_favicon = os.path.join(root_dir, 'Contents', 'Resources', 'web', 'images', 'favicon.ico')
html_logo = os.path.join(root_dir, 'Contents', 'Resources', 'attribution.png')
html_logo = os.path.join(root_dir, 'Contents', 'Resources', 'icon-default.png')

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
Expand Down
20 changes: 20 additions & 0 deletions docs/source/contributing/build.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,26 @@ Build Plist
python ./scripts/build_plist.py
npm dependencies
----------------
Install nodejs and npm. Downloads available `here <https://nodejs.org/en/download/>`_.

Install npm dependencies.
.. code-block:: bash
npm install
Move modules directory.
Linux/macOS
.. code-block:: bash
mv ./node_modules ./Contents/Resources/web
Windows
.. code-block:: batch
move .\node_modules .\Contents\Resources\web
Remote Build
------------
It may be beneficial to build remotely in some cases. This will enable easier building on different operating systems.
Expand Down
2 changes: 1 addition & 1 deletion docs/source/contributing/testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Testing

Flake8
------
Plugger uses `Flake8 <https://pypi.org/project/flake8/>`_ for enforcing consistent code styling. Flake is included
Plugger uses `Flake8 <https://pypi.org/project/flake8/>`_ for enforcing consistent code styling. Flake8 is included
in the ``requirements-dev.txt``.

The config file for flake8 is ``.flake8``. This is already included in the root of the repo and should not be modified.
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ future==0.18.3
polib==1.2.0;python_version<"3"
requests==2.27.1;python_version<"3"
typing==3.10.0.0
werkzeug==1.0.1;python_version<"3"
xmltodict==0.12.0;python_version<"3"

# custom python-plexapi supporting python 2.7
Expand Down
2 changes: 1 addition & 1 deletion scripts/_locale.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
root_dir = os.path.dirname(script_dir)
locale_dir = os.path.join(root_dir, 'Contents', 'Strings')

# retroarcher target locales
# target locales
target_locales = [
'de', # Deutsch
'en', # English
Expand Down

0 comments on commit 45f3615

Please sign in to comment.