Skip to content

Commit

Permalink
Release 0.1.5. Fix no results issue when not selecting an episode number
Browse files Browse the repository at this point in the history
  • Loading branch information
johnvictorfs committed Dec 16, 2019
1 parent 129e861 commit 697978b
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 10 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

---

## 0.1.5

- Fix issue where selecting no Episodes when searching barely got any selections
- Add published date next to Episode selection entries

---

## 0.1.4

- Add Windows Support [(b609d2f)](https://github.com/johnvictorfs/nyaa-cli/commit/b609d2f05c0b2bb1a42b9654f380d38ab4219df6) (Closes Issue #10)
Expand Down
2 changes: 1 addition & 1 deletion nyaacli/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def main(anime: str, episode: int, output: str):
\b
Example:
\33[92mnyaa \33[36m"Kimetsu no Yaiba" \33[33m19 \33[34m-o "My/Animes/Folder/Kimetsu_No_Yaiba/\033[0m
\33[92mnyaa \33[36m"Kimetsu no Yaiba" \33[33m19 \33[34m-o /home/user/My/Animes/Folder/Kimetsu_No_Yaiba/\033[0m
"""
torrent_search = search_torrent(anime, episode)

Expand Down
22 changes: 18 additions & 4 deletions nyaacli/nyaa_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from urllib import request
from typing import Optional, List, Tuple
from dataclasses import dataclass
from datetime import datetime
from time import mktime
import os
import feedparser

Expand Down Expand Up @@ -45,6 +47,7 @@ class Entry:
seeders: Optional[str]
size: Optional[str]
episode_title: Optional[str]
date: datetime


def search_torrent(search: str, episode: Optional[int] = None, dub: bool = False) -> Optional[Tuple[str, str]]:
Expand All @@ -58,12 +61,19 @@ def search_torrent(search: str, episode: Optional[int] = None, dub: bool = False
if episode:
search_query += f" {episode}".replace(' ', '%20')

search_url = f"https://nyaa.si/rss?c=1_2&q={search_query}&s=seeders&o=desc"

# Parse Nyaa.si rss feed search
feed: feedparser.FeedParserDict = feedparser.parse(f"https://nyaa.si/rss?c=1_2&q={search_query}&s=seeders&o=desc")
feed: feedparser.FeedParserDict = feedparser.parse(search_url)

if not feed.entries and feed.bozo_exception:
# Malformatted feed
print(red(f"[Error] {str(feed.bozo_exception)}"))
sys.exit(1)

entries: List[Entry] = []

for entry in feed['entries']:
for entry in feed.entries:
title = guessit(entry['title'])

if not title.get('screen_size'):
Expand All @@ -77,7 +87,7 @@ def search_torrent(search: str, episode: Optional[int] = None, dub: bool = False
# Screen size needs to be higher than 480p
good_size = int(title.get('screen_size').replace('p', '')) > 480

if title.get('episode') == episode and title.get('type') == 'episode' and good_size:
if (title.get('episode') == episode or not episode) and title.get('type') == 'episode' and good_size:
entries.append(Entry(
link=entry['link'],
size=entry['nyaa_size'],
Expand All @@ -93,7 +103,8 @@ def search_torrent(search: str, episode: Optional[int] = None, dub: bool = False
other=title.get('other'),
release_group=title.get('release_group'),
screen_size=title.get('screen_size'),
alternative_title=title.get('alternative_title')
alternative_title=title.get('alternative_title'),
date=datetime.fromtimestamp(mktime(entry.get('published_parsed')))
))

if not entries:
Expand Down Expand Up @@ -141,6 +152,9 @@ def search_torrent(search: str, episode: Optional[int] = None, dub: bool = False
if entry.size:
entry_title += f" - {entry.size}"

if entry.date:
entry_title += f" ({entry.date.strftime('%d/%m/%y')})"

entry.display_title = entry_title

choices = [{'name': entry.display_title, 'value': index} for index, entry in enumerate(entries[:5])]
Expand Down
9 changes: 5 additions & 4 deletions nyaacli/torrenting.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,19 @@ def download_torrent(filename: str, result_filename: str = None, show_progress:
progress = green(f"{status.progress * 100:.2f}%")
download_rate = green(f"{status.download_rate / 1000:.1f} kB/s")

sys.stdout.write(
f'\r{green(str(status.state).title())} - {progress} '
print(
f'◉ {green(str(status.state).title())} - {progress} '
f'(Download: {download_rate} - Upload: {status.upload_rate / 1000:.1f} kB/s - '
f'Peers: {status.num_peers}) '
f'Peers: {status.num_peers}) ',
end='\r'
)

alerts = session.pop_alerts()

alert: libtorrent.alert
for alert in alerts:
if alert.category() & libtorrent.alert.category_t.error_notification:
sys.stdout.write(f"\r{red('[Alert]')} {alert} ")
sys.stdout.write(f"{red('[Alert]')} {alert} \r")

sys.stdout.flush()

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "nyaacli"
version = "0.1.4"
version = "0.1.5"
description = "A CLI for downloading Anime from https://nyaa.si"
authors = ["John Victor <johnvictorfs@gmail.com>"]
license = "MIT"
Expand Down

0 comments on commit 697978b

Please sign in to comment.