diff options
-rw-r--r-- | LICENSE | 22 | ||||
-rw-r--r-- | README.md | 17 | ||||
-rw-r--r-- | jnfilter/__init__.py (renamed from jnfilter/main.py) | 31 | ||||
-rw-r--r-- | jnfilter/__main__.py | 4 | ||||
-rw-r--r-- | setup.py | 11 |
5 files changed, 58 insertions, 27 deletions
@@ -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. @@ -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/__init__.py index 193975f..2c7641a 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 @@ def match(title: str, series: List[str]) -> bool: 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 @@ def filter_titles_xml(xml_str) -> Iterator[str]: 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 @@ async def load_titles() -> Iterator[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/jnfilter/__main__.py b/jnfilter/__main__.py new file mode 100644 index 0000000..ff2b876 --- /dev/null +++ b/jnfilter/__main__.py @@ -0,0 +1,4 @@ +from . import run + +if __name__ == '__main__': + run() @@ -8,16 +8,17 @@ requirements = [ 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) |