Compare commits

...

11 Commits

Author SHA1 Message Date
Florian Wetzel
239dd02b79
Merge 7d1941ed7595896103dfcfa8e8c8f0d5b4aa7514 into eb4558569ce18a1120232cbd51e07cdb37e3c16e 2024-03-19 16:36:20 +00:00
CommanderRedYT
7d1941ed75
Improvements 2024-03-19 17:35:30 +01:00
CommanderRedYT
429010f664
Improvements 2024-03-19 16:33:22 +01:00
CommanderRedYT
61b584f547
Improvements 2024-03-19 16:22:09 +01:00
CommanderRedYT
5833594769
Improvements 2024-03-19 16:15:05 +01:00
CommanderRedYT
a17d8de8d4
Improvements 2024-03-19 16:09:03 +01:00
CommanderRedYT
1ea8832cac
Improvements 2024-03-19 16:04:15 +01:00
CommanderRedYT
8b70df5f93
Relace function with builtin 2024-03-19 15:56:00 +01:00
CommanderRedYT
fccf9c865a
Fixes 2024-03-19 15:56:00 +01:00
CommanderRedYT
a4b5081c7a
Ignore venv folder from jetbrains 2024-03-19 15:56:00 +01:00
CommanderRedYT
2481248736
Add ability to have a different name for folder 2024-03-19 15:55:59 +01:00
7 changed files with 31 additions and 10 deletions

View File

@ -53,6 +53,7 @@ An example configuration is provided in the docker-compose.yml file. Configure t
- `TA_TOKEN`: Tube Archivist API token, accessible from the settings page - `TA_TOKEN`: Tube Archivist API token, accessible from the settings page
- `JF_URL`: Full URL where Jellyfin is reachable - `JF_URL`: Full URL where Jellyfin is reachable
- `JF_TOKEN`: Jellyfin API token - `JF_TOKEN`: Jellyfin API token
- `JF_FOLDER`: Folder override if your folder is not named "YouTube" on your Filesystem.
- `LISTEN_PORT`: Optionally change the port where the integration is listening for messages. Defaults to `8001`. If you change this, make sure to also change the json link for auto trigger as described below. - `LISTEN_PORT`: Optionally change the port where the integration is listening for messages. Defaults to `8001`. If you change this, make sure to also change the json link for auto trigger as described below.
Mount the `/youtube` folder from Tube Archivist also in this container at `/youtube` to give this integration access to the media archive. Mount the `/youtube` folder from Tube Archivist also in this container at `/youtube` to give this integration access to the media archive.
@ -83,6 +84,7 @@ pip install requests
- `ta_token`: Tube Archivist API token, accessible from the settings page - `ta_token`: Tube Archivist API token, accessible from the settings page
- `jf_url`: Full URL where Jellyfin is reachable - `jf_url`: Full URL where Jellyfin is reachable
- `jf_token`: Jellyfin API token - `jf_token`: Jellyfin API token
- `jf_folder`: Name of the folder where TubeArchivist puts the files into
Then run the script from the main folder with python, e.g. Then run the script from the main folder with python, e.g.
```python ```python

View File

@ -38,6 +38,7 @@ def get_config_env() -> ConfigType | Literal[False]:
"ta_token": os.environ["TA_TOKEN"], "ta_token": os.environ["TA_TOKEN"],
"jf_url": os.environ["JF_URL"], "jf_url": os.environ["JF_URL"],
"jf_token": os.environ["JF_TOKEN"], "jf_token": os.environ["JF_TOKEN"],
"jf_folder": os.environ.get("JF_FOLDER", "youtube"),
} }
return config_content return config_content

View File

@ -9,7 +9,14 @@ from src.static_types import ConfigType, TAChannel, TAVideo
CONFIG: ConfigType = get_config() CONFIG: ConfigType = get_config()
TIMEOUT = 60 TIMEOUT = 60
EXPECTED_ENV = {"ta_url", "ta_token", "jf_url", "jf_token", "ta_video_path"} EXPECTED_ENV = {
"ta_url",
"ta_token",
"jf_url",
"jf_token",
"ta_video_path",
"jf_folder",
}
class Jellyfin: class Jellyfin:

View File

@ -22,8 +22,10 @@ class Library:
"""get collection id for youtube folder""" """get collection id for youtube folder"""
path: str = "Items?Recursive=true&includeItemTypes=Folder" path: str = "Items?Recursive=true&includeItemTypes=Folder"
folders: dict = Jellyfin().get(path) folders: dict = Jellyfin().get(path)
folder_name: str = get_config()["jf_folder"]
for folder in folders["Items"]: for folder in folders["Items"]:
if folder.get("Name").lower() == "youtube": if folder.get("Name").lower() == folder_name.lower():
return folder.get("Id") return folder.get("Id")
raise ValueError("youtube folder not found") raise ValueError("youtube folder not found")
@ -72,7 +74,7 @@ class Library:
path: str = f"Items/{collection_id}/Refresh?Recursive=true&ImageRefreshMode=Default&MetadataRefreshMode=Default" # noqa: E501 path: str = f"Items/{collection_id}/Refresh?Recursive=true&ImageRefreshMode=Default&MetadataRefreshMode=Default" # noqa: E501
Jellyfin().post(path, False) Jellyfin().post(path, False)
for _ in range(12): for _ in range(24):
response = Jellyfin().get("Library/VirtualFolders") response = Jellyfin().get("Library/VirtualFolders")
for folder in response: for folder in response:
if not folder["ItemId"] == collection_id: if not folder["ItemId"] == collection_id:
@ -82,7 +84,7 @@ class Library:
return return
print("waiting for library refresh") print("waiting for library refresh")
sleep(5) sleep(10)
class Show: class Show:
@ -207,10 +209,13 @@ class Show:
"""wait for season to be created in JF""" """wait for season to be created in JF"""
jf_id: str = self.show["Id"] jf_id: str = self.show["Id"]
path: str = f"Items/{jf_id}/Refresh?Recursive=true&ImageRefreshMode=Default&MetadataRefreshMode=Default" # noqa: E501 path: str = f"Items/{jf_id}/Refresh?Recursive=true&ImageRefreshMode=Default&MetadataRefreshMode=Default" # noqa: E501
print(f"[setup] {path=}")
Jellyfin().post(path, False) Jellyfin().post(path, False)
for _ in range(12): for _ in range(100):
all_existing: set[str] = set(self._get_existing_seasons()) all_existing: set[str] = set(self._get_existing_seasons())
print(f"[setup] seasons: {all_existing} {expected_season=}")
if expected_season in all_existing: if expected_season in all_existing:
return return
@ -225,7 +230,11 @@ class Show:
path: str = f"Shows/{series_id}/Seasons" path: str = f"Shows/{series_id}/Seasons"
all_seasons: dict = Jellyfin().get(path) all_seasons: dict = Jellyfin().get(path)
return [str(i.get("IndexNumber")) for i in all_seasons["Items"]] print(f"[setup] {path=} all_seasons_items={all_seasons['Items']}")
res = [str(i.get("Name")) for i in all_seasons["Items"]]
return [name.split(' ')[1] if ' ' in name else name for name in res]
def delete_folders(self, folders: list[str]) -> None: def delete_folders(self, folders: list[str]) -> None:
"""delete temporary folders created""" """delete temporary folders created"""

View File

@ -11,6 +11,7 @@ class ConfigType(TypedDict):
ta_token: str ta_token: str
jf_url: str jf_url: str
jf_token: str jf_token: str
jf_folder: str
class TAChannel(TypedDict): class TAChannel(TypedDict):

View File

@ -3,5 +3,6 @@
"ta_url": "http://tubearchivist.local", "ta_url": "http://tubearchivist.local",
"ta_token": "xxxxxxxxxxxxxxxx", "ta_token": "xxxxxxxxxxxxxxxx",
"jf_url": "http://jellyfin.local:8096", "jf_url": "http://jellyfin.local:8096",
"jf_token": "yyyyyyyyyyyyyyyy" "jf_token": "yyyyyyyyyyyyyyyy",
"jf_folder": "YouTube"
} }

View File

@ -17,12 +17,12 @@ function validate {
echo "running black" echo "running black"
black --force-exclude "migrations/*" --diff --color --check -l 79 "$check_path" black --force-exclude "migrations/*" --diff --color --check -l 79 "$check_path"
echo "running codespell" echo "running codespell"
codespell --skip="./.git,./.venv,./.mypy_cache" "$check_path" codespell --skip="./.git,./.venv,venv,./.mypy_cache" "$check_path"
echo "running flake8" echo "running flake8"
flake8 "$check_path" --exclude "migrations,.venv" --count --max-complexity=10 \ flake8 "$check_path" --exclude "migrations,.venv,venv" --count --max-complexity=10 \
--max-line-length=79 --show-source --statistics --max-line-length=79 --show-source --statistics
echo "running isort" echo "running isort"
isort --skip "migrations" --skip ".venv" --check-only --diff --profile black -l 79 "$check_path" isort --skip "migrations" --skip ".venv" --skip "venv" --check-only --diff --profile black -l 79 "$check_path"
printf " \n> all validations passed\n" printf " \n> all validations passed\n"
} }