Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sourcery refactored main branch #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

sourcery-ai[bot]
Copy link

@sourcery-ai sourcery-ai bot commented Jun 15, 2022

Branch main refactored by Sourcery.

If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

Review changes via command line

To manually merge these changes, make sure you're on the main branch, then run:

git fetch origin sourcery/main
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from zYxDevs June 15, 2022 04:31
@@ -34,7 +34,6 @@


@app.get("/api/v1/search")
# @cache(expire=CACHE_EXPIRATION)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function call_api refactored with the following changes:

This removes the following comments ( why? ):

# @cache(expire=CACHE_EXPIRATION)

@@ -58,7 +57,6 @@ async def call_api(


@app.get("/api/v1/trending")
# @cache(expire=CACHE_EXPIRATION)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_trending refactored with the following changes:

This removes the following comments ( why? ):

# @cache(expire=CACHE_EXPIRATION)

return {"error": "invalid site"}


@app.get("/api/v1/category")
# @cache(expire=CACHE_EXPIRATION)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_category refactored with the following changes:

This removes the following comments ( why? ):

# @cache(expire=CACHE_EXPIRATION)

return {"error": "invalid site"}


@app.get("/api/v1/recent")
# @cache(expire=CACHE_EXPIRATION)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_recent refactored with the following changes:

This removes the following comments ( why? ):

# @cache(expire=CACHE_EXPIRATION)

if site in all_sites.keys():
if site in all_sites:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function check_if_site_available refactored with the following changes:

if not category:
url = self.BASE_URL + "/new/"
else:
url = self.BASE_URL + "/{}/".format(category)
url = self.BASE_URL + f"/{category}/" if category else f"{self.BASE_URL}/new/"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Kickass.recent refactored with the following changes:

Comment on lines -27 to +29
if a.text == "One-filetorrent":
if a["href"] != "#":
obj["torrent"] = self.BASE_URL + a["href"]
poster = soup.find_all("img")[0]

if poster:
if a.text == "One-filetorrent" and a["href"] != "#":
obj["torrent"] = self.BASE_URL + a["href"]
if poster := soup.find_all("img")[0]:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Libgen._individual_scrap refactored with the following changes:

Comment on lines -63 to +64
authors = []
author = td[1].find_all("a")
for a in author:
authors.append(a.text.strip())
authors = [a.text.strip() for a in author]
name_and_url = td[2].find("a")
name = name_and_url.text
url = self.BASE_URL + "/" + name_and_url["href"]
url = f"{self.BASE_URL}/" + name_and_url["href"]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Libgen._parser refactored with the following changes:

Comment on lines -108 to +105
+ "/search.php?req={}&lg_topic=libgen&open=0&view=simple&res=100&phrase=1&column=def".format(
query
)
+ f"/search.php?req={query}&lg_topic=libgen&open=0&view=simple&res=100&phrase=1&column=def"
)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Libgen.search refactored with the following changes:

Comment on lines -29 to +30
).group(0)
)[0]

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Limetorrent._individual_scrap refactored with the following changes:

Comment on lines -98 to +99
url = self.BASE_URL + "/search/all/{}//{}".format(query, page)
url = self.BASE_URL + f"/search/all/{query}//{page}"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Limetorrent.search refactored with the following changes:

Comment on lines -115 to +116
url = self.BASE_URL + "/top100"
url = f"{self.BASE_URL}/top100"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Limetorrent.trending refactored with the following changes:

Comment on lines -123 to +131
url = self.BASE_URL + "/latest100"
url = f"{self.BASE_URL}/latest100"
else:
category = (category).capitalize()
if category == "Apps":
category = "Applications"
elif category == "Tv":
category = "TV-shows"
url = self.BASE_URL + "/browse-torrents/{}/date/{}/".format(
category, page
)
url = (self.BASE_URL + f"/browse-torrents/{category}/date/{page}/")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Limetorrent.recent refactored with the following changes:

Comment on lines -47 to +69
).group(0),
)[0],
"magnet": magnet,
"url": self.BASE_URL + url,
"date": date,
}
)

if len(my_dict["data"]) == self.LIMIT:
break
total_results = soup.find("div", id="footer").text.replace(",", "")
current_page = int(
(re.search(r"Page\s\d*", total_results).group(0)).replace(
"Page ", ""
)
re.search(r"Page\s\d*", total_results)[0].replace("Page ", "")
)

total_pages = (
int(
(
(re.search(r"Found\s\d*", total_results).group(0)).replace(
"Found ", ""
)
re.search(r"Found\s\d*", total_results)[0].replace(
"Found ", ""
)
)
// 40
)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Magnetdl._parser refactored with the following changes:

Comment on lines -100 to +99
url = self.BASE_URL + "/{}/{}/se/desc/{}/".format(query[0], query, page)
url = self.BASE_URL + f"/{query[0]}/{query}/se/desc/{page}/"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Magnetdl.search refactored with the following changes:

Comment on lines -149 to +152
url = self.BASE_URL + "/fresh.html"
url = f"{self.BASE_URL}/fresh.html"
else:
if category == "books":
category = "ebooks"
url = self.BASE_URL + "/{}/{}/added/desc.html".format(category, page)
url = self.BASE_URL + f"/{category}/{page}/added/desc.html"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Torlock.recent refactored with the following changes:

url = self.BASE_URL + "/?t={}&p={}".format(query, page - 1)
url = self.BASE_URL + f"/?t={query}&p={page - 1}"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TorrentProject.search refactored with the following changes:

Comment on lines -76 to +83
).group(0),
)[0],
"magnet": magnet,
"torrent": torrent,
"url": self.BASE_URL + url,
"date": date,
}
)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TorrentGalaxy._parser refactored with the following changes:

Comment on lines -108 to +111
+ "/torrents.php?search=+{}&sort=seeders&order=desc&page={}".format(
query, page - 1
)
+ f"/torrents.php?search=+{query}&sort=seeders&order=desc&page={page - 1}"
)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TorrentGalaxy.search refactored with the following changes:

Comment on lines -135 to +143
url = self.BASE_URL + "/latest"
url = f"{self.BASE_URL}/latest"
else:
if category == "documentaries":
category = "Docus"
url = (
self.BASE_URL
+ "/torrents.php?parent_cat={}&sort=id&order=desc&page={}".format(
str(category).capitalize(), page - 1
)
+ f"/torrents.php?parent_cat={str(category).capitalize()}&sort=id&order=desc&page={page - 1}"
)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TorrentGalaxy.recent refactored with the following changes:

Comment on lines -76 to +80
"uploader": uploader if uploader else None,
"uploader": uploader or None,
"url": url,
}
)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TorrentFunk._parser refactored with the following changes:

Comment on lines -90 to +91
url = self.BASE_URL + "/all/torrents/{}/{}.html".format(query, page)
url = self.BASE_URL + f"/all/torrents/{query}/{page}.html"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TorrentFunk.search refactored with the following changes:

Comment on lines -115 to +116
url = self.BASE_URL + "/movies/recent.html"
url = f"{self.BASE_URL}/movies/recent.html"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TorrentFunk.recent refactored with the following changes:

Comment on lines -36 to +46
obj["poster"] = "https:" + poster
obj["poster"] = f"https:{poster}"
elif str(poster).startswith("/"):
obj["poster"] = self.BASE_URL + poster
except:
pass
obj["magnet"] = magnet

obj["hash"] = re.search(
r"([{a-f\d,A-F\d}]{32,40})\b", magnet
).group(0)
obj["hash"] = re.search(r"([{a-f\d,A-F\d}]{32,40})\b", magnet)[
0
]

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function x1337._individual_scrap refactored with the following changes:

Comment on lines -72 to +73
name = td[0].find_all("a")[-1].text
if name:
if name := td[0].find_all("a")[-1].text:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function x1337._parser refactored with the following changes:

hash = re.search(r"([{a-f\d,A-F\d}]{32,40})\b", magnet).group(0)
hash = re.search(r"([{a-f\d,A-F\d}]{32,40})\b", magnet)[0]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Yts._individual_scrap refactored with the following changes:

