Skip to content
This repository was archived by the owner on Mar 22, 2025. It is now read-only.

Commit 02dd95d

Browse files
authored
feat: Add support for file url scheme (#183)
Closes #179
1 parent 8a4e30c commit 02dd95d

File tree

4 files changed

+40
-3
lines changed

4 files changed

+40
-3
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ podcast-archiver -d ~/Music/Podcasts \
6666

6767
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.
6868

69+
Feeds can also be "fetched" from a local file:
70+
71+
```bash
72+
podcast-archiver -f file:/Users/janw/downloaded_feed.xml
73+
```
74+
6975
### Changing the filename format
7076

7177
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:

podcast_archiver/models.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,13 @@ class FeedPage(BaseModel):
163163

164164
@classmethod
165165
def from_url(cls, url: str) -> FeedPage:
166-
response = session.get(url, allow_redirects=True, timeout=REQUESTS_TIMEOUT)
167-
response.raise_for_status()
168-
feedobj = feedparser.parse(response.content)
166+
parsed = urlparse(url)
167+
if parsed.scheme == "file":
168+
feedobj = feedparser.parse(parsed.path)
169+
else:
170+
response = session.get(url, allow_redirects=True, timeout=REQUESTS_TIMEOUT)
171+
response.raise_for_status()
172+
feedobj = feedparser.parse(response.content)
169173
return cls.model_validate(feedobj)
170174

171175

tests/conftest.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ def feed_lautsprecher(responses: RequestsMock) -> str:
3333
return FEED_URL
3434

3535

36+
@pytest.fixture
37+
def feed_lautsprecher_file() -> str:
38+
return f'file:{FIXTURES_DIR/ "feed_lautsprecher.xml"}'
39+
40+
3641
@pytest.fixture
3742
def feed_lautsprecher_notconsumed(responses: RequestsMock) -> str:
3843
return FEED_URL

tests/test_fetch.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from pathlib import Path
2+
3+
import pytest
4+
5+
from podcast_archiver.models import Feed
6+
7+
FILE_FIXTURE = Path(__file__).parent / "fixtures" / "feed_lautsprecher.xml"
8+
9+
10+
def test_fetch_from_http(feed_lautsprecher_onlyfeed: str) -> None:
11+
assert Feed.from_url(feed_lautsprecher_onlyfeed)
12+
13+
14+
@pytest.mark.parametrize(
15+
"url",
16+
[
17+
f"file:{FILE_FIXTURE}",
18+
f"file://{FILE_FIXTURE}",
19+
],
20+
)
21+
def test_fetch_from_file(url: str) -> None:
22+
assert Feed.from_url(url)

0 commit comments

Comments
 (0)