a4k-openproject / script.module.openscrapers

OpenScrapers Project
GNU General Public License v3.0
102 stars 40 forks source link

Adjust file "default.py" and "addon.xml #138

Closed kasi45 closed 4 years ago

kasi45 commented 4 years ago

Please excuse my poor English.

Hello,

is there a special reason why in the 'addon.xml' the line <extension point="xbmc.python.pluginsource" library="lib/default.py"> is not <extension point="xbmc.python.script" library="lib/default.py"> like other script modules?

I changed this for me and also changed the 'default.py' a little bit. The advantage is that after changing the settings, the settings are always saved when you click on the "OK" button.

As an example my "default.py":

default.py.txt

kasi45 commented 4 years ago
# -*- coding: utf-8 -*-

import sys
import urlparse

import xbmcgui
dialog = xbmcgui.Dialog()
from openscrapers import sources_openscrapers
from openscrapers.modules import control

params =  None
action  = None
mode = None
query = None

try:
    params = dict(urlparse.parse_qsl(sys.argv[1].replace('?', '')))
    action = params.get('action')
    mode = params.get('mode')
    query = params.get('query')
except:
    yes = dialog.yesno('OpenScrapersDE', ' ', 'Die Einstellungen von OpenScrapersDE öffnen?', '', '', '')
    if not yes: exit()
    action = "OpenscrapersSettings"

def ScraperChoice():
    from openscrapers import providerSources
    sourceList = sorted(providerSources())
    control.idle()
    select = control.selectDialog([i for i in sourceList])
    if select == -1: return
    module_choice = sourceList[select]
    control.setSetting('module.provider', module_choice)
    control.openSettings('0.1')

if action == "OpenscrapersSettings":
    control.openSettings('0.3', 'script.module.openscrapers')

elif mode == "OpenscrapersSettings":
    control.openSettings('0.0', 'script.module.openscrapers')

elif action == "ScraperChoice":
    ScraperChoice()

elif action == "Defaults":
    dialog.notification('OpenScrapersDE', 'Die Einstellungen werden übernommen', xbmcgui.NOTIFICATION_INFO, 500, sound=False)
    sourceList = []
    sourceList = sources_openscrapers.all_providers
    for i in sourceList:
        source_setting = 'provider.' + i
        value = control.getSettingDefault(source_setting)
        control.setSetting(source_setting, value)
        # xbmc.log('provider-default = %s-%s' % (source_setting, value), 2)
    #control.openSettings(query, "script.module.openscrapers")

elif action == "toggleAll":
    dialog.notification('OpenScrapersDE', 'Die Einstellungen werden übernommen', xbmcgui.NOTIFICATION_INFO, 500, sound=False)
    sourceList = []
    sourceList = sources_openscrapers.all_providers
    for i in sourceList:
        source_setting = 'provider.' + i
        control.setSetting(source_setting, params['setting'])
    #    xbmc.log('All providers = %s' % sourceList,2)
    #control.openSettings(query, "script.module.openscrapers")

...
<\snip>

Of course you should still replace the text 'Die Einstellungen von OpenScrapersDE öffnen?' and 'Die Einstellungen werden übernommen' with a language variable

bjbca commented 4 years ago

he has a point when it comes to settings not being saved when "Ok" button selected, changes are not saved by Ok when openscrapers settings are selected through os cm, the only way they save in is is by escape or back, but if openscrapers settings are selected through an addon for instance venom and then changes made and ok selected then the settings are saved.

kasi45 commented 4 years ago

The changes I suggest fix the problem "Save with OK". I also had to think a bit longer about how to solve the problem.

kasi45 commented 4 years ago

not only change the file "default.py". also the line in the file "addon.xml".

kasi45 commented 4 years ago

Please excuse me. I forgot to point out that the ' settings.xml' has to be adjusted as well.

The following example shows the necessary change!

change from

<setting label="OpenScrapers Default Providers" type="action" option="close"
                 action="RunPlugin(plugin://script.module.openscrapers/?action=Defaults&amp;setting=true&amp;query=0.1)"/>

to

<setting label="OpenScrapers Default Providers" type="action" option=""
                 action="RunScript(script.module.openscrapers, action=Defaults&amp;setting=true&amp;query=0.1)"/>
kasi45 commented 4 years ago

https://youtu.be/nSgcfXnuThk

123Venom commented 4 years ago

was just about to comment on how changing that extension point will break all calls with RunPlugin and another thing you forgot is all addons out there are already using that so they'd all have to be adjusted. This gets pushed and devs be screaming , 'wtf broke the settings call`..oh sorry we did that. As far as the settings being saved...cured with a 200ms sleep state before settings opens again.

kasi45 commented 4 years ago

I am not sure if I have understood them correctly now (translation). The calls for the openscraper settings in the video addons do not need to be changed.

These are the corresponding lines of code from the "Venom Addon"

elif action == 'openscrapersSettings':
    control.openSettings('0.0', 'script.module.openscrapers')
123Venom commented 4 years ago

right but not what I'm talking about....how is that action called from another addon?

RunPlugin(plugin://script.module.openscrapers

So changing the extension point will break that and all addons using OpenScrapers will have to be updated.

kasi45 commented 4 years ago

They'd be right!

But I did not find this call anywhere in the video addons. Okay, I didn't look at 'Seren'. ;-)

123Venom commented 4 years ago

@kasi45 Also try adding

control.sleep(200)

before each instance where settings open again after changes. This fixed the random issue of settings not appearing to be saved for me...plus the whole import sys missing that breaks the params..how the hell that happened I have no idea but good catch on that one.

kasi45 commented 4 years ago

I wasn't online for a moment. but..:

Before I get lost with errors in the 'PR', I have a few files here to test.

Maybe you will like them too. Just tested them in Venom.

addon.xml.txt default.py.txt settings.xml.txt

123Venom commented 4 years ago

again you are changing the extension point to .script and for the sake of breaking other addons out there we are simply not going to do this.

123Venom commented 4 years ago

They'd be right!

But I did not find this call anywhere in the video addons. Okay, I didn't look at 'Seren'. ;-)

Seren doesn't use OpenScrapers and no they'd not be right using RunPlugin still

kasi45 commented 4 years ago

these files were only meant for you - so you can test the alternative. Also for testing with other video addons. Because I don't know the addons that might still use openscraper

with 'RunPlugin(plugin://script.module.openscrapers' I have to rewrite and test it myself

123Venom commented 4 years ago

simple...dial in your extension point change to openscrapers...restart kodi. Go to Venom Settings - Providers - OpenScrapers...never loads! Because it uses RunPlugin like other exo forks. We are not changing this and with that said I'm finished on this subject.

kasi45 commented 4 years ago
control.sleep(200)
control.openSettings(query, "script.module.openscrapers")

Oh, now I get what you meant by "200 ms." I'm very sorry that I understand English so poorly.

Then we could close up here.

Thanks for your time. Greetings!