Skip to content
This repository was archived by the owner on Jan 23, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added src/tests/template5_poster.vsmeta
Binary file not shown.
Binary file added src/tests/template_movie5_poster.vsmeta
Binary file not shown.
34 changes: 33 additions & 1 deletion src/tests/testHelpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,36 @@ def writeVsMetaFile(filename: str, content: bytes):

with open(filename, 'wb') as writeFile:
writeFile.write(content)
writeFile.close()
writeFile.close()

def readPosterVsMetaFile(filename: str, filename_out_image: str, START_BYTE, END_BYTE):
import base64
from io import BytesIO
image_bytes = bytes()
read_img = False
read_img_other = False
last_byte = b""

with BytesIO(filename) as f:
byte = f.read(1)
while byte != b"":
# Do stuff with byte.
if byte == START_BYTE:
read_img=True

if byte == END_BYTE and last_byte == b"=":
read_img=False

if read_img and not byte == START_BYTE:
if not byte == b'\n':
image_bytes += byte

last_byte = byte
byte = f.read(1)

f = open(filename_out_image, "wb")
f.write(base64.b64decode((image_bytes)))
f.close()



38 changes: 36 additions & 2 deletions src/tests/testVsMetaMovieEncoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from vsmetaEncoder.vsmetaMovieEncoder import VsMetaMovieEncoder
from vsmetaEncoder.vsmetaInfo import VsMetaInfo
from testHelpers import readTemplateFile, compareBytesBitByBit, compareBytesLength, writeVsMetaFile
from testHelpers import readPosterVsMetaFile, readTemplateFile, compareBytesBitByBit, compareBytesLength, writeVsMetaFile

class TestVsMetaEncoder(unittest.TestCase):

Expand Down Expand Up @@ -76,5 +76,39 @@ def test_encodeTemplate4(self):
compareBytesBitByBit(self, template, testData)
compareBytesLength(self, template, testData)

def test_encodeTemplate5Poster(self):
# setup class under test

template = readTemplateFile(os.path.join(os.path.dirname(os.path.realpath(__file__)),"template_movie5_poster.vsmeta"))
testimage = os.path.join(os.path.dirname(os.path.realpath(__file__)),"Testposter.jpg")


start_byte = VsMetaMovieEncoder.TAG_EPISODE_THUMB_DATA
end_byte = VsMetaMovieEncoder.TAG_EPISODE_THUMB_MD5

readPosterVsMetaFile(template, testimage, start_byte, end_byte)

info = VsMetaInfo()
info.episodeTitle = 'MovieTitle'
info.showTitle = 'Short summary of movie'
info.setEpisodeDate(date(2022, 7, 3))
info.chapterSummary = 'This is a long summary of a movie.'

with open(testimage, "rb") as image2string:
info.images.episodeImage = image2string.read()
os.remove(testimage)

# execute, prepare result
writer = VsMetaMovieEncoder()
testData = writer.encode(info)

#writeVsMetaFile(os.path.join(os.path.dirname(os.path.realpath(__file__)),'template_movie4-reconstructed.vsmeta'), testData)

# compare
compareBytesBitByBit(self, template, testData)
compareBytesLength(self, template, testData)

if __name__ == "__main__":
unittest.main()
unittest.main()


54 changes: 52 additions & 2 deletions src/tests/testvsmetaSeriesEncoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
import os

from vsmetaEncoder.vsmetaSeriesEncoder import VsMetaSeriesEncoder
from vsmetaEncoder.vsmetaMovieEncoder import VsMetaMovieEncoder
from vsmetaEncoder.vsmetaInfo import VsMetaInfo
from testHelpers import readTemplateFile, compareBytesBitByBit, compareBytesLength, writeVsMetaFile
from testHelpers import readPosterVsMetaFile, readTemplateFile, compareBytesBitByBit, compareBytesLength, writeVsMetaFile

class TestVsMetaEncoder(unittest.TestCase):

