Skip to content

Commit

Permalink
feat: Add support for file url scheme (#183)
Browse files Browse the repository at this point in the history
Closes #179
  • Loading branch information
janw authored Sep 22, 2024
1 parent 8a4e30c commit 02dd95d
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ podcast-archiver -d ~/Music/Podcasts \

This way, you can easily add and remove feeds to the list and let the archiver fetch the newest episodes for example by adding it to your crontab.

Feeds can also be "fetched" from a local file:

```bash
podcast-archiver -f file:/Users/janw/downloaded_feed.xml
```

### Changing the filename format

Podcast Archiver has a `--filename-template` option that allows you to change the particular naming scheme of the archive. The default value for `--filename-template`. is shown in `podcast-archiver --help`, as well as all the available variables. The basic ones are:
Expand Down
10 changes: 7 additions & 3 deletions podcast_archiver/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,13 @@ class FeedPage(BaseModel):

@classmethod
def from_url(cls, url: str) -> FeedPage:
response = session.get(url, allow_redirects=True, timeout=REQUESTS_TIMEOUT)
response.raise_for_status()
feedobj = feedparser.parse(response.content)
parsed = urlparse(url)
if parsed.scheme == "file":
feedobj = feedparser.parse(parsed.path)
else:
response = session.get(url, allow_redirects=True, timeout=REQUESTS_TIMEOUT)
response.raise_for_status()
feedobj = feedparser.parse(response.content)
return cls.model_validate(feedobj)


Expand Down
5 changes: 5 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ def feed_lautsprecher(responses: RequestsMock) -> str:
return FEED_URL


@pytest.fixture
def feed_lautsprecher_file() -> str:
return f'file:{FIXTURES_DIR/ "feed_lautsprecher.xml"}'


@pytest.fixture
def feed_lautsprecher_notconsumed(responses: RequestsMock) -> str:
return FEED_URL
Expand Down
22 changes: 22 additions & 0 deletions tests/test_fetch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from pathlib import Path

import pytest

from podcast_archiver.models import Feed

FILE_FIXTURE = Path(__file__).parent / "fixtures" / "feed_lautsprecher.xml"


def test_fetch_from_http(feed_lautsprecher_onlyfeed: str) -> None:
assert Feed.from_url(feed_lautsprecher_onlyfeed)


@pytest.mark.parametrize(
"url",
[
f"file:{FILE_FIXTURE}",
f"file://{FILE_FIXTURE}",
],
)
def test_fetch_from_file(url: str) -> None:
assert Feed.from_url(url)

0 comments on commit 02dd95d

Please sign in to comment.