Skip to content

Commit

Permalink
Merge pull request #6 from JakeLunn/buildid
Browse files Browse the repository at this point in the history
added auto-fetching build id from onepact (fix)
  • Loading branch information
JakeLunn authored Sep 11, 2023
2 parents 2b40002 + c91765d commit f298914
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
10 changes: 5 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ def add_plex_parser(subparsers):
help="Upload metadata for One Piece to Plex (titles, descriptions, etc.)",
)
subparser.add_argument(
"--plex-token",
"-t", "--plex-token",
required=True,
help="Your Plex token \
(see https://support.plex.tv/articles/204059436-finding-an-authentication-token-x-plex-token/)",
)
subparser.add_argument(
"--plex-host",
"-ph", "--plex-host",
required=True,
help="Your Plex host \
(e.g. http://localhost:32400, https://plex.mydomain.com, etc.)",
)
subparser.add_argument(
"--plex-library",
"-l", "--plex-library",
required=False,
help='The name of the Plex library that contains \
One Piece/One Pace episodes \
Expand Down Expand Up @@ -58,15 +58,15 @@ def add_media_parser(subparsers):
help="Create folders for One Pace episodes for the Plex library",
)
subparser.add_argument(
"--source-dir",
"-s", "--source-dir",
required=True,
help="The directory containing the initial downloaded \
One Pace episodes from onepace.net \
Warning: Do NOT change the original file names of \
the downloaded episodes",
)
subparser.add_argument(
"--target-dir", required=True, help="The directory to create the folders in"
"-t", "--target-dir", required=True, help="The directory to create the folders in"
)


Expand Down
16 changes: 15 additions & 1 deletion modules/onepacenet.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
"""Module for calling the onepace.net API to retrieve episode information"""
import re
import requests

BUILD_ID_REGEX = re.compile(r"\"buildId\".+?\"(?P<BuildId>.+?)\"")


class TranslationNotFoundException(Exception):
"""Exception for when a translation is not found"""


def get_build() -> str:
"""Get the Build Id from onepace.net"""
response = requests.get("https://onepace.net", timeout=10)
response.raise_for_status()
return BUILD_ID_REGEX.search(response.text).group("BuildId")


def get_arcs() -> list:
"""Get the One Pace episodes from the API"""
build_id = get_build()
response = requests.get(
"https://onepace.net/_next/data/3ivGuB-QWFxGji410gfuK/en/watch.json", timeout=10
f"https://onepace.net/_next/data/{build_id}/en/watch.json", timeout=10
)
response.raise_for_status()
arcs = response.json()["pageProps"]["arcs"]
Expand All @@ -24,6 +35,7 @@ def get_image(url: str) -> bytes:
response.raise_for_status()
return response.content


def extract_from_translations(media, language_code: str, key: str) -> str:
"""Extract the title from the One Pace episode"""
translation = next(
Expand All @@ -38,10 +50,12 @@ def extract_from_translations(media, language_code: str, key: str) -> str:
raise TranslationNotFoundException(f"No {language_code} translation found")
return translation[key]


def extract_title(media) -> str:
"""Extract the title from the One Pace episode"""
return extract_from_translations(media, "en", "title")


def extract_description(media) -> str:
"""Extract the description from the One Pace episode"""
return extract_from_translations(media, "en", "description")

0 comments on commit f298914

Please sign in to comment.