@@ -227,13 +227,20 @@ def rawToFields(cls, raw={}):
227
227
msgTime = datetime .strptime (raw .get ("originalarrivaltime" , "" ), "%Y-%m-%dT%H:%M:%S.%fZ" )
228
228
except ValueError :
229
229
msgTime = datetime .now ()
230
- return {"id" : raw .get ("id" ),
231
- "type" : raw .get ("messagetype" ),
232
- "time" : msgTime ,
233
- "clientId" : raw .get ("clientmessageid" , raw .get ("skypeeditedid" )),
234
- "userId" : SkypeUtils .userToId (raw .get ("from" , "" )),
235
- "chatId" : SkypeUtils .chatToId (raw .get ("conversationLink" , "" )),
236
- "content" : raw .get ("content" )}
230
+ fields = {"id" : raw .get ("id" ),
231
+ "type" : raw .get ("messagetype" ),
232
+ "time" : msgTime ,
233
+ "clientId" : raw .get ("clientmessageid" , raw .get ("skypeeditedid" )),
234
+ "userId" : SkypeUtils .userToId (raw .get ("from" , "" )),
235
+ "chatId" : SkypeUtils .chatToId (raw .get ("conversationLink" , "" )),
236
+ "content" : raw .get ("content" )}
237
+ if fields ["content" ]:
238
+ fields .update (cls .contentToFields (BeautifulSoup (fields ["content" ], "html.parser" )))
239
+ return fields
240
+
241
+ @classmethod
242
+ def contentToFields (cls , content ):
243
+ return {}
237
244
238
245
@classmethod
239
246
def fromRaw (cls , skype = None , raw = {}):
@@ -369,10 +376,10 @@ class SkypeContactMsg(SkypeMsg):
369
376
attrs = SkypeMsg .attrs + ("contactIds" , "contactNames" )
370
377
371
378
@classmethod
372
- def rawToFields (cls , raw = {} ):
373
- fields = super (SkypeContactMsg , cls ).rawToFields ( raw )
379
+ def contentToFields (cls , content ):
380
+ fields = super (SkypeContactMsg , cls ).contentToFields ( content )
374
381
fields .update ({"contactIds" : [], "contactNames" : []})
375
- contactTags = BeautifulSoup ( raw . get ( " content" ), "html.parser" ) .find_all ("c" )
382
+ contactTags = content .find_all ("c" )
376
383
for tag in contactTags :
377
384
fields ["contactIds" ].append (tag .get ("s" ))
378
385
fields ["contactNames" ].append (tag .get ("f" ))
@@ -411,9 +418,9 @@ class SkypeLocationMsg(SkypeMsg):
411
418
attrs = SkypeMsg .attrs + ("latitude" , "longitude" , "altitude" , "speed" , "course" , "address" , "mapUrl" )
412
419
413
420
@classmethod
414
- def rawToFields (cls , raw = {} ):
415
- fields = super (SkypeLocationMsg , cls ).rawToFields ( raw )
416
- locTag = BeautifulSoup ( raw . get ( " content" ), "html.parser" ) .find ("location" )
421
+ def contentToFields (cls , content ):
422
+ fields = super (SkypeLocationMsg , cls ).contentToFields ( content )
423
+ locTag = content .find ("location" )
417
424
for attr in ("latitude" , "longitude" , "altitude" , "speed" , "course" ):
418
425
fields [attr ] = int (locTag .get (attr )) if locTag .get (attr ) else None
419
426
# Exponent notation produces a float, meaning lat/long will always be floats too.
@@ -480,9 +487,9 @@ def data(self):
480
487
attrs = SkypeMsg .attrs + ("title" , "body" , "buttons" )
481
488
482
489
@classmethod
483
- def rawToFields (cls , raw = {} ):
484
- fields = super (SkypeCardMsg , cls ).rawToFields ( raw )
485
- swiftTag = BeautifulSoup ( raw . get ( " content" ), "html.parser" ) .find ("swift" )
490
+ def contentToFields (cls , content ):
491
+ fields = super (SkypeCardMsg , cls ).contentToFields ( content )
492
+ swiftTag = content .find ("swift" )
486
493
data = json .loads (base64 .b64decode (swiftTag .get ("b64" )))
487
494
card = data .get ("attachments" , [{}])[0 ].get ("content" , {})
488
495
fields .update ({"title" : card .get ("title" ),
@@ -565,10 +572,10 @@ def urlAsm(self):
565
572
attrs = SkypeMsg .attrs + ("file" ,)
566
573
567
574
@classmethod
568
- def rawToFields (cls , raw = {} ):
569
- fields = super (SkypeFileMsg , cls ).rawToFields ( raw )
575
+ def contentToFields (cls , content ):
576
+ fields = super (SkypeFileMsg , cls ).contentToFields ( content )
570
577
# BeautifulSoup converts tag names to lower case, and find() is case-sensitive.
571
- file = BeautifulSoup ( raw . get ( " content" ), "html.parser" ) .find ("uriobject" )
578
+ file = content .find ("uriobject" )
572
579
if file :
573
580
fileFields = {"name" : (file .find ("originalname" ) or {}).get ("v" ),
574
581
"size" : (file .find ("filesize" ) or {}).get ("v" ),
@@ -657,9 +664,9 @@ class SkypeCallMsg(SkypeMsg):
657
664
attrs = SkypeMsg .attrs + ("state" , "userIds" , "userNames" )
658
665
659
666
@classmethod
660
- def rawToFields (cls , raw = {} ):
661
- fields = super (SkypeCallMsg , cls ).rawToFields ( raw )
662
- listTag = BeautifulSoup ( raw . get ( " content" ), "html.parser" ) .find ("partlist" )
667
+ def contentToFields (cls , content ):
668
+ fields = super (SkypeCallMsg , cls ).contentToFields ( content )
669
+ listTag = content .find ("partlist" )
663
670
fields .update ({"state" : {"started" : cls .State .Started ,
664
671
"ended" : cls .State .Ended ,
665
672
"missed" : cls .State .Missed }.get (listTag .get ("type" )),
@@ -710,9 +717,9 @@ class SkypeTopicPropertyMsg(SkypePropertyMsg):
710
717
attrs = SkypeMsg .attrs + ("topic" ,)
711
718
712
719
@classmethod
713
- def rawToFields (cls , raw = {} ):
714
- fields = super (SkypeTopicPropertyMsg , cls ).rawToFields ( raw )
715
- propInfo = BeautifulSoup ( raw . get ( " content" ), "html.parser" ) .find ("topicupdate" )
720
+ def contentToFields (cls , content ):
721
+ fields = super (SkypeTopicPropertyMsg , cls ).contentToFields ( content )
722
+ propInfo = content .find ("topicupdate" )
716
723
if propInfo :
717
724
fields .update ({"userId" : SkypeUtils .noPrefix (propInfo .find ("initiator" ).text ),
718
725
"topic" : propInfo .find ("value" ).text })
@@ -738,9 +745,9 @@ class SkypeOpenPropertyMsg(SkypePropertyMsg):
738
745
attrs = SkypeMsg .attrs + ("open" ,)
739
746
740
747
@classmethod
741
- def rawToFields (cls , raw = {} ):
742
- fields = super (SkypeOpenPropertyMsg , cls ).rawToFields ( raw )
743
- propInfo = BeautifulSoup ( raw . get ( " content" ), "html.parser" ) .find ("joiningenabledupdate" )
748
+ def contentToFields (cls , content ):
749
+ fields = super (SkypeOpenPropertyMsg , cls ).contentToFields ( content )
750
+ propInfo = content .find ("joiningenabledupdate" )
744
751
if propInfo :
745
752
fields .update ({"userId" : SkypeUtils .noPrefix (propInfo .find ("initiator" ).text ),
746
753
"open" : propInfo .find ("value" ).text == "true" })
@@ -766,9 +773,9 @@ class SkypeHistoryPropertyMsg(SkypePropertyMsg):
766
773
attrs = SkypeMsg .attrs + ("history" ,)
767
774
768
775
@classmethod
769
- def rawToFields (cls , raw = {} ):
770
- fields = super (SkypeHistoryPropertyMsg , cls ).rawToFields ( raw )
771
- propInfo = BeautifulSoup ( raw . get ( " content" ), "html.parser" ) .find ("historydisclosedupdate" )
776
+ def contentToFields (cls , content ):
777
+ fields = super (SkypeHistoryPropertyMsg , cls ).contentToFields ( content )
778
+ propInfo = content .find ("historydisclosedupdate" )
772
779
if propInfo :
773
780
fields .update ({"userId" : SkypeUtils .noPrefix (propInfo .find ("initiator" ).text ),
774
781
"history" : propInfo .find ("value" ).text == "true" })
@@ -805,9 +812,9 @@ class SkypeAddMemberMsg(SkypeMemberMsg):
805
812
"""
806
813
807
814
@classmethod
808
- def rawToFields (cls , raw = {} ):
809
- fields = super (SkypeAddMemberMsg , cls ).rawToFields ( raw )
810
- memInfo = BeautifulSoup ( raw . get ( " content" ), "html.parser" ) .find ("addmember" )
815
+ def contentToFields (cls , content ):
816
+ fields = super (SkypeAddMemberMsg , cls ).contentToFields ( content )
817
+ memInfo = content .find ("addmember" )
811
818
if memInfo :
812
819
fields .update ({"userId" : SkypeUtils .noPrefix (memInfo .find ("initiator" ).text ),
813
820
"memberId" : SkypeUtils .noPrefix (memInfo .find ("target" ).text )})
@@ -833,9 +840,9 @@ class SkypeChangeMemberMsg(SkypeMemberMsg):
833
840
attrs = SkypeMemberMsg .attrs + ("admin" ,)
834
841
835
842
@classmethod
836
- def rawToFields (cls , raw = {} ):
837
- fields = super (SkypeChangeMemberMsg , cls ).rawToFields ( raw )
838
- memInfo = BeautifulSoup ( raw . get ( " content" ), "html.parser" ) .find ("roleupdate" )
843
+ def contentToFields (cls , content ):
844
+ fields = super (SkypeChangeMemberMsg , cls ).contentToFields ( content )
845
+ memInfo = content .find ("roleupdate" )
839
846
if memInfo :
840
847
fields .update ({"userId" : SkypeUtils .noPrefix (memInfo .find ("initiator" ).text ),
841
848
"memberId" : SkypeUtils .noPrefix (memInfo .find ("target" ).find ("id" ).text ),
@@ -859,9 +866,9 @@ class SkypeRemoveMemberMsg(SkypeMemberMsg):
859
866
"""
860
867
861
868
@classmethod
862
- def rawToFields (cls , raw = {} ):
863
- fields = super (SkypeRemoveMemberMsg , cls ).rawToFields ( raw )
864
- memInfo = BeautifulSoup ( raw . get ( " content" ), "html.parser" ) .find ("deletemember" )
869
+ def contentToFields (cls , content ):
870
+ fields = super (SkypeRemoveMemberMsg , cls ).contentToFields ( content )
871
+ memInfo = content .find ("deletemember" )
865
872
if memInfo :
866
873
fields .update ({"userId" : SkypeUtils .noPrefix (memInfo .find ("initiator" ).text ),
867
874
"memberId" : SkypeUtils .noPrefix (memInfo .find ("target" ).text )})
0 commit comments