a4k-openproject / script.module.openscrapers

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

New function "get_titles_for_search()" for "source_utils.py" #137

Closed kasi45 closed 4 years ago

kasi45 commented 4 years ago

Please transfer the following function "get_titles_for_search()" to the "source_utils.py

def get_titles_for_search(title, localtitle, aliases):
    try:
        titles = []
        if "country':" in str(aliases): aliases = aliases_to_array(aliases)
        if localtitle != '': titles.append(localtitle)
        if title != ''and title != localtitle: titles.append(title)
        [titles.append(i) for i in aliases if i.lower() != title.lower() and i.lower() != localtitle.lower() and i != '']
        titles = [str(i) for i in titles if all(ord(c) < 128 for c in i)]
        return titles
    except:
        return []

This function simplifies the writing of scrapres. It creates a list from the transferred values in which there are no more duplicates.

as an example you see some codelines from a scraper:

old:

def movie(self, imdb, title, localtitle, aliases, year):
    try:
        url = self.__search([localtitle] + source_utils.aliases_to_array(aliases))
        if not url and title != localtitle: url = self.__search([title] + source_utils.aliases_to_array(aliases))
        return url
    except:
        return

new with "get_titles_for_search()"

def movie(self, imdb, title, localtitle, aliases, year):
    try:
        return self.__search(source_utils.get_titles_for_search(title, localtitle, aliases))
    except:
        return

many thanks

123Venom commented 4 years ago

I have an idea. How about doing a PR and updating all the foreign scrapers to then utilize this new function...then we elect you to take control of the foreign scrapers? Nobody wants to deal with them, and frankly I don't have the time myself. This would be a great help to the OpenScrapers project!! If you decide to do this just please touch base with @Tikipeter as I believe he's doing an update as we speak.