Skip to content

Commit

Permalink
Added untrusted uploaders option and improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
marcpinet committed Oct 5, 2022
1 parent a517a10 commit 6ebf720
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 15 deletions.
26 changes: 15 additions & 11 deletions lib/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ def setupUi(self, MainWindow) -> None:
self.pushButton_4 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_4.setGeometry(QtCore.QRect(120, 370, 75, 23))
self.pushButton_4.setObjectName("pushButton_4")
self.checkBox_2 = QtWidgets.QCheckBox(self.centralwidget)
self.checkBox_2.setGeometry(QtCore.QRect(340, 50, 101, 17))
self.checkBox_2.setObjectName("checkBox_2")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 21))
Expand Down Expand Up @@ -149,10 +152,9 @@ def retranslateUi(self, MainWindow) -> None:
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "NyaaDownloader"))
self.label.setText(_translate("MainWindow", "Uploaders:"))
self.lineEdit.setText(_translate("MainWindow", "Erai-raws;SubsPlease"))
self.lineEdit.setPlaceholderText(
_translate(
"MainWindow", "Separate them with semicolon (e.g Erai-raws;SubsPlease)"
"MainWindow", "Empty=all, else use semicolon like Erai-raws;SubsPlease"
)
)
self.label_2.setText(_translate("MainWindow", "Anime Title:"))
Expand All @@ -179,6 +181,7 @@ def retranslateUi(self, MainWindow) -> None:
self.pushButton_2.setText(_translate("MainWindow", "Open folder"))
self.pushButton_3.setText(_translate("MainWindow", "Save logs as .txt"))
self.pushButton_4.setText(_translate("MainWindow", "Stop"))
self.checkBox_2.setText(_translate("MainWindow", "Allow untrusted"))
self.menuTranslator.setTitle(_translate("MainWindow", "Translator"))
self.actionGet_translation_of_an_anime_title.setText(
_translate("MainWindow", "Get translation of an anime title")
Expand Down Expand Up @@ -353,10 +356,6 @@ def is_everything_good(self) -> None:
everything_good = True
self.pushButton.setEnabled(False)

if self.lineEdit.text() == "":
self.show_error_popup("You need to input at least 1 uploader name.")
everything_good = False

if self.lineEdit_2.text() == "":
self.show_error_popup("You need to input your anime title.")
everything_good = False
Expand All @@ -379,11 +378,15 @@ def is_everything_good(self) -> None:
# Setting proper values
if everything_good:

global uploaders, anime_name, start_end, quality, option, path
global uploaders, anime_name, start_end, quality, option, untrusted_option, path

uploaders = [
u.strip() for u in self.lineEdit.text().strip().split(";") if u != ""
]

if not uploaders:
uploaders = [""]

anime_name = " ".join(self.lineEdit_2.text().strip().split())
start_end = (
(int(self.spinBox.text()), 10000)
Expand All @@ -392,7 +395,8 @@ def is_everything_good(self) -> None:
)
quality = int(self.comboBox.currentText()[:-1])
option = 1 if self.radioButton.isChecked() else 2

untrusted_option = True if self.radioButton_2.isChecked() else False

folder_name = anime_name
for c in unhandled_characters:
folder_name = folder_name.replace(c, "")
Expand Down Expand Up @@ -426,8 +430,8 @@ def worker_finished(self) -> None:
verbal_base (str): [description]
"""

self.notify(f"The anime {anime_name} has been fully checked!")
self.set_widget_after_check()
self.notify(f"The anime {anime_name} has been fully checked!")

def append_to_logs(self, text: str) -> None:
"""Appends a text to the logs widget
Expand Down Expand Up @@ -459,9 +463,9 @@ def run(self) -> None:
# Will break if "END" found in title (Erai-raws)
while not unexpected_end and episode <= start_end[1] and fails_in_a_row < 10:
for uploader in uploaders:
torrent = nyaa.find_torrent(uploader, anime_name, episode, quality)
torrent = nyaa.find_torrent(uploader, anime_name, episode, quality, untrusted_option)

if torrent is not None:
if torrent:
fails_in_a_row = 0

if option == 1:
Expand Down
14 changes: 10 additions & 4 deletions lib/nyaa.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def is_in_database(anime_name: str) -> bool:
if (
len(
NyaaPy.Nyaa.search(
keyword=anime_name, category=1, subcategory=2, filters=2
keyword=anime_name, category=1, subcategory=2, filters=0
)
)
== 0
Expand Down Expand Up @@ -73,7 +73,7 @@ def transfer(torrent: dict) -> bool:
return True


def find_torrent(uploader: str, anime_name: str, episode: int, quality: int) -> dict:
def find_torrent(uploader: str, anime_name: str, episode: int, quality: int, untrusted_option: bool) -> dict:
"""Find if the torrent is already in the database. If not, download it.
Args:
uploader (str): The name of the uploader.
Expand All @@ -95,8 +95,14 @@ def find_torrent(uploader: str, anime_name: str, episode: int, quality: int) ->
keyword=f"[{uploader}] {anime_name} - {episode} [{quality}p]",
category=1,
subcategory=2,
filters=2,
filters=0 if untrusted_option else 2,
) + NyaaPy.Nyaa.search(
keyword=f"[{uploader}] {anime_name} - {episode} ({quality}p)",
category=1,
subcategory=2,
filters=0 if untrusted_option else 2,
)

try:
# We take the very closest title to what we are looking for.
torrent = None
Expand All @@ -122,6 +128,6 @@ def find_torrent(uploader: str, anime_name: str, episode: int, quality: int) ->
# The only exception possible is that no torrent have been found when NyaaPy.Nyaa.search()
# (we are doing dict operations on a None object => raise an exception)
except:
return None
return {}

return torrent
13 changes: 13 additions & 0 deletions pyqt-ui/base.ui
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,19 @@
<string>Cancel</string>
</property>
</widget>
<widget class="QCheckBox" name="checkBox_2">
<property name="geometry">
<rect>
<x>340</x>
<y>50</y>
<width>101</width>
<height>17</height>
</rect>
</property>
<property name="text">
<string>Allow untrusted</string>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
Expand Down

0 comments on commit 6ebf720

Please sign in to comment.