Hash video profile paths

This commit is contained in:
Abel Luck 2026-03-31 15:01:49 +02:00
parent 954608c5f9
commit 2ad0536bb0
5 changed files with 180 additions and 28 deletions

View file

@ -6,7 +6,13 @@ from scrapy.settings import Settings
from repub import entrypoint as entrypoint_module
from repub import settings as repub_settings
from repub.spiders.rss_spider import RssFeedSpider
from repub.utils import FileType, local_audio_path, local_image_path, local_video_path
from repub.utils import (
FileType,
local_audio_path,
local_image_path,
local_video_path,
published_media_path,
)
def test_entrypoint_supports_file_feed_urls(tmp_path: Path, monkeypatch) -> None:
@ -67,15 +73,33 @@ def test_rss_spider_rewrites_public_asset_urls_as_relative_paths() -> None:
)
== f"audio/{local_audio_path('https://example.com/media/podcast.mp3')}-vbr7.mp3"
)
assert (
spider.rewrite_file_url(
FileType.VIDEO,
"https://example.com/media/clip.mp4",
)
== f"video/{local_video_path('https://example.com/media/clip.mp4')}-720.mp4"
assert spider.rewrite_file_url(
FileType.VIDEO,
"https://example.com/media/clip.mp4",
) == (
"video/"
f"{local_video_path('https://example.com/media/clip.mp4')}"
"-720-457f0928.mp4"
)
def test_published_video_path_changes_when_profile_args_change() -> None:
source_url = "https://example.com/media/clip.mp4"
base_profile = repub_settings.REPUBLISHER_VIDEO[0]
assert published_media_path(
FileType.AUDIO, source_url, repub_settings.REPUBLISHER_AUDIO[0]
) == (f"{local_audio_path(source_url)}-vbr7.mp3")
assert published_media_path(FileType.VIDEO, source_url, base_profile) == (
f"{local_video_path(source_url)}-720-457f0928.mp4"
)
changed_profile = {**base_profile, "max_height": 1080}
assert published_media_path(
FileType.VIDEO, source_url, changed_profile
) != published_media_path(FileType.VIDEO, source_url, base_profile)
def test_rss_spider_keeps_items_with_empty_content_encoded() -> None:
feed_text = """<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0">