From b00e24efc4eae99ff09081f3d29c2784de095942 Mon Sep 17 00:00:00 2001 From: Rogee Date: Mon, 2 Sep 2024 11:39:47 +0800 Subject: [PATCH] add exporter offset --- internal/client.go | 15 +++++++++++---- internal/client_print_channels.go | 20 -------------------- internal/cmd_export.go | 15 ++++++++++++--- 3 files changed, 23 insertions(+), 27 deletions(-) delete mode 100644 internal/client_print_channels.go diff --git a/internal/client.go b/internal/client.go index f1fe1c2..76d070b 100644 --- a/internal/client.go +++ b/internal/client.go @@ -22,6 +22,8 @@ type TClient struct { logger *zap.Logger api *tg.Client + downloadMedia bool + waitLogin chan error block chan struct{} } @@ -45,6 +47,11 @@ func NewClient(config *config.Config) *TClient { return c } +func (t *TClient) WithMedia() *TClient { + t.downloadMedia = true + return t +} + // func (t *TClient) Run(ctx context.Context) { // err := t.Client.Run(ctx, func(ctx context.Context) error { // flow := auth.NewFlow(Terminal{PhoneNumber: t.Config.Phone}, auth.SendCodeOptions{}) @@ -135,6 +142,10 @@ func (t *TClient) Channel(ctx context.Context, channel *tg.Channel, offset int) return } + if !t.downloadMedia { + return + } + if mediaClass, ok := msg.GetMedia(); ok { if photoClass, ok := mediaClass.(*tg.MessageMediaPhoto).GetPhoto(); ok { photo := photoClass.(*tg.Photo) @@ -161,10 +172,6 @@ func (t *TClient) Channel(ctx context.Context, channel *tg.Channel, offset int) } } } - - fmt.Println("") - fmt.Println("------------------------------------------------------------------------------------------------------") - fmt.Println("") }) return nil diff --git a/internal/client_print_channels.go b/internal/client_print_channels.go deleted file mode 100644 index 87c9ecc..0000000 --- a/internal/client_print_channels.go +++ /dev/null @@ -1,20 +0,0 @@ -package internal - -import ( - "context" - - "github.com/gotd/td/tg" - "github.com/pkg/errors" -) - -func (t *TClient) PrintChannels(ctx context.Context) error { - channels, err := t.Client.API().ChannelsGetChannels(context.Background(), []tg.InputChannelClass{ - &tg.InputChannelEmpty{}, - }) - if err != nil { - return errors.Wrap(err, "failed to get channels") - } - _ = channels - - return nil -} diff --git a/internal/cmd_export.go b/internal/cmd_export.go index 3809748..eefec1c 100644 --- a/internal/cmd_export.go +++ b/internal/cmd_export.go @@ -9,8 +9,10 @@ import ( ) var ( - channelID int64 - channelAlias string + channelID int64 + offsetID int + channelAlias string + downloadMedia bool ) func ExportCmd() *cobra.Command { @@ -35,12 +37,19 @@ func ExportCmd() *cobra.Command { return err } } - return client.Channel(ctx, channel, 0) + + if downloadMedia { + client.WithMedia() + } + + return client.Channel(ctx, channel, offsetID) }), } cmd.Flags().Int64Var(&channelID, "channel", 0, "channel id") + cmd.Flags().IntVar(&offsetID, "offset", 0, "offset id") cmd.Flags().StringVar(&channelAlias, "alias", "", "channel alias") + cmd.Flags().BoolVar(&downloadMedia, "media", false, "download media") return cmd }