jnfilter @ 74aa2ec7fcd8881b442dce1e6cd24e53ee1c2919

feat: Adiciona tag opcionalmente

Agora para ativar a tag no metadata e preciso passar um _query param_
`tag=true`.
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000000000000000000000000000000000000..588d327cb48b7636ddc55620254b780856f2e4bd
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,22 @@
+MIT License
+
+Copyright (c) 2021 Gabriel Arakaki Giovanini
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+of the Software, and to permit persons to whom the Software is furnished to do
+so, subject to the following conditions:
+
+The above copyright notice and this permission notice (including the next
+        paragraph) shall be included in all copies or substantial portions of the
+Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+    SOFTWARE.
diff --git a/README.md b/README.md
index 71a700f3f7bd664861b2e9e9917cf3d1d6ddfc48..30a5a41f93c90024e19188169332f1920655b944 100644
--- a/README.md
+++ b/README.md
@@ -45,21 +45,26 @@ Adicionei recentemente uma parte no código pare mexer na metadata do feed
 (mudar titulo, nome, descrição, etc) para fazer com que o Pocketcast reconheça
 o feed gerado como se fosse outro feed. Eles usam a metadata para decidir se um
 feed e novo, então como eu não mexia na metadata ele gerava um link para o feed
-original do jovem nerd.
+original do jovem nerd. Para ativar essa funcionalidade use parametro
+`tag=true`, exemplo:
+
+```
+https://jnfilter.gabrielgio.me/?q=nerdcash,nerdcast&tag=true
+```
 
 Entao os usuarios do Pocketcast tem que ir ao https://pocketcasts.com/submit/
 para submeterem a sua URL. Observação, esse processo de submit deles e meio
 cagado, então se ele não oferecer o feed certo tente trocar as ordens dos
 parâmetro, se tiver `nerdcast,mamicas` troque para `mamicas,nercast`
 
-o ideal e que cliente de podcast nao obrigue a fazer isso mas fazer o que as outras
-opções fazem pior.
+o ideal e que cliente de podcast nao obrigue a fazer isso mas fazer o que as
+outras opções fazem pior.
 
 ## Para programadores
 
-E um projeto simples feito em cima do FastApi. Ele vai pegar o _feed_ e
-filtrar os itens do _feed_ do podcast. Não tem cache nem nada sendo armazenado,
-todo processamento e feito a partir do feed para cada requisição.
+E um projeto simples feito em cima do FastApi. Ele vai pegar o _feed_ e filtrar
+os itens do _feed_ do podcast. Não tem cache nem nada sendo armazenado, todo
+processamento e feito a partir do feed para cada requisição.
 
 Para rodar basta instalar os requirements e rodar o seguinte código:
 
diff --git a/jnfilter/__main__.py b/jnfilter/__main__.py
new file mode 100644
index 0000000000000000000000000000000000000000..ff2b876b8a6e8561b7cf4bcd07153c57cf6527da
--- /dev/null
+++ b/jnfilter/__main__.py
@@ -0,0 +1,4 @@
+from . import run
+
+if __name__ == '__main__':
+    run()
diff --git a/jnfilter/main.py b/jnfilter/__init__.py
rename from jnfilter/main.py
rename to jnfilter/__init__.py
index 193975fb757caa8556d9e68f6a8e0c759b3af8bc..2c7641a07a789f2d4b170076174701443c1670e2 100644
--- a/jnfilter/main.py
+++ b/jnfilter/__init__.py
@@ -3,7 +3,7 @@ import httpx
 import uvicorn
 
 from functools import reduce
-from typing import List, Iterator
+from typing import List, Iterator, Union
 from xml.etree.ElementTree import ElementTree, fromstring, tostring, register_namespace
 from fastapi import FastAPI
 from starlette.responses import Response, PlainTextResponse
@@ -44,21 +44,20 @@
     return reduce(lambda x, y: x or _match(y), series, False)
 
 
-def filter_xml(xml_str: str, series: List[str]) -> str:
+def filter_xml(xml_str: str, series: List[str], tag: Union[bool, None] = False) -> str:
     tree = ElementTree(fromstring(xml_str))
     tree_root = tree.getroot()
     for channel in tree_root.findall("./channel"):
-        tag = f' [{",".join(series)}]'.upper()
 
-        channel.find("title").text += tag
-        channel.find("description").text += tag
-        channel.find("link").text += f"?{tag}"
-        channel.find(f"{{{ITUNES}}}author").text += tag
-        channel.find(f"{{{GOOGLEPLAY}}}author").text += tag
-        channel.find(f"{{{ITUNES}}}subtitle").text += tag
-        channel.find(f"{{{ITUNES}}}summary").text += tag
-
-        print({elem.tag for elem in channel.iter()})
+        if tag:
+            tag = f' [{",".join(series)}]'.upper()
+            channel.find("title").text += tag
+            channel.find("description").text += tag
+            channel.find("link").text += f"?{tag}"
+            channel.find(f"{{{ITUNES}}}author").text += tag
+            channel.find(f"{{{GOOGLEPLAY}}}author").text += tag
+            channel.find(f"{{{ITUNES}}}subtitle").text += tag
+            channel.find(f"{{{ITUNES}}}summary").text += tag
 
         for item in channel.findall("item"):
             title = item.find("title").text
@@ -75,13 +74,13 @@     for item in tree_root.findall("./channel/item"):
         yield item.find("title").text
 
 
-async def load_and_filter(series: str) -> str:
+async def load_and_filter(series: str, tag: Union[bool, None] = False) -> str:
     series = series or 'nerdcast'
     series = series.split(',')
     async with httpx.AsyncClient() as client:
         response = await client.get(URL)
         xml_str = response.content
-        return filter_xml(xml_str, series)
+        return filter_xml(xml_str, series, tag)
 
 
 async def load_titles() -> Iterator[str]:
@@ -92,8 +91,8 @@         return filter_titles_xml(xml_str)
 
 @app.head("/")
 @app.get("/", response_class=XMLResponse)
-async def root(q: str = ''):
-    return await load_and_filter(q)
+async def root(q: str = '', tag: Union[bool, None] = False):
+    return await load_and_filter(q, tag)
 
 
 @app.get("/titles", response_class=PlainTextResponse)
diff --git a/setup.py b/setup.py
index 8f95a75c9c6878bc492bd789794aa4ffa918dd1f..07add8246257827906a2d7f0a149d2a00ff2223d 100644
--- a/setup.py
+++ b/setup.py
@@ -8,16 +8,17 @@ ]
 
 
 setup(name='jnfilter',
-    version='0.2.1',
+    version='0.3.0',
     description='A FastAPI server to filter Nercast podcast feed',
     url='https://git.sr.ht/~gabrielgio/jnfilter',
     author='Gabriel Arakaki Giovanini',
     author_email='mail@gabrielgio.me',
     license='MIT',
     packages=['jnfilter'],
-    entry_points="""
-    [console_scripts]
-    jnfilterd=jnfilter.main:run
-    """,
+    entry_points={
+        'console_scripts': [
+            'jnfilterd=jnfilter',
+        ]
+    },
     install_requires=requirements,
     zip_safe=False)