download torrents from imdb links
This commit is contained in:
parent
7273e90066
commit
385694da91
4 changed files with 22 additions and 1 deletions
|
@ -31,7 +31,11 @@ dev-dependencies = [
|
||||||
allow-direct-references = true
|
allow-direct-references = true
|
||||||
|
|
||||||
[tool.hatch.build.targets.wheel]
|
[tool.hatch.build.targets.wheel]
|
||||||
packages = ["src/torrent_downloader"]
|
packages = [
|
||||||
|
"src/torrent_downloader",
|
||||||
|
"static",
|
||||||
|
"templates",
|
||||||
|
]
|
||||||
|
|
||||||
[tool.rye.scripts]
|
[tool.rye.scripts]
|
||||||
client = "python -m torrent_downloader"
|
client = "python -m torrent_downloader"
|
||||||
|
|
|
@ -8,6 +8,7 @@ from fastapi.staticfiles import StaticFiles
|
||||||
from fastapi.templating import Jinja2Templates
|
from fastapi.templating import Jinja2Templates
|
||||||
|
|
||||||
from torrent_downloader.client import TorrentDownloader
|
from torrent_downloader.client import TorrentDownloader
|
||||||
|
from torrent_downloader.imdb import search_string_from_url
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
app.mount("/static", StaticFiles(directory="static"), name="static")
|
app.mount("/static", StaticFiles(directory="static"), name="static")
|
||||||
|
@ -53,6 +54,9 @@ async def search_for_torrents(request: Request):
|
||||||
@app.get("/list", response_class=HTMLResponse)
|
@app.get("/list", response_class=HTMLResponse)
|
||||||
@hx
|
@hx
|
||||||
async def list_torrents(request: Request, query: str, downloader=Depends(get_downloader)):
|
async def list_torrents(request: Request, query: str, downloader=Depends(get_downloader)):
|
||||||
|
if query.startswith("https") and "imdb.com" in query:
|
||||||
|
query = search_string_from_url(query)
|
||||||
|
|
||||||
torrents = downloader.search(query)
|
torrents = downloader.search(query)
|
||||||
return templates.TemplateResponse(
|
return templates.TemplateResponse(
|
||||||
request=request, name="torrents.html", context={"torrents": torrents}
|
request=request, name="torrents.html", context={"torrents": torrents}
|
||||||
|
|
12
src/torrent_downloader/imdb.py
Normal file
12
src/torrent_downloader/imdb.py
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
from urllib.parse import unquote, urlsplit
|
||||||
|
|
||||||
|
from imdb import Cinemagoer
|
||||||
|
|
||||||
|
|
||||||
|
def search_string_from_url(url: str) -> str:
|
||||||
|
print(url)
|
||||||
|
_, _, imdb_id = urlsplit(unquote(url)).path.strip("/").rpartition("/")
|
||||||
|
|
||||||
|
cg = Cinemagoer()
|
||||||
|
movie = cg.get_movie(imdb_id[2:])
|
||||||
|
return f"{movie['title']} {movie['year']}"
|
|
@ -87,4 +87,5 @@ ul.torrents li {
|
||||||
}
|
}
|
||||||
ul.torrents li:hover {
|
ul.torrents li:hover {
|
||||||
background-color: bisque;
|
background-color: bisque;
|
||||||
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue