Skip to content

Commit

Permalink
Merge pull request #49 from SenZmaKi/v2.1.11
Browse files Browse the repository at this point in the history
v2.1.11
  • Loading branch information
SenZmaKi authored Jul 30, 2024
2 parents fd48848 + ae617d6 commit 90554d2
Show file tree
Hide file tree
Showing 34 changed files with 899 additions and 473 deletions.
19 changes: 10 additions & 9 deletions docs/release-notes.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# New features

- Add tips in about section
- senpcli: Stylize output 💅✨
# New features and Changes
- Shorten long anime titles in progress bars
- Hover on folder button shows folder location
- senpcli: Always show units/time instead of time/units in progress bars
- senpcli: Add anime tracking functionality
- senpcli: Add option to print direct download links instead of downloading

# Bug fixes

- Maybe fix randomly skipped downloads, if it still happens report it
- pahe: Fix infinite loading for some anime. Issue #43
- senpcli: Sort of fix Ctrl+C not terminating program, it still bugs out sometimes though
- Fix some linux port issues
- Fix some gogo downloads randomly failing, if you still experience it be sure to report it
- Fix failed to fetch direct download links notification on cancelling direct download links retrieval
- Fix anime randomizer
- Fix opening chosen anime window for other anime failing if previous attempt failed
2 changes: 1 addition & 1 deletion docs/senpcli-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Senpwai ships with the Senpcli pre-installed.
pip install senpwai
```

- **Android (Using [termux](https://github.com/termux/termux-app))**
- **Android (Using [termux](https://github.com/termux/termux-app), note that the android port is currently really buggy and barely even works)**

```sh
pkg update -y && curl https://raw.githubusercontent.com/SenZmaKi/Senpwai/master/termux/install.sh | bash
Expand Down
13 changes: 6 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "senpwai"
version = "2.1.10"
version = "2.1.11"
description = "A desktop app for tracking and batch downloading anime"
authors = ["SenZmaKi <[email protected]>"]
license = "GPL v3"
Expand Down Expand Up @@ -68,13 +68,12 @@ bump_version = "python -m scripts.bump_version"
announce = "python -m scripts.announce"
announce_discord = "python scripts/announce/discord.py"
announce_reddit = "python scripts/announce/reddit.py"
ruff = [{ ref = "lint_fix" }, { ref = "format" }]
lint = "python -m scripts.ruff"
lint_fix = "python -m scripts.ruff --lint_fix"
format = "python -m scripts.ruff --format"
generate_release_test = [{ref = "lint"}, { ref = "test" }, { ref = "generate_release" }]
generate_release_ddl = [{ ref = "test_ddl" }, { ref = "generate_release" }]
generate_release = [
lint_fix = "python -m scripts.ruff --lint_fix"
lint = "python -m scripts.ruff --lint"
build_release_test = [{ref = "lint"}, { ref = "test" }, { ref = "build_release" }]
build_release_ddl = [{ ref = "test_ddl" }, { ref = "build_release" }]
build_release = [
{ ref = "build_exes" },
{ ref = "compile_installers" },
{ ref = "install" },
Expand Down
15 changes: 13 additions & 2 deletions scripts/announce/__main__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
from argparse import ArgumentParser
from scripts.announce.main import main
from scripts.common import get_piped_input, ARGS
from scripts.common import get_piped_input

if __name__ == "__main__":
main(ARGS[0], get_piped_input())
parser = ArgumentParser("Announce a new release on Discord and Reddit")
parser.add_argument("-t", "--title", type=str, help="Title of the release")
parser.add_argument(
"-r",
"--release_notes",
type=str,
help="Release notes, will use stdin if not provided",
)
parsed = parser.parse_args()
release_notes = parsed.release_notes or get_piped_input()
main(parsed.title, release_notes)
133 changes: 116 additions & 17 deletions scripts/announce/discord.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,141 @@
from argparse import ArgumentParser
from enum import Enum
import json
from typing import Any
import requests
import re

from scripts.common import ARGS, ROOT_DIR, get_piped_input
from scripts.common import ROOT_DIR, get_piped_input
from scripts.announce.common import FailedToAnnounce

CHANNEL_URL = "https://discord.com/api/v10/channels/1142774130689720370/messages"
CHANNEL_URL = "https://discord.com/api/v10/channels/{}/messages"
URL_REGEX = re.compile(r"https://\S+")


class ChannelID(Enum):
general = "1131981620975517787"
help = "1190075801815748648"
bug_reports = "1134645830163378246"
suggestions = "1134645775905861673"
github_logs = "1205730845953097779"
misc = "1211137093955362837"
announcements = "1142774130689720370"

def __str__(self) -> str:
return self.name


def remove_embed_url(string: str) -> str:
return URL_REGEX.sub(lambda x: f"<{x.group(0)}>", string)


def main(title: str, release_notes: str) -> None:
with open(ROOT_DIR.joinpath(".credentials/discord.json")) as f:
def send_message(message: str, channel_id: str, message_reference_id: str) -> None:
with open(ROOT_DIR.joinpath(".credentials", "discord.json")) as f:
token = json.load(f)["token"]
headers = {
"Authorization": f"Bot {token}",
"Content-Type": "application/json",
}
nonembed_notes = remove_embed_url(release_notes)
smaller_titles = "\n".join(
[
line.replace("# ", "## ", 1) if line.strip().startswith("# ") else line
for line in nonembed_notes.splitlines()
]
)

everyone = "@everyone\n" if "--ping_everyone" in ARGS else ""
message = f"{everyone}# {title}\n\n" + smaller_titles
payload = {
payload: dict[str, Any] = {
"content": message,
}
response = requests.post(url=CHANNEL_URL, headers=headers, json=payload)
if message_reference_id:
payload["message_reference"] = {"message_id": message_reference_id}
url = CHANNEL_URL.format(channel_id)
response = requests.post(url, headers=headers, json=payload)
if not response.ok:
raise FailedToAnnounce("discord", response.json())


def main(
title: str,
message: str,
is_release_notes=True,
pinged_user_id="",
message_reference_id="",
channel_id=ChannelID.announcements.value,
) -> None:
if is_release_notes:
non_embed_notes = remove_embed_url(message)
message = "\n".join(
[
line.replace("# ", "## ", 1) if line.strip().startswith("# ") else line
for line in non_embed_notes.splitlines()
]
)
if pinged_user_id:
ping_str = (
"@everyone" if pinged_user_id == "everyone" else f"<@{pinged_user_id}>"
)
message = (
f"{ping_str}\n{message}"
if pinged_user_id == "everyone" and is_release_notes
else f"{ping_str} {message}"
)
if title:
message = f"# {title}\n{message}"
send_message(message, channel_id, message_reference_id)


if __name__ == "__main__":
main(ARGS[0], get_piped_input())
parser = ArgumentParser(description="Message on Discord")
parser.add_argument("-t", "--title", help="Title of the message", default="")
parser.add_argument(
"-m",
"--message",
help="Body of the message, will use stdin if not provided",
default="",
)
parser.add_argument(
"-irn",
"--is_release_notes",
action="store_true",
help="Whether the message is release notes",
)
parser.add_argument(
"-pui",
"--pinged_user_id",
type=str,
help="ID of the user to ping",
default="",
)
parser.add_argument(
"-pe",
"--ping_everyone",
action="store_true",
help="Ping everyone",
)
parser.add_argument(
"-mri",
"--message_reference_id",
type=str,
help="ID of the message to reply to",
default="",
)
parser.add_argument(
"-cid",
"--channel_id",
type=str,
help="ID of the channel to send the message to",
default="",
)
parser.add_argument(
"-c",
"--channel",
type=lambda channel: ChannelID[channel],
choices=list(ChannelID),
help="Channel to send the message to",
default=ChannelID.announcements,
)
parsed = parser.parse_args()
message = parsed.message or get_piped_input()
channel_id = parsed.channel_id or parsed.channel.value
pinged_user_id = "everyone" if parsed.ping_everyone else parsed.pinged_user_id
main(
parsed.title,
message,
parsed.is_release_notes,
pinged_user_id,
parsed.message_reference_id,
channel_id,
)
26 changes: 19 additions & 7 deletions scripts/announce/reddit.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from argparse import ArgumentParser
from typing import Any, cast
from scripts.announce.common import FailedToAnnounce
from scripts.common import ARGS, ROOT_DIR, get_piped_input
from scripts.common import ROOT_DIR, get_piped_input
import json
import requests
import re
Expand All @@ -22,7 +23,7 @@ def validate_response(is_ok: bool, response_json: dict[str, Any]) -> None:


def fetch_access_token() -> str:
with open(ROOT_DIR.joinpath(".credentials/reddit.json"), "r") as f:
with open(ROOT_DIR.joinpath(".credentials", "reddit.json"), "r") as f:
credentials = json.load(f)
data = {
"scope": "*",
Expand All @@ -41,7 +42,7 @@ def fetch_access_token() -> str:

def submit_post(
title: str,
release_notes: str,
message: str,
access_token: str,
) -> str:
headers = {"Authorization": f"Bearer {access_token}", "User-Agent": "script"}
Expand All @@ -52,7 +53,7 @@ def submit_post(
"sr": "Senpwai",
"resubmit": "true",
"send_replies": "true",
"text": release_notes,
"text": message,
}

response = requests.post(SUBMIT_POST_URL, headers=headers, data=data)
Expand All @@ -70,14 +71,25 @@ def approve_post(post_short_id: str, access_token: str) -> None:
validate_response(response.ok, response_json)


def main(title: str, release_notes: str) -> None:
def main(title: str, message: str) -> None:
log_info("Fetching auth token")
access_token = fetch_access_token()
log_info("Submitting post")
post_short_id = submit_post(title, release_notes, access_token)
post_short_id = submit_post(title, message, access_token)
log_info("Approving post")
approve_post(post_short_id, access_token)


if __name__ == "__main__":
main(ARGS[0], get_piped_input())
parser = ArgumentParser(description="Post on Reddit")
parser.add_argument("-t", "--title", type=str, help="Title of the post")
parser.add_argument(
"-m",
"--message",
type=str,
default="",
help="Body of the post, will use stdin if not provided",
)
parsed = parser.parse_args()
message = parsed.message or get_piped_input()
main(parsed.title, message)
53 changes: 31 additions & 22 deletions scripts/bump_version.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from argparse import ArgumentParser
from functools import cache
import subprocess
import sys
import re
from typing import cast
from .common import (
ROOT_DIR,
ARGS,
get_current_branch_name,
git_commit,
log_error as common_log_error,
Expand All @@ -23,9 +23,6 @@
ROOT_DIR.joinpath("scripts/setup_senpcli.iss"),
]

USAGE = """
Usage: bump_version <OLD_VERSION> <NEW_VERSION>
"""
ENCOUNTERED_ERROR = False
VERSION_REGEX = re.compile(r"(\d+(\.\d+)*)")

Expand Down Expand Up @@ -59,11 +56,6 @@ def get_new_version() -> str:
return cast(re.Match, new_version).group(1)


def get_versions() -> tuple[str, str]:
prev_version, new_version = get_prev_version(), get_new_version()
return prev_version, new_version


def bump_version(prev_version: str, new_version: str, ignore_same: bool):
for file_path in FILES_PATHS:
if not file_path.is_file():
Expand All @@ -85,20 +77,37 @@ def bump_version(prev_version: str, new_version: str, ignore_same: bool):


def main(ignore_same=False) -> None:
if len(ARGS) == 1 and ARGS[0] in ("--help", "-h"):
print(USAGE)
return
if len(ARGS) == 2:
prev_version = ARGS[0]
new_version = ARGS[1]
else:
prev_version, new_version = get_versions()
if not ignore_same and prev_version == new_version:
log_error(f"Previous and New version are the same: {prev_version}", True)
log_info(f"Bumping version from {prev_version} --> {new_version}")
bump_version(prev_version, new_version, ignore_same)
parser = ArgumentParser(description="Bump version in files")
parser.add_argument(
"-is",
"--ignore_same",
action="store_true",
help="Ignore if previous and new version are the same",
)
parser.add_argument(
"-pv",
"--previous_version",
type=str,
help="Previous version to bump from",
default=get_prev_version(),
)
parser.add_argument(
"-nv",
"--new_version",
type=str,
help="New version to bump to",
default=get_new_version(),
)
parsed = parser.parse_args()
ignore_same = parsed.ignore_same
previous_version = parsed.previous_version
new_version = parsed.new_version
if not ignore_same and previous_version == new_version:
log_error(f"Previous and New version are the same: {previous_version}", True)
log_info(f"Bumping version from {previous_version} --> {new_version}")
bump_version(previous_version, new_version, ignore_same)
subprocess.run("git --no-pager diff").check_returncode()
git_commit(f"Bump version from {prev_version} --> {new_version}")
git_commit(f"Bump version from {previous_version} --> {new_version}")
if ENCOUNTERED_ERROR:
sys.exit(1)

Expand Down
Loading

0 comments on commit 90554d2

Please sign in to comment.