Expand Down Expand Up @@ -78,6 +77,57 @@ def test_encodeTemplate4(self):
compareBytesBitByBit(self, template, testData)
compareBytesLength(self, template, testData)

def test_encodeTemplate5Poster(self):
# setup class under test

template = readTemplateFile(os.path.join(os.path.dirname(os.path.realpath(__file__)),"template5_poster.vsmeta"))
tvimage = os.path.join(os.path.dirname(os.path.realpath(__file__)),"Testtvimage.jpg")
posterimage = os.path.join(os.path.dirname(os.path.realpath(__file__)),"Testposter.jpg")

readPosterVsMetaFile(template, posterimage,
VsMetaSeriesEncoder.TAG_EPISODE_THUMB_DATA,
VsMetaSeriesEncoder.TAG_EPISODE_THUMB_MD5)

readPosterVsMetaFile(template, tvimage,
VsMetaSeriesEncoder.TAG2_POSTER_DATA,
VsMetaSeriesEncoder.TAG2_POSTER_MD5)

info = VsMetaInfo()


info.showTitle = 'TV series'
info.tvshowLocked = True
info.tvshowSummary = 'Series summary.'
info.season = 1
info.setShowDate(date(2022, 7, 3))
info.tvshowMetaJson = '{}'

with open(tvimage, "rb") as image2string:
info.images.tvshowPoster = image2string.read()

info.episodeTitle = 'Episode Title'
info.setEpisodeDate(date(2022, 7, 3))
info.episodeLocked = True
info.episode = 1
info.chapterSummary = 'This is a long summary of a the episode.'
info.episodeMetaJson = 'null'

with open(posterimage, "rb") as image2string:
info.images.episodeImage = image2string.read()

os.remove(tvimage)
os.remove(posterimage)

# execute, prepare result
writer = VsMetaSeriesEncoder()
testData = writer.encode(info)

#writeVsMetaFile(os.path.join(os.path.dirname(os.path.realpath(__file__)),'template_movie4-reconstructed.vsmeta'), testData)

# compare
compareBytesBitByBit(self, template, testData)
compareBytesLength(self, template, testData)


if __name__ == "__main__":
unittest.main()
14 changes: 8 additions & 6 deletions src/vsmetaEncoder/vsmetaBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,18 @@ def _writeGroup2(self):
else:
group2Content += self.TAG2_TV_SHOW_YEAR + self._writeInt(0, 1, True)
if self.info.tvshowLocked: group2Content += self.TAG2_LOCKED + self._writeBool(True)
if len(self.info.tvshowMetaJson) > 0:
group2Content += self.TAG2_TVSHOW_META_JSON
group2Content += self._writeStr(self.info.tvshowMetaJson)

group2Content += self.TAG2_TVSHOW_SUMMARY + self._writeStr(self.info.tvshowSummary)

if len(self.info.tvshowSummary) > 0:
group2Content += self.TAG2_TVSHOW_SUMMARY + self._writeStr(self.info.tvshowSummary)

if self.info.images.tvshowPoster:
group2Content += self.TAG2_POSTER_DATA + self._writeImage(self.info.images.tvshowPoster)
group2Content += self.TAG2_POSTER_MD5 + self._writeMD5(self.info.images.tvshowPoster)


if len(self.info.tvshowMetaJson) > 0:
group2Content += self.TAG2_TVSHOW_META_JSON
group2Content += self._writeStr(self.info.tvshowMetaJson)

self._writeTag(self.TAG_GROUP2)
self._writeTag(b'\x01') # group 2 - occurence no. 1?
self.encodedContent += self._writeSpecialInt(len(group2Content))
Expand Down
1 change: 1 addition & 0 deletions src/vsmetaEncoder/vsmetaMovieEncoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def _writeEncodedContent(self):
self._writeEpisodeMetaJSON()
self._writeClassification()
self._writeRating()
self._writePoster()

def _writeFileHeader(self):
self._writeTag(self.TAG_FILE_HEADER_MOVIE)
Expand Down