-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
finish basic functionality, set up ghcr.io
- Loading branch information
1 parent
86d33b7
commit edbea83
Showing
8 changed files
with
168 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
name: Code Quality | ||
|
||
on: [push, pull_request] | ||
on: [push, pull_request, workflow_call] | ||
|
||
jobs: | ||
lint: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
name: 'Publish release image to ghcr.io' | ||
on: | ||
# publish on releases, e.g. v2.1.13 (image tagged as "2.1.13") | ||
# NB: "v" prefix is removed | ||
release: | ||
types: | ||
- published | ||
|
||
# publish "latest" tag on pushes to the main branch | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
code_quality: | ||
uses: './.github/workflows/code-quality.yml' | ||
|
||
build_dockerfile: | ||
uses: './.github/workflows/docker.yml' | ||
|
||
publish_release: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
packages: write | ||
contents: read | ||
# TODO: Re-enable code_quality after we fix ruff etc. | ||
# needs: [code_quality, build_dockerfile] | ||
needs: build_dockerfile | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Build and publish a Docker image for ${{ github.repository }} | ||
uses: macbre/push-to-ghcr@master | ||
with: | ||
image_name: ${{ github.repository }} | ||
github_token: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
name: Docker | ||
|
||
on: [push, pull_request] | ||
on: [push, pull_request, workflow_call] | ||
|
||
jobs: | ||
lint: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import json | ||
|
||
|
||
def populate_discs_json( | ||
*, | ||
template_file: str, | ||
title: str, | ||
author: str, | ||
duration: int, | ||
lores: list[str] = None, | ||
) -> dict: | ||
with open(template_file, encoding="utf-8") as template_file: | ||
discs = json.load(template_file) | ||
|
||
discs[0]["title"] = str(title) | ||
discs[0]["author"] = str(author) | ||
discs[0]["duration"] = int(duration) | ||
|
||
# `lores` is optional, custom lores can be specified in the template file | ||
if lores: | ||
if len(lores < 3): | ||
discs[0]["lores"] = lores | ||
else: | ||
raise ValueError(f"lores array has too many items! ({len(lores)} > 2)") | ||
|
||
return discs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
"""Simple helper module for managing RSS feeds.""" | ||
|
||
from .rss_helper import RSSHelper # noqa: F401 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
"""Simple helper class for managing RSS feeds.""" | ||
import requests | ||
from rss_parser import Parser | ||
from rss_parser.models.item import Item | ||
from rss_parser.models.types import Tag | ||
|
||
|
||
class RSSHelper: | ||
|
||
"""Simple helper class for managing RSS feeds.""" | ||
|
||
__feed_url: str = "" | ||
__feed = None | ||
__user_agent = None | ||
|
||
def __init__(self, url: str, *, user_agent: str): | ||
"""Initialize internal feed URL, feed object, and user-agent.""" | ||
self.__feed_url = url | ||
self.__user_agent = user_agent | ||
|
||
self.__feed = self.from_url(self.__feed_url) | ||
|
||
def feed(self): | ||
return self.__feed | ||
|
||
def from_url(self, url: str): | ||
"""Create an RSS object from a feed URL.""" | ||
print(f"[RSS] Downloading feed from {url}...") | ||
|
||
feed_req = requests.get( | ||
url, timeout=1000, headers={"User-Agent": self.__user_agent} | ||
) | ||
|
||
feed_req.raise_for_status() | ||
|
||
return Parser.parse(feed_req.text) | ||
|
||
def latest_episode(self, *, feed=None) -> Tag[Item]: | ||
"""Get the latest episode from an RSS feed.""" | ||
if not feed: | ||
feed = self.__feed | ||
|
||
print(f"[RSS] Feed language: {feed.channel.language}") | ||
print(f"[RSS] Feed version: {feed.version}") | ||
|
||
feed_items = feed.channel.items | ||
|
||
# The feed is ordered by date ascending so the newest episodes are at | ||
# the end of rss_items | ||
feed_items.reverse() | ||
|
||
i = 0 | ||
|
||
# TODO: Check the number of items in rss_items before entering this loop | ||
while True: | ||
i = i + 1 | ||
|
||
latest_rss_item = feed_items.pop() | ||
|
||
title = latest_rss_item.title.lower() | ||
|
||
# TODO: Make this filter customizable | ||
if not title.startswith("teaser"): | ||
return latest_rss_item | ||
|
||
# HACK: Find a better way of handling this edge case | ||
if i > 5: # abort after 5 iterations so we're not here all day | ||
raise RuntimeError("Could not find a non-teaser episode after 5 tries.") | ||
|
||
def episode_file_url(self, episode) -> str: | ||
"""Get the URL to download the audio file for an episode.""" | ||
return episode.enclosure.attributes["url"] |