Comment on lines -135 to +139
+ "/browse-movies/{}/all/all/0/latest/0/all?page={}".format(
query, page
)
+ f"/browse-movies/{query}/all/all/0/latest/0/all?page={page}"
)

else:
url = self.BASE_URL + "/browse-movies/{}/all/all/0/latest/0/all".format(
query
)
url = (self.BASE_URL + f"/browse-movies/{query}/all/all/0/latest/0/all")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Yts.search refactored with the following changes:

Comment on lines -159 to +156
url = self.BASE_URL + "/trending-movies"
url = f"{self.BASE_URL}/trending-movies"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Yts.trending refactored with the following changes:

Comment on lines -166 to +163
url = self.BASE_URL + "/browse-movies/0/all/all/0/featured/0/all"
url = f"{self.BASE_URL}/browse-movies/0/all/all/0/featured/0/all"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Yts.recent refactored with the following changes:

Comment on lines -46 to +52
).group(0),
)[0],
"magnet": magnet,
"url": self.BASE_URL + url,
"date": date,
}
)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Zooqle._parser refactored with the following changes:

@sourcery-ai
Copy link
Author

sourcery-ai bot commented Jun 15, 2022

Sourcery Code Quality Report

✅  Merging this PR will increase code quality in the affected files by 0.01%.

Quality metrics Before After Change
Complexity 8.79 🙂 8.51 ⭐ -0.28 👍
Method Length 71.14 🙂 71.42 🙂 0.28 👎
Working memory 11.12 😞 11.30 😞 0.18 👎
Quality 58.65% 🙂 58.66% 🙂 0.01% 👍
Other metrics Before After Change
Lines 2367 2346 -21
Changed files Quality Before Quality After Quality Change
main.py 53.65% 🙂 56.28% 🙂 2.63% 👍
helper/is_site_available.py 62.02% 🙂 62.05% 🙂 0.03% 👍
torrents/bitsearch.py 52.09% 🙂 51.39% 🙂 -0.70% 👎
torrents/glodls.py 61.16% 🙂 60.90% 🙂 -0.26% 👎
torrents/kickass.py 62.24% 🙂 61.91% 🙂 -0.33% 👎
torrents/libgen.py 57.87% 🙂 59.91% 🙂 2.04% 👍
torrents/limetorrents.py 62.58% 🙂 62.21% 🙂 -0.37% 👎
torrents/magnet_dl.py 56.07% 🙂 55.69% 🙂 -0.38% 👎
torrents/nyaa_si.py 56.71% 🙂 56.71% 🙂 0.00%
torrents/pirate_bay.py 60.35% 🙂 59.34% 🙂 -1.01% 👎
torrents/torlock.py 56.91% 🙂 56.84% 🙂 -0.07% 👎
torrents/torrentProject.py 70.03% 🙂 69.80% 🙂 -0.23% 👎
torrents/torrent_galaxy.py 40.56% 😞 39.63% 😞 -0.93% 👎
torrents/torrentfunk.py 68.35% 🙂 68.66% 🙂 0.31% 👍
torrents/x1337.py 59.63% 🙂 57.47% 🙂 -2.16% 👎
torrents/your_bittorrent.py 69.47% 🙂 69.58% 🙂 0.11% 👍
torrents/yts.py 57.74% 🙂 57.70% 🙂 -0.04% 👎
torrents/zooqle.py 51.37% 🙂 51.41% 🙂 0.04% 👍

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
torrents/torrent_galaxy.py TorrentGalaxy._parser 39 ⛔ 374 ⛔ 19 ⛔ 12.35% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
torrents/magnet_dl.py Magnetdl._parser 25 😞 246 ⛔ 18 ⛔ 23.46% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
torrents/bitsearch.py Bitsearch._parser 17 🙂 262 ⛔ 21 ⛔ 26.18% 😞 Try splitting into smaller methods. Extract out complex expressions
torrents/torlock.py Torlock._parser 19 😞 220 ⛔ 15 😞 31.95% 😞 Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
torrents/x1337.py x1337._parser 15 🙂 196 😞 19 ⛔ 33.03% 😞 Try splitting into smaller methods. Extract out complex expressions

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.


Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Help us improve this quality report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0 participants