@@ -62,7 +62,14 @@ def encode(self, info : VsMetaInfo = None) -> bytes:
6262 # ------------------------------------
6363 def _writeFileHeader (self ):
6464 self ._writeTag ( self .TAG_FILE_HEADER_OTHER )
65-
65+
66+ def _writePoster (self ):
67+ self ._writeTag (b'\x01 ' )
68+
69+ if self .info .images .episodeImage :
70+ self .encodedContent += self .TAG_EPISODE_THUMB_DATA + b'\x01 ' + self ._writeImage (self .info .images .episodeImage )
71+ self .encodedContent += self .TAG_EPISODE_THUMB_MD5 + b'\x01 ' + self ._writeMD5 (self .info .images .episodeImage )
72+
6673 def _writeShowTitle (self ):
6774 self ._writeTag ( self .TAG_SHOW_TITLE , self .info .showTitle2 or self .info .showTitle )
6875 self ._writeTag ( self .TAG_SHOW_TITLE2 , self .info .showTitle2 or self .info .showTitle )
@@ -83,7 +90,7 @@ def _writeClassification(self):
8390 self ._writeTag ( self .TAG_CLASSIFICATION , 0 )
8491
8592 def _writeRating (self ):
86- self ._writeTag ( self .TAG_RATING , b'\xFF \xFF \xFF \xFF \xFF \xFF \xFF \xFF \xFF \x01 ' )
93+ self ._writeTag ( self .TAG_RATING , b'\xFF \xFF \xFF \xFF \xFF \xFF \xFF \xFF \xFF ' )
8794
8895 def _writeSummary (self ):
8996 if len (self .info .chapterSummary ) > 0 :
@@ -108,9 +115,7 @@ def _writeGroup2(self):
108115 if (self .info .tvshowReleaseDate .year != 1900 ):
109116 tvshowYear = self .info .tvshowReleaseDate .year
110117 tvshowYear += 2048
111-
112- self ._writeTag ( self .TAG_GROUP2 )
113- self ._writeTag ( b'\x01 ' ) # group 2 - occurence no. 1?
118+
114119 #group 2 payload
115120 group2Content = bytes ()
116121 group2Content += self .TAG2_SEASON + self ._writeSpecialInt (self .info .season )
@@ -125,13 +130,19 @@ def _writeGroup2(self):
125130 if len (self .info .tvshowMetaJson ) > 0 :
126131 group2Content += self .TAG2_TVSHOW_META_JSON
127132 group2Content += self ._writeStr (self .info .tvshowMetaJson )
128-
129- group2Content = len (group2Content ).to_bytes (1 , 'big' ) + group2Content # length of group 2 payload
130-
133+
134+ group2Content += self .TAG2_TVSHOW_SUMMARY + self ._writeStr (self .info .tvshowSummary )
135+
136+ if self .info .images .tvshowPoster :
137+ group2Content += self .TAG2_POSTER_DATA + self ._writeImage (self .info .images .tvshowPoster )
138+ group2Content += self .TAG2_POSTER_MD5 + self ._writeMD5 (self .info .images .tvshowPoster )
139+
140+ self ._writeTag (self .TAG_GROUP2 )
141+ self ._writeTag (b'\x01 ' ) # group 2 - occurence no. 1?
142+ self .encodedContent += self ._writeSpecialInt (len (group2Content ))
131143 self .encodedContent += group2Content
132144
133- # TODO tvshowsummary,
134- # TODO tvshowposter, md5, tv_show_metajson
145+ # TODO tv_show_metajson
135146 self ._writeGroup3
136147
137148 def _writeGroup3 (self , info : VsMetaInfo ):
@@ -155,6 +166,26 @@ def _writeTag(self, tag : bytes, value = None, intBytes : int = 0, signed : bool
155166 if (type (value ) == bool ): self .encodedContent += self ._writeBool (value )
156167 if (type (value ) == bytes ): self .encodedContent += self ._writeBinary (value )
157168
169+ def _writeImage (self , image ) -> bytes :
170+ import base64
171+ converted_string = base64 .b64encode (image )
172+ out_string = ''
173+ count = 0
174+ for char in converted_string .decode ():
175+ if count == 76 :
176+ count = 0
177+ out_string += '\n '
178+ out_string += char
179+ count += 1
180+
181+ returnValue = self ._writeStr (text = out_string )
182+ return returnValue
183+
184+ def _writeMD5 (self , image ) -> bytes :
185+ import hashlib
186+ returnValue = self ._writeStr (text = hashlib .md5 (image ).hexdigest ())
187+ return returnValue
188+
158189 def _writeBinary (self , byteValue : bytes ) -> bytes :
159190
160191 returnValue = bytes ()
@@ -215,4 +246,4 @@ def _writeSpecialInt(self, valueI:int) -> bytes:
215246
216247 returnValue += (value1 | value2 ).to_bytes (1 , 'little' )
217248
218- return returnValue
249+ return returnValue
0 commit comments