diff --git a/mtproto.go b/mtproto.go index 4b9eb167..7b583e7f 100755 --- a/mtproto.go +++ b/mtproto.go @@ -256,7 +256,7 @@ func (m *MTProto) ExportNewSender(dcID int, mem bool) (*MTProto, error) { } sender, _ := NewMTProto(cfg) m.Logger.Info("exporting new sender for DC " + strconv.Itoa(dcID)) - err = sender.CreateConnection(true) + err = sender.CreateConnection(false) if err != nil { return nil, errors.Wrap(err, "creating connection") } @@ -269,6 +269,8 @@ func (m *MTProto) CreateConnection(withLog bool) error { m.stopRoutines = cancelfunc if withLog { m.Logger.Info("Connecting to [" + m.Addr + "] - ...") + } else { + m.Logger.Debug("Connecting to [" + m.Addr + "] - ...") } err := m.connect(ctx) if err != nil { @@ -281,7 +283,14 @@ func (m *MTProto) CreateConnection(withLog bool) error { } else { m.Logger.Info("Connection to [" + m.Addr + "] - established") } + } else { + if m.proxy != nil && m.proxy.Host != "" { + m.Logger.Debug("Connection to (~" + m.proxy.Host + ")[" + m.Addr + "] - established") + } else { + m.Logger.Debug("Connection to [" + m.Addr + "] - established") + } } + m.startReadingResponses(ctx) if !m.encrypted { m.Logger.Debug("authKey not found, creating new one") diff --git a/telegram/const.go b/telegram/const.go index 474fe5f8..1e3e176e 100644 --- a/telegram/const.go +++ b/telegram/const.go @@ -4,7 +4,7 @@ import "regexp" const ( ApiVersion = 181 - Version = "v2.3.11" + Version = "v2.3.12" LogDebug = "debug" LogInfo = "info" diff --git a/telegram/helpers.go b/telegram/helpers.go index ff27676e..5aa7ca68 100644 --- a/telegram/helpers.go +++ b/telegram/helpers.go @@ -602,15 +602,13 @@ func gatherVideoMetadata(path string, attrs []DocumentAttribute) ([]DocumentAttr } lines := strings.Split(strings.TrimSpace(string(out)), "\n") - if len(lines) == 3 { - dur, _ = strconv.ParseFloat(strings.TrimSpace(lines[2]), 64) - width, _ = strconv.ParseInt(strings.TrimSpace(lines[0]), 10, 32) - height, _ = strconv.ParseInt(strings.TrimSpace(lines[1]), 10, 32) - } else { - width, _ = strconv.ParseInt(strings.TrimSpace(lines[0]), 10, 32) - height, _ = strconv.ParseInt(strings.TrimSpace(lines[1]), 10, 32) - if len(lines) > 4 { - dur, _ = strconv.ParseFloat(strings.TrimSpace(lines[4]), 64) + for i, line := range lines { + if i == 0 { + width, _ = strconv.ParseInt(strings.TrimSpace(line), 10, 32) + } else if i == 1 { + height, _ = strconv.ParseInt(strings.TrimSpace(line), 10, 32) + } else if i == len(lines)-1 { + dur, _ = strconv.ParseFloat(strings.TrimSpace(line), 64) } } diff --git a/telegram/media.go b/telegram/media.go index d9778247..dd4bb3ea 100644 --- a/telegram/media.go +++ b/telegram/media.go @@ -106,6 +106,7 @@ func (c *Client) UploadFile(src interface{}, Opts ...*UploadOptions) (InputFile, } } + c.Logger.Debug(fmt.Sprintf("expected workers: %d, preallocated workers: %d", numWorkers, sendersPreallocated)) for i := sendersPreallocated; i < numWorkers; i++ { x, _ := c.CreateExportedSender(c.GetDC()) // go c.AddNewExportedSenderToMap(c.GetDC(), x) TODO: Implement this @@ -130,7 +131,7 @@ func (c *Client) UploadFile(src interface{}, Opts ...*UploadOptions) (InputFile, go func(i int, part []byte, p int) { defer wg.Done() uploadStartPoint: - c.Logger.Debug("Uploading part", p, "with size", len(part), "in KB:", len(part)/1024, "to", i) + c.Logger.Debug(fmt.Sprintf("uploading part %d/%d in chunks of %d", p, totalParts, len(part)/1024)) if !IsFsBig { _, err = sender[i].c.UploadSaveFilePart(fileId, int32(p), part) hash.Write(part) @@ -138,12 +139,8 @@ func (c *Client) UploadFile(src interface{}, Opts ...*UploadOptions) (InputFile, _, err = sender[i].c.UploadSaveBigFilePart(fileId, int32(p), int32(totalParts), part) } if err != nil { - if matchError(err, "FLOOD_WAIT_") { - if waitTime := getFloodWait(err); waitTime > 0 { - c.Logger.Warn("flood wait", waitTime, "seconds, waiting...") - time.Sleep(time.Duration(waitTime) * time.Second) - goto uploadStartPoint - } + if handleIfFlood(err, c) { + goto uploadStartPoint } c.Logger.Error(err) } @@ -170,7 +167,7 @@ func (c *Client) UploadFile(src interface{}, Opts ...*UploadOptions) (InputFile, } lastPartUploadStartPoint: - c.Logger.Debug("Uploading last part", totalParts-1, "with size", len(part), "in KB:", len(part)/1024) + c.Logger.Debug(fmt.Sprintf("uploading last part %d/%d in chunks of %d", totalParts-1, totalParts, len(part)/1024)) if !IsFsBig { _, err = c.UploadSaveFilePart(fileId, int32(totalParts)-1, part) } else { @@ -178,12 +175,8 @@ func (c *Client) UploadFile(src interface{}, Opts ...*UploadOptions) (InputFile, } if err != nil { - if matchError(err, "FLOOD_WAIT_") { - if waitTime := getFloodWait(err); waitTime > 0 { - c.Logger.Warn("flood wait", waitTime, "seconds, waiting...") - time.Sleep(time.Duration(waitTime) * time.Second) - goto lastPartUploadStartPoint - } + if handleIfFlood(err, c) { + goto lastPartUploadStartPoint } c.Logger.Error(err) } @@ -191,8 +184,6 @@ func (c *Client) UploadFile(src interface{}, Opts ...*UploadOptions) (InputFile, if opts.ProgressCallback != nil { go opts.ProgressCallback(int32(totalParts), int32(totalParts)) } - - c.Logger.Debug("Uploaded last part", totalParts-1, "with size", len(part), "in KB:", len(part)/1024) } wg.Wait() @@ -225,6 +216,18 @@ func (c *Client) UploadFile(src interface{}, Opts ...*UploadOptions) (InputFile, }, nil } +func handleIfFlood(err error, c *Client) bool { + if matchError(err, "FLOOD_WAIT_") { + if waitTime := getFloodWait(err); waitTime > 0 { + c.Logger.Warn("flood wait", waitTime, "seconds, waiting...") + time.Sleep(time.Duration(waitTime) * time.Second) + return true + } + } + + return false +} + func prettifyFileName(file string) string { return filepath.Base(file) }