Skip to content

Gitmask Anonymous PR #40

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Gitmask Anonymous PR #40

wants to merge 1 commit into from

Conversation

gitmask-anonymous
Copy link

This is an anonymous PR submitted via Gitmask - https://www.gitmask.com

Copy link
Collaborator

@rysson rysson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Po włączeniu PR #45, zmiana w normalize nie będzie konieczna.

@@ -30,7 +30,7 @@ def __init__(self):
self.domains = ['fili.cc']

self.base_link = 'https://fili.cc'
self.url_transl = 'embed?type=%s&code=%s&code2=%s&salt=%s'
self.url_transl = 'embed?type=%s&code=%s&code2=%s&salt=%s&title=title&title2=title2'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ta strona potrzebuje stałego napisu w postaci title=title&title2=title2?

@@ -77,7 +77,7 @@ def normalize(title):
try:
try: return title.decode('ascii').encode("utf-8")
except: pass
return str(''.join(c for c in unicodedata.normalize('NFKD', unicode(title.decode('utf-8'))) if unicodedata.category(c) != 'Mn')).replace('ł','l')
return str(''.join(c for c in unicodedata.normalize('NFKD', unicode(title.decode('utf-8'))) if unicodedata.category(c) != 'Mn').replace(u"\u0142",'l'))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A to ciekawe jest. Wiem, że już było i poprawka jest drobna, ale przy okazji:

  1. Czy ta funkcja służy do wycinania ogonków i innych narodowych śmieci?
  2. Czy mamy pewność, że tylko małe litery będą? Małe Ł jest obsłużone (nie dekomponuje się, to nie akcent), ale wielkie już nie. To samo z ręcznym przejściem na 'ąć..' na 'ac'..
  3. Po co jest unicode(title.decode('utf-8')) skoro samo title.decode('utf-8') zwraca unicode?

Może zamieniać resztę dziwnych znaków na ?, np.

maketrans = lambda s1, s2: dict(zip(map(ord, s1), map(ord, s2)))
unicode_translate_table = maketrans(u'łŁ–—\u2044•„”«»', u'lL--/.""<>')

def normalize(title):
    """Convert UTF-8 title to ASCII as well as we can."""
    if not isinstance(title, type(u'')):
        title = title.decode('utf-8')
    title = u''.join(c for c in unicodedata.normalize('NFKD', title) if unicodedata.category(c) != 'Mn')
    return title.translate(unicode_translate_table).encode('ascii', 'replace')

Dzięki czemu mamy konwersję (zawsze można rozszerzyć unicode_translate_table jakby co):

UTF-8 ASCII
Zażółć AŁĆ Zazolc ALC
• Hit – „Česki Film «Arabela ½»” . Hit - "Ceski Film <Arabela 1/2>"
µ-film ?-film

Działa w Python2 i Python3.

EDIT: Dodałem wykrywanie czy to już nie jest unicode, nie trzeba będzie dawać encode przed wywołaniem, jak jest np. w #41.

@rysson rysson self-requested a review March 5, 2019 20:09
@rysson rysson mentioned this pull request Mar 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants