83 lines
2.5 KiB
Python
83 lines
2.5 KiB
Python
import io
|
|
import shutil
|
|
import tempfile
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
from mutagen import id3
|
|
from PIL import Image, ImageChops
|
|
|
|
from ucast import tests
|
|
from ucast.models import Video
|
|
from ucast.service import videoutil
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_tag_audio():
|
|
video = Video.objects.get(video_id="ZPxEr4YdWt8")
|
|
|
|
tmpdir_o = tempfile.TemporaryDirectory()
|
|
tmpdir = Path(tmpdir_o.name)
|
|
audio_file = tmpdir / "audio.mp3"
|
|
cover_file = tests.DIR_TESTFILES / "cover" / "c1_blur.png"
|
|
shutil.copyfile(tests.DIR_TESTFILES / "audio" / "audio1.mp3", audio_file)
|
|
|
|
videoutil.tag_audio(
|
|
audio_file,
|
|
video.title,
|
|
video.channel.name,
|
|
video.published.date(),
|
|
video.get_full_description(),
|
|
cover_file,
|
|
)
|
|
|
|
tag = id3.ID3(audio_file)
|
|
assert tag["TPE1"].text[0] == "ThetaDev"
|
|
assert tag["TALB"].text[0] == "ThetaDev"
|
|
assert tag["TIT2"].text[0] == "2019-06-02 ThetaDev @ Embedded World 2019"
|
|
assert tag["TDRC"].text[0].text == "2019-06-02"
|
|
assert (
|
|
tag["COMM::XXX"].text[0]
|
|
== """This february I spent one day at the Embedded World in Nuremberg. They showed tons of interesting electronics stuff, so I had to take some pictures and videos for you to see ;-)
|
|
|
|
Sorry for the late upload, I just didn't have time to edit my footage.
|
|
|
|
Embedded World: https://www.embedded-world.de/
|
|
|
|
My website: https://thdev.org
|
|
Twitter: https://twitter.com/Theta_Dev
|
|
|
|
https://youtu.be/ZPxEr4YdWt8"""
|
|
)
|
|
|
|
tag_cover = tag["APIC:Cover"]
|
|
assert tag_cover.mime == "image/png"
|
|
|
|
tag_cover_img = Image.open(io.BytesIO(tag_cover.data))
|
|
expected_cover_img = Image.open(cover_file)
|
|
diff = ImageChops.difference(tag_cover_img, expected_cover_img)
|
|
assert diff.getbbox() is None
|
|
|
|
|
|
def test_resize_avatar():
|
|
tmpdir_o = tempfile.TemporaryDirectory()
|
|
tmpdir = Path(tmpdir_o.name)
|
|
source_file = tests.DIR_TESTFILES / "avatar" / "a1.jpg"
|
|
resized_file = tmpdir / "avatar.webp"
|
|
|
|
videoutil.resize_avatar(source_file, resized_file)
|
|
|
|
resized_avatar = Image.open(resized_file)
|
|
assert resized_avatar.size == (100, 100)
|
|
|
|
|
|
def test_resize_thumbnail():
|
|
tmpdir_o = tempfile.TemporaryDirectory()
|
|
tmpdir = Path(tmpdir_o.name)
|
|
source_file = tests.DIR_TESTFILES / "thumbnail" / "t1.webp"
|
|
resized_file = tmpdir / "thumbnail.webp"
|
|
|
|
videoutil.resize_thumbnail(source_file, resized_file)
|
|
|
|
resized_thumbnail = Image.open(resized_file)
|
|
assert resized_thumbnail.size == (360, 202)
|