ResolveURL icon indicating copy to clipboard operation
ResolveURL copied to clipboard

enhancement: possibility to add domains themselves in settings

Open teletcl opened this issue 1 year ago • 2 comments

Could it be possible to make it possible for a user to add domains themselves, In settings? This would involve adding to variable "domains" and "pattern" in the class of plugin.

I was thinking more of a temporary entry until the next update comes out.

Based on the "mixdrop" plugin, I created proposal code. The "domains" variable is easier to modify, but the "pattern" variable can also be modified. I was wondering whether to divide it into "user_pattern". If something repeats in the pattern, it is not a problem.

# taken from "mixdrop.py"
domains = ['mixdrop.co', 'mixdrop.to']
pattern = r'(?://|\.)((?:mixdro*p\d*(?:jmk)?|md(?:3b0j6hj|bekjwqa|fx9dc8n|y48tn97|zsmutpcvykb))\.' \
          r'(?:c[ho]m?|to|sx|bz|gl|club|vc|ag|pw|net|is|si|nu|ms))/(?:f|e)/(\w+)'


# get from Settings as string
user_domains = common.get_setting('MixDropResolver_user_domains')  # proposition
user_domains = 'new1.net, new2.bl'  # example
if user_domains:  # if user write something
    user_domains0 = user_domains = user_domains.strip(',. ').lower()  # clean a little
    user_domains = user_domains.split(', ')
    user_domains = list(filter(None, user_domains))  # eliminate empty
    user_domains = list(dict.fromkeys(user_domains))  # eliminate duplicates
    user_domains = [d for d in user_domains if d not in domains]  # eliminate exists
    if user_domains:  # if it's something to add
        domains += user_domains

        ud_name = ud_dot = ''
        for user_domain in user_domains:
            ud = user_domain.split('.')
            ud_name += f"|{ud[0]}"
            ud_dot += f"|{ud[1]}"
        #user_pattern = rf'(?://|\.)((?:{ud_name.lstrip("|")})\.(?:{ud_dot.lstrip("|")}))/(?:f|e)/(\w+)'  # generic pattern
        #print(user_pattern)  # result

        # the problem is where to insert new datas
        pattern = pattern.replace(r'))\.', rf'{ud_name}))\.', 1)
        pattern = pattern.replace('))/', f'{ud_dot}))/', 1)

        # final result
        print(domains)
        print(pattern)

        # check if override user setting
        user_domains = ", ".join(user_domains)  # back from list to string
        if user_domains != user_domains0:
            common.set_setting('MixDropResolver_user_domains', user_domains)  # set to Settings

And how to clean after update:

user_domains = common.get_setting('MixDropResolver_user_domains')  # get user text from settings
if user_domains:  # if user write something
    user_domains = user_domains.strip(',. ').lower()  # clean a little
    user_domains = user_domains.split(', ')  # from string to list
    user_domains = list(filter(None, user_domains))  # eliminate empty
    user_domains = list(dict.fromkeys(user_domains))  # eliminate duplicates
    user_domains = [d for d in user_domains if d not in domains]  # eliminate exists
    user_domains = ", ".join(user_domains)  # back from list to string
    common.set_setting('MixDropResolver_user_domains', user_domains)  # set to Settings

teletcl avatar Jun 02 '24 06:06 teletcl

No, this will make the settings file massive and unusable. Also the patterns generated by code wont be optimal as it is too generic and will take longer to match If Implemented, this feature may be used by less than 0.0001% of the users.

If you are capable of coding, you might as well edit the resolver py file on your device yourself to add the new domain and also raise a PR here which will be merged and released. Your copy will keep working and when there is a new release will get updated and continue to work.

Gujal00 avatar Jun 02 '24 07:06 Gujal00

Thanks for the answer.

I don't know statistics how many people and how often issues about new domain. if it's very rare, then maybe it really doesn't make sense.

Change file on device is easy if it's a PC - on Android (phone, box, TV) it's difficult.

The presented code could perhaps be further optimized - this is the first version, intended to provoke discussion.

teletcl avatar Jun 02 '24 08:06 teletcl

@teletcl for reference, there's a method where you wouldn't have to keep updating the resolvers: https://github.com/Gujal00/ResolveURL/issues/279

I've been using it daily.

There's also PlayThis by anxdpanic, which I think does a similar thing but I'm not sure as I've never used it: https://github.com/anxdpanic/plugin.video.playthis

doko-desuka avatar Jul 22 '24 06:07 doko-desuka