Profile Picture Save + Fix Duplicate Problem - #12
Conversation
3bl3gamer
left a comment
There was a problem hiding this comment.
Hello (:
Thank you again, and here are some comments:
| for _, d := range group { | ||
| for _, c := range chats { | ||
| if d.ID == c.ID { | ||
| continue //If duplicates don't add to array again |
There was a problem hiding this comment.
It will continue the inner range chats loop, i.e. do nothing. Loop label is missing?
| } | ||
| case mtproto.TL_photos_photosSlice: //Downloads first 20 photos if 20+ photos exists | ||
| photos := resPhotos.(mtproto.TL_photos_photosSlice) | ||
| for _, photo := range photos.Photos { |
There was a problem hiding this comment.
There are two almost same loops, better move it outside of switch. For example
var photos []mtproto.TL
switch {
...
photos = append(photos, ...photos.Photos)
...
}
for _, photo := range photos {Also, _, err = os.Stat(fpath) is missing in second (this one) loop.
| } | ||
| } | ||
|
|
||
| func tgGetPhotoFileInfo(photo mtproto.TL_photo) *TGFileInfo { |
There was a problem hiding this comment.
This func does the half work of the tgGetMessageMediaFileInfo. So it's better to move that half inside tgGetPhotoFileInfo (including FName: "photo.jpg" and if size == nil, just in case) and call this func from tgGetMessageMediaFileInfo.
| for _, photo := range photos.Photos { | ||
| photo := photo.(mtproto.TL_photo) | ||
| file := tgGetPhotoFileInfo(photo) | ||
| fpath := profilePicFPath + "/" + strconv.Itoa(int(photo.Date)) + ".jpg" |
There was a problem hiding this comment.
Better make file name more human-readable. I.e. profilePicFPath + "/" + time.Unix(photo.Date, 0).UTC().Format("2006-01-02_15-04-05Z")
| saver.SaveAccount(*me) | ||
| log.Info("User Account Info Saved") | ||
|
|
||
| tgSaveUserProfilePhotos(tg, *me, saver.profilePicFPath()) |
There was a problem hiding this comment.
There should be a config option for profile pics, so the whole dump could still be text-only. Something like "dump_account_profilepics": true/false and disabled by default.
That way it can also work independently of config.DoAccountDump (i.e. outside that if).
Hello again ;)
To fix this Issue #9 and adding profile picture save feature,
I check duplicate chats while appending and I change pp saving style.
To remind you, this pull request fix both Open Issue and makes unneccessary old pull request #10
I try to watch your comments on old pull request;
Added default WrongRespError to switch case.
Profile pictures saving a new directory to decrease file count in same folder.
Profile pictures saving with timestamps to detect duplicates and skip downloading next time.
Detecting duplicate chats algorithm was so complicated before, I do same thing with few lines of code;
5fdefa4#diff-d794c0fcc1a8766d115416f801ed1ea1b6d31c57acaa1f342c7ed9ac084c287fR212 (Line 212)