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

Commit 89ea8f4

Browse files
committed
Merge remote-tracking branch 'origin/encoder-decoder' into encoder-decoder
2 parents 94a6f55 + 3d543b5 commit 89ea8f4

File tree

4 files changed

+16
-18
lines changed

4 files changed

+16
-18
lines changed

src/vsmetaCodec/vsmetaBase.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,6 @@ def _writeEncodedContent(self):
8484

8585
return
8686

87-
def contentHashMd5Hex(self) -> str:
88-
return self.encContent.hashMd5Hex()
89-
9087
def writeVsMetaFile(self, file_path: str):
9188
self.encContent.writeToFile(file_path)
9289

@@ -184,7 +181,7 @@ def _writeGroup2(self):
184181
if len(self.info.tvshowSummary) > 0:
185182
grp2_content.writeTag(self.TAG2_TVSHOW_SUMMARY, self.info.tvshowSummary)
186183

187-
image_bytes = None if self.info.posterImage is None else self.info.posterImage.image
184+
image_bytes = None if self.info.posterImageInfo is None else self.info.posterImageInfo.image
188185
if image_bytes is not None and len(image_bytes) > 0:
189186
grp2_content.writeTag(self.TAG2_POSTER_DATA, self.b64encodeImage(image_bytes))
190187
grp2_content.writeTag(self.TAG2_POSTER_MD5, self.calcMD5(image_bytes))

src/vsmetaCodec/vsmetaCode.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
from datetime import date # , datetime, timezone
2-
import hashlib
1+
from datetime import date
32
import base64
43

54

@@ -14,9 +13,6 @@ def __len__(self) -> int:
1413
def data(self) -> bytes:
1514
return self._data
1615

17-
def hashMd5Hex(self) -> str:
18-
return hashlib.md5(self._data).hexdigest()
19-
2016
def writeToFile(self, file_path: str):
2117
if len(self._data) > 0:
2218
with open(file_path, "wb") as f_vsmeta:
@@ -96,7 +92,7 @@ def writeTag(self, tag: bytes, value=None): # , int_bytes: int = 0, signed: boo
9692
return
9793
# write content
9894
if type(value) is int:
99-
self._data += self.calcSpecialInt(value)
95+
self._data += self.specialInt(value)
10096
elif type(value) is str:
10197
self.writeStr(value)
10298
elif type(value) is date:
@@ -114,7 +110,7 @@ def writeStr(self, text: str, with_bom: bool = False):
114110
# byteOrderMark \xEF\xBB\xBF is written automatically when using utf-8-sig.
115111
encoding = 'utf-8-sig' if with_bom else 'utf-8'
116112
text_bytes = bytes(text, encoding)
117-
self._data += self.calcSpecialInt(len(text_bytes)) + text_bytes
113+
self._data += self.specialInt(len(text_bytes)) + text_bytes
118114

119115
def _writeDate(self, date_value: date):
120116
# length of date string: x0a = 10
@@ -127,11 +123,11 @@ def _writeBytes(self, byte_value: bytes):
127123
self._data += byte_value
128124

129125
def _writeContent(self, value):
130-
self._data += self.calcSpecialInt(len(value)) + value.data()
126+
self._data += self.specialInt(len(value)) + value.data()
131127

132128
# --------------- public methods which don't access self._data as of here ----------------
133129
@staticmethod
134-
def calcSpecialInt(num: int) -> bytes:
130+
def specialInt(num: int) -> bytes:
135131
if num < 0:
136132
return b'\x00' # may be better to raise an exception here ?!
137133
return_value = b''

src/vsmetaCodec/vsmetaDecoder.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def _readGroup1(self, code: VsMetaCode) -> int:
100100
return code.byteCountAhead()
101101

102102
def _readGroup2(self, code: VsMetaCode) -> int:
103-
self.info.posterImage = VsMetaImageInfo()
103+
self.info.posterImageInfo = VsMetaImageInfo()
104104
while code.byteCountAhead() > 0:
105105
tag = code.readTag()
106106
if tag == self.TAG2_SEASON:
@@ -116,10 +116,10 @@ def _readGroup2(self, code: VsMetaCode) -> int:
116116
elif tag == self.TAG2_TVSHOW_SUMMARY:
117117
self.info.tvshowSummary = code.readString()
118118
elif tag == self.TAG2_POSTER_DATA:
119-
(self.info.posterImage.image,
120-
self.info.posterImage.b64LastCharIsNewLine) = code.readImage()
119+
(self.info.posterImageInfo.image,
120+
self.info.posterImageInfo.b64LastCharIsNewLine) = code.readImage()
121121
elif tag == self.TAG2_POSTER_MD5:
122-
self.info.posterImage.md5str = code.readString()
122+
self.info.posterImageInfo.md5str = code.readString()
123123
elif tag == self.TAG2_TVSHOW_META_JSON:
124124
self.info.tvshowMetaJson = code.readString()
125125
elif tag == self.TAG2_GROUP3:

src/vsmetaCodec/vsmetaInfo.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import textwrap
22
import json
3+
import hashlib
34
from datetime import date, datetime
45

56

@@ -9,6 +10,10 @@ def __init__(self):
910
self.md5str = ""
1011
self.b64LastCharIsNewLine = False
1112

13+
def calcHashMd5Hex(self) -> str:
14+
self.md5str = hashlib.md5(self.image).hexdigest()
15+
return self.md5str
16+
1217

1318
class VsMetaListInfo:
1419
def __init__(self):
@@ -48,7 +53,7 @@ def __init__(self):
4853
self.tvshowReleaseDate = date(1900, 1, 1)
4954
self.tvshowLocked = True
5055
self.tvshowSummary = ""
51-
self.posterImage = VsMetaImageInfo()
56+
self.posterImageInfo = VsMetaImageInfo()
5257
self.tvshowMetaJson = "null"
5358

5459
# Group3 Information:

0 commit comments

Comments
 (0)