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

an add-on for automatically filter before download #701

Closed
alexis26 opened this issue Nov 9, 2019 · 32 comments
Closed

an add-on for automatically filter before download #701

alexis26 opened this issue Nov 9, 2019 · 32 comments
Labels
fixed-in-master Will appear in next release

Comments

@alexis26
Copy link
Contributor

alexis26 commented Nov 9, 2019

hi,
some channel have a big content and mix their topics...
...it would be nice to have an add-on (an option) for automatically filter before downloading
like "only donwload if there is [example] in the title"

What do you think about ?
ty

@elelay
Copy link
Member

elelay commented Nov 11, 2019

Yes, you can create such an add-on.
See https://gpodder.github.io/docs/extensions.html for explanations on how to write it.

You'll want to add the on_podcast_updated hook to the hello_world.py gPodderExtension class:

    def on_podcast_updated(self, podcast):
        ''' Called when a podcast is refreshed, but before showing the download dialog '''
        keyword = None
        # define your keyword per podcast
        if podcast.url == 'http://radiofrance-podcast.net/podcast09/rss_11370.xml':
            keyword = 'scandinave'
        # then if there is a filter, mark all non-matching episodes old
        if keyword:
            for e in podcast.get_episodes(gpodder.STATE_NORMAL):
                if e.is_new:
                    if keyword not in e.title:
                        e.mark_old()

@auouymous
Copy link
Member

@elelay, Do you know of any extensions that modify the podcast settings dialog, or do you know how I could add a tab to that dialog? A filtering extension would be more useful if the user could edit filters in each podcast's settings dialog instead of hardcoding them in the extension's python file.

@auouymous
Copy link
Member

The code says on_ui_object_available shouldn't be used but with the following patch, I was able to add a tab to the podcast's settings dialog. What I can't figure out though, is how to save changes to self.container.config.<extension>.* made by the extension. The changes show up in the edit config dialog but are lost when gpodder restarts.

diff --git a/src/gpodder/gtkui/desktop/channel.py b/src/gpodder/gtkui/desktop/channel.py
index bcdd8717..406184bd 100644
--- a/src/gpodder/gtkui/desktop/channel.py
+++ b/src/gpodder/gtkui/desktop/channel.py
@@ -94,6 +94,8 @@ class gPodderChannel(BuilderWidget):
         self.imgCoverEventBox.connect('button-press-event',
                 self.on_cover_popup_menu)
 
+        gpodder.user_extensions.on_ui_object_available('channel-gtk', self)
+
     def on_button_add_section_clicked(self, widget):
         text = self.show_text_edit_dialog(_('Add section'), _('New section:'),
             affirmative_text=Gtk.STOCK_ADD)

@elelay
Copy link
Member

elelay commented Nov 12, 2019

Interesting: the on_ui_object_available is only used to give the main window to extensions. But why not pass other parts, indeed!

Changes to the settings should be persistent : it's used in many extensions. Does it work if you do it in the edit config dialog, not in your podcast settings tab?

@auouymous
Copy link
Member

Double-clicking on the setting and then hitting enter to exit the edit does cause it to be saved. I looked through the edit config and preferences and couldn't find any save ability.

@auouymous
Copy link
Member

It does save the settings modified by the extension, but it is buggy. I have a setting that defaults to an empty array with []. It doesn't save when appending one dictionary to the array and quiting. Appending two or more dictionaries will save both correctly. Removing one of the dictionaries so it only has one will cause it to not save and on next startup, it has both dictionaries again.

@auouymous
Copy link
Member

There were no bugs, it was just randomly saving, not sure how though. Calling self.container.manager.core.config.schedule_save() when the extension makes changes seems to work. It auto-saves after 60 seconds or at shutdown if sooner. I'll post the extension tomorrow after I clean it up.

@alexis26
Copy link
Contributor Author

Thank you for your interest and enthusiasm, I follow with interest ...
(unfortunately I do not have the ability to do more...)
on the other hand, auouymous a, I can be your beta tester if you want ...

[I am under seven and I can install gpodder specially for that, because I use it normally in portable version]

@elelay
Copy link
Member

elelay commented Nov 13, 2019

yes, the config module is tricky: it can only observe changes when you set an attribute of an object.
Adding an item to the dict won't be noticed. But re-setting the resulting dict should do the trick (untested)

self.container.config.patterns.update({ 'key': 'value'})
self.container.config.patterns = self.container.config.patterns

@auouymous
Copy link
Member

http://borg.qzx.com/files/gpodder-filter-extension.zip

Unzip that file to ~/gPodder/Extensions/ and restart gpodder. Then open settings for a podcast and go to the new "Filter" tab. It has some help text on the dialog.

ISSUES:

@elelay, Setting the key to itself doesn't trigger _on_key_changed().

@alexis26
Copy link
Contributor Author

i try (with a new/clean) 3.10.11 on seven : i have the extension in the list and active-it
(i active "search for new episode on startup" too for testing)

but after the re-start i haven't new "Filter" tab in the right clic podcast setting windows...
(only have the 'normal' general and advanced tab)

if this is because of your 702 issues, i don't know how to apply...

@auouymous
Copy link
Member

#701 (comment)

That link is the most important patch, #702 is only needed if you will delete a podcast that has been filtered.

You need to find where gpodder is installed, edit gtkui/desktop/channel.py, go to line 96 and insert the following line (including the 8 spaces at start of line):

        gpodder.user_extensions.on_ui_object_available('channel-gtk', self)

@alexis26
Copy link
Contributor Author

ok, ty (sorry for my level!...)

It seem to work for me :-)
i have make some little test :
-the RE option work with uppercase and accented characters
-work with a part of a name ('star' offers podcast with 'stars' too)
-little pb with uppercase (without RE option) 'star' don't offers 'Star' podcast
-pb if you modify the filter : no longer offers any download if you modify the filter with another word (but I haven't done the 702 modification, is it linked ???); even if after a modification I make an other to go back to the first filter i have put
[example : if you put 'star' and modify to 'stars' : no pb ; if you go back to 'star' : no pb too
but if you modify by 'planet' no more downloads are offered, even if you come back to 'star' ( no download as much for 'star' as for 'planet')]

@auouymous
Copy link
Member

I didn't think about case-sensitivity. Not sure if I should add a checkbox or just always ignore case for normal and RE filters.

-pb if you modify the filter : no longer offers any download if you modify the filter with another word (but I haven't done the 702 modification, is it linked ???); even if after a modification I make an other to go back to the first filter i have put
[example : if you put 'star' and modify to 'stars' : no pb ; if you go back to 'star' : no pb too
but if you modify by 'planet' no more downloads are offered, even if you come back to 'star' ( no download as much for 'star' as for 'planet')]

I'm not sure what you are saying here, but #702 isn't related.

@alexis26
Copy link
Contributor Author

I meant that I think there is a problem if/when we change the word/filter: no more downloads are offered (neither for the old nor for the new filter)

@auouymous
Copy link
Member

http://borg.qzx.com/test-rss.php

For that fake test feed, if you set filter for 'aaa' and update, it will mark all episodes with 'aaa' as old. After changing filter to 'bbb' and updating, it will mark all episodes with 'bbb' as old. But it never marks episodes as new when no longer blocked. Is this the problem you are describing?

If so, I'm not sure it should be changed. The user may have manually marked an allowed episode as old and having the extension mark it back to new would be unwanted behavior. I added a button on the filter tab to manually force a re-filtering of all episodes. A new download is available at http://borg.qzx.com/files/gpodder-filter-extension.zip.

But the following patch is required to refresh the episode list. Without the patch, you must click another podcast and then click back to refresh. Edit gtkui/main.py around line 3118 and insert the line starting with a +, but remove the +.

@elelay, It would probably be better if the gPodder instance was passed to gPodderChannel instead of passing a bunch of its methods.

diff --git a/src/gpodder/gtkui/main.py b/src/gpodder/gtkui/main.py
index 2a401a51..20a91a87 100644
--- a/src/gpodder/gtkui/main.py
+++ b/src/gpodder/gtkui/main.py
@@ -3115,6 +3115,7 @@ class gPodder(BuilderWidget, dbus.service.Object):
         gPodderChannel(self.main_window,
                 channel=self.active_channel,
                 update_podcast_list_model=self.update_podcast_list_model,
+                update_episode_list_model=self.update_episode_list_model,
                 cover_downloader=self.cover_downloader,
                 sections=set(c.section for c in self.channels),
                 clear_cover_cache=self.podcast_list_model.clear_cover_cache,

@alexis26
Copy link
Contributor Author

Thank you for describing how the extension works ; that's what I was describing.
And you're right about not wanting to change it for real use of ext (it's testing that made me do something that I would not normally do with the filtering...)

the idea of a re-filtering button seems excellent (either for a modification of the filter, or in case of typing error during the first filtering ...)

I will test it tonight or we (because i have a pb of electricity and snow here!)

Thanks again for all this work

@alexis26
Copy link
Contributor Author

it seems to work fine :-)
the new button "Filter episode now" correctly reset filter after a modify and re-propose 'old downloads' (all downloads if you leave blank or only those you filtering with a new word) :-)))

nice job and great thank you

@alexis26
Copy link
Contributor Author

i try to translate for myself for now

so i add

# -*- coding: utf-8 -*-

in line 2 for accented characters in your filter.py

@auouymous
Copy link
Member

I added that utf-8 line to the extension. I also figured out that the gPodder instance could be grabbed from on_ui_object_available('gpodder-gtk') so the second patch here for update_episode_list_mode is not needed.

@alexis26 There is no reason to download newest version if you've modified your copy.

@alexis26
Copy link
Contributor Author

Hi,
I just saw that it is not in the new version (3.10.12) ...
Is it a choice, a forgetting or the procedure is longer?

Since I tested the version of auouymous it works very well and I use it a lot ; it's super practical!

@elelay
Copy link
Member

elelay commented Jan 26, 2020

This is mainly me forgetting about it.

Still, it's not super trivial to integrate: I'm not sure on_ui_object_available('channel-gtk') is the way to go. Also the code should be polished a bit and the ui refined and made localizable.

Wouldn't it be better to add an extension point like on_channel_settings(gpodder, channel) where the extension returns a panel to be added to the channel settings? And on_preferences(gpodder) to provide preference tabs? Maybe do both: on_ui_object_available as an unstable way to do wild things and on_channel_settings and on_preferences to return dialog tabs in a more controlled way?

@auouymous maybe we can refine this in a PR?

@auouymous
Copy link
Member

http://borg.qzx.com/files/gpodder-filter-v2-extension.zip

Requires https://github.com/gpodder/gpodder/commit/117e72107411388fa2322a34002f57102c6248aa.patch applied to gpodder or use https://ci.appveyor.com/project/elelay/gpodder/builds/30507515/artifacts if on windows.

Now uses the on_channel_settings callback and supports case-insensitive filtering. Also cleaned up the UI and localized all strings (assuming that is how it is done).

@alexis26
Copy link
Contributor Author

alexis26 commented Feb 2, 2020

Hi for me it works well ...
(with both: your updated version and mine modified)

just a small thing (for the user friendly side): I fully understand the logic of having to check 'block' before checking 'allow' which will block everything except what you allow ...
but could you not just allow ticking 'allow' and this choice automatically ticks 'block'?
(for me it poses no problem, but I think it would be more intuitive for users ...)

Otherwise, I wanted at least to help translate into my language (not be only requester!...) But I saw nothing in the 'po'

@auouymous
Copy link
Member

What modifications have you made?

Having allow automatically tick block might be less intuitive. By checking block first you know that episodes are being blocked and you can unblock some by checking allow. It might be confusing to enable both choices up front and then block is forced on and shaded when you enable allow. The action is also not symmetrical, when you uncheck allow, block would remain checked. Having it so unchecking allow also unchecks block would cause data loss for anyone who had added a block pattern.

The extension is not part of gpodder (yet) so there is no reason the strings would exist in po files. If it gets added, the strings would become available and you could translate them at that time.

@alexis26
Copy link
Contributor Author

alexis26 commented Feb 6, 2020

"modification" : I just talking about a fresh 3.10.11 portable that i used specially for this thread and modifications you mentioned since the begining...

about the 'blocked' 'allow' field : me, I have no pb with ... I was just wondering if it will be intuitive for users to have to uncheck another field to be able to write in the one they want ...

for po files, sorry, my mistake...translation problem for "localized all strings"!

@auouymous
Copy link
Member

Are you not able to write in both allow and block patterns when allow is checked? The block checkbox grays out when allow is checked to prevent the user from unchecking it, but the block pattern can still be used.

@alexis26
Copy link
Contributor Author

alexis26 commented Feb 7, 2020

"The block checkbox grays out when allow is checked to prevent the user from unchecking it, but the block pattern can still be used." that seems normal and justified

"Are you not able to write in both allow and block patterns when allow is checked?"
yes I can. But to be able to check 'allow' it is necessary, checked block beforehand.
that's just that, that doesn't seem very intuitive to me, but I'll let you judge if you think it's better this way ...

@auouymous
Copy link
Member

I think clicking block before clicking allow better indicates something is being blocked and allow is unblocking it.

@elelay
Copy link
Member

elelay commented Feb 16, 2020

What would you think about switching Block and Allow lines and renaming Allow to Except?
To my mind it would match the workflow better.

@elelay
Copy link
Member

elelay commented Feb 23, 2020

Merged to master.
Documentation to be added to manual

@elelay elelay added the fixed-in-master Will appear in next release label Feb 23, 2020
@elelay
Copy link
Member

elelay commented Apr 16, 2020

gPodder 3.10.15 bundles the extension

@elelay elelay closed this as completed Apr 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed-in-master Will appear in next release
Projects
None yet
Development

No branches or pull requests

3 participants