-
-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathutils.go
executable file
·764 lines (684 loc) · 18.2 KB
/
utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
// Copyright (c) 2024 RoseLoverX
package telegram
import (
"encoding/base64"
"encoding/binary"
"fmt"
"math/rand"
"net/http"
"net/url"
"os"
"os/exec"
"path/filepath"
"regexp"
"strconv"
"strings"
"time"
"github.com/amarnathcjd/gogram/internal/utils"
"github.com/pkg/errors"
)
type mimeTypeManager struct {
mimeTypes map[string]string
}
// type ExportedAuthParams struct {
// ID int64
// Bytes []byte
// }
func (m *mimeTypeManager) addMime(ext, mime string) {
m.mimeTypes[ext] = mime
}
func (m *mimeTypeManager) match(filePath string) string {
if IsURL(filePath) {
// do a get request with timeout and get the content type
req, err := http.NewRequest("GET", filePath, nil)
if err != nil {
return ""
}
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 6.1; rv:60.0) Gecko/20100101 Firefox/60.0")
HTTPClient := &http.Client{
Timeout: 4 * time.Second,
}
resp, err := HTTPClient.Do(req)
if err != nil {
return ""
}
defer resp.Body.Close()
if resp.StatusCode == 200 {
if resp.Header.Get("Content-Type") != "" {
return resp.Header.Get("Content-Type")
}
}
return ""
}
if mime, ok := m.mimeTypes[filepath.Ext(filePath)]; ok {
return mime
}
// use http.DetectContentType if no match
file, err := os.Open(filePath)
if err != nil {
return ""
}
defer file.Close()
buffer := make([]byte, 512)
_, err = file.Read(buffer)
if err != nil {
return ""
}
return http.DetectContentType(buffer)
}
func (m *mimeTypeManager) Ext(mime string) string {
for ext, m := range m.mimeTypes {
if m == mime {
return ext
}
}
return ""
}
func (m *mimeTypeManager) IsPhoto(mime string) bool {
return strings.HasPrefix(mime, "image/") && !strings.Contains(mime, "image/webp")
}
func (m *mimeTypeManager) MIME(filePath string) (string, bool) {
mime := m.match(filePath)
return mime, m.IsPhoto(mime)
}
var MimeTypes = &mimeTypeManager{
mimeTypes: make(map[string]string),
}
func init() {
MimeTypes.addMime(".png", "image/png")
MimeTypes.addMime(".jpg", "image/jpeg")
MimeTypes.addMime(".jpeg", "image/jpeg")
MimeTypes.addMime(".webp", "image/webp")
MimeTypes.addMime(".gif", "image/gif")
MimeTypes.addMime(".bmp", "image/bmp")
MimeTypes.addMime(".tga", "image/x-tga")
MimeTypes.addMime(".tiff", "image/tiff")
MimeTypes.addMime(".psd", "image/vnd.adobe.photoshop")
MimeTypes.addMime(".mp4", "video/mp4")
MimeTypes.addMime(".mov", "video/quicktime")
MimeTypes.addMime(".avi", "video/avi")
MimeTypes.addMime(".flv", "video/x-flv")
MimeTypes.addMime(".m4v", "video/x-m4v")
MimeTypes.addMime(".mkv", "video/x-matroska")
MimeTypes.addMime(".webm", "video/webm")
MimeTypes.addMime(".3gp", "video/3gpp")
MimeTypes.addMime(".mp3", "audio/mpeg")
MimeTypes.addMime(".m4a", "audio/m4a")
MimeTypes.addMime(".aac", "audio/aac")
MimeTypes.addMime(".ogg", "audio/ogg")
MimeTypes.addMime(".flac", "audio/x-flac")
MimeTypes.addMime(".opus", "audio/opus")
MimeTypes.addMime(".wav", "audio/wav")
MimeTypes.addMime(".alac", "audio/x-alac")
MimeTypes.addMime(".tgs", "application/x-tgsticker")
}
var (
regexDataCenter = regexp.MustCompile(`DC (\d+)`)
regexCode = regexp.MustCompile(`code (\d+)`)
)
func GetErrorCode(err error) (int, int) {
datacenter := 0
code := 0
if err == nil {
return datacenter, code
}
if regexDataCenter.MatchString(err.Error()) {
datacenter, _ = strconv.Atoi(regexDataCenter.FindStringSubmatch(err.Error())[1])
}
if regexCode.MatchString(err.Error()) {
code, _ = strconv.Atoi(regexCode.FindStringSubmatch(err.Error())[1])
}
return datacenter, code
}
var (
regexFloodWait = regexp.MustCompile(`A wait of (\d+) seconds is required`)
regexFloodWaitBasic = regexp.MustCompile(`FLOOD_WAIT_(\d+)`)
regexFloodWaitPremium = regexp.MustCompile(`FLOOD_PREMIUM_WAIT_(\d+)`)
)
func GetFloodWait(err error) int {
if err == nil {
return 0
}
if regexFloodWait.MatchString(err.Error()) {
wait, _ := strconv.Atoi(regexFloodWait.FindStringSubmatch(err.Error())[1])
return wait
} else if regexFloodWaitBasic.MatchString(err.Error()) {
wait, _ := strconv.Atoi(regexFloodWaitBasic.FindStringSubmatch(err.Error())[1])
return wait
} else if regexFloodWaitPremium.MatchString(err.Error()) {
wait, _ := strconv.Atoi(regexFloodWaitPremium.FindStringSubmatch(err.Error())[1])
return wait
}
return 0
}
func MatchError(err error, str string) bool {
if err != nil {
return strings.Contains(err.Error(), str)
}
return false
}
type FileLocationOptions struct {
ThumbOnly bool
ThumbSize PhotoSize
Video bool
}
// GetFileLocation returns file location, datacenter, file size and file name
func GetFileLocation(file any, opts ...FileLocationOptions) (InputFileLocation, int32, int64, string, error) {
var opt = getVariadic(opts, FileLocationOptions{})
var (
location any
dataCenter int32 = 4
fileSize int64
)
mediaMessageSwitch:
switch f := file.(type) {
case InputFileLocation:
return f, dataCenter, fileSize, "", nil
case UserPhoto:
location, _ = f.InputLocation()
dataCenter = f.DcID()
fileSize = f.FileSize()
case Photo, Document:
location = f
case *MessageMediaDocument:
location = f.Document
case *MessageMediaPhoto:
location = f.Photo
case *NewMessage:
if !f.IsMedia() {
return nil, 0, 0, "", errors.New("message is not media")
}
file = f.Media()
goto mediaMessageSwitch
case *MessageService:
if f.Action != nil {
switch f := f.Action.(type) {
case *MessageActionChatEditPhoto:
location = f.Photo
}
}
case *MessageMediaWebPage:
if f.Webpage != nil {
switch w := f.Webpage.(type) {
case *WebPageObj:
if w.Photo != nil {
location = w.Photo
} else if w.Document != nil {
location = w.Document
}
}
}
default:
return nil, 0, 0, "", errors.New("unsupported file type")
}
switch l := location.(type) {
case *DocumentObj:
if opt.ThumbOnly {
var selectedThumb = l.Thumbs[0]
if opt.ThumbSize != nil {
selectedThumb = opt.ThumbSize
}
size, sizeType := getPhotoSize(selectedThumb)
return &InputDocumentFileLocation{
ID: l.ID,
AccessHash: l.AccessHash,
FileReference: l.FileReference,
ThumbSize: sizeType,
}, l.DcID, size, GetFileName(l), nil
}
return &InputDocumentFileLocation{
ID: l.ID,
AccessHash: l.AccessHash,
FileReference: l.FileReference,
ThumbSize: "",
}, l.DcID, l.Size, GetFileName(l), nil
case *PhotoObj:
if len(l.VideoSizes) > 0 && opt.Video {
var selectedThumb = l.VideoSizes[len(l.VideoSizes)-1]
size, sizeType := getVideoSize(selectedThumb)
return &InputPhotoFileLocation{
ID: l.ID,
AccessHash: l.AccessHash,
FileReference: l.FileReference,
ThumbSize: sizeType,
}, l.DcID, size, GetFileName(l, true), nil
}
var selectedThumb = l.Sizes[len(l.Sizes)-1]
if len(opts) > 0 && opts[0].ThumbOnly {
if opts[0].ThumbSize != nil {
selectedThumb = opts[0].ThumbSize
} else {
selectedThumb = l.Sizes[0]
}
}
size, sizeType := getPhotoSize(selectedThumb)
return &InputPhotoFileLocation{
ID: l.ID,
AccessHash: l.AccessHash,
FileReference: l.FileReference,
ThumbSize: sizeType,
}, l.DcID, size, GetFileName(l), nil
case *InputPhotoFileLocation:
return l, dataCenter, fileSize, "", nil
default:
return nil, 0, 0, "", errors.New("unsupported file type")
}
}
func getPhotoSize(sizes PhotoSize) (int64, string) {
switch s := sizes.(type) {
case *PhotoSizeObj:
return int64(s.Size), s.Type
case *PhotoStrippedSize:
if len(s.Bytes) < 3 || s.Bytes[0] != 1 {
return int64(len(s.Bytes)), s.Type
}
return int64(len(s.Bytes)) + 622, s.Type
case *PhotoCachedSize:
return int64(len(s.Bytes)), s.Type
case *PhotoSizeEmpty:
return 0, s.Type
case *PhotoSizeProgressive:
return int64(getMax(s.Sizes)), s.Type
default:
return 0, "w"
}
}
func getVideoSize(sizes VideoSize) (int64, string) {
switch s := sizes.(type) {
case *VideoSizeObj:
return int64(s.Size), s.Type
}
return 0, ""
}
func getMax(a []int32) int32 {
if len(a) == 0 {
return 0
}
var maximum = a[0]
for _, v := range a {
if v > maximum {
maximum = v
}
}
return maximum
}
func pathIsDir(path string) bool {
return strings.HasSuffix(path, "/") || strings.HasSuffix(path, "\\")
}
func sanitizePath(path string, filename string) string {
if pathIsDir(path) {
return filepath.Join(path, filename)
}
return path
}
// Func to get the file name of Media
//
// Accepted types:
// *MessageMedia
// *Document
// *Photo
func GetFileName(f any, video ...bool) string {
var isVid = getVariadic(video, false)
getDocName := func(doc *DocumentObj) string {
var name string
for _, attr := range doc.Attributes {
switch attr := attr.(type) {
case *DocumentAttributeFilename:
if attr.FileName != "" {
return attr.FileName
}
case *DocumentAttributeAudio:
if attr.Title != "" {
name = attr.Title + ".mp3"
}
case *DocumentAttributeVideo:
name = fmt.Sprintf("video_%s_%d.mp4", time.Now().Format("2006-01-02_15-04-05"), rand.Intn(1000))
case *DocumentAttributeAnimated:
name = fmt.Sprintf("animation_%s_%d.gif", time.Now().Format("2006-01-02_15-04-05"), rand.Intn(1000))
case *DocumentAttributeSticker:
return fmt.Sprintf("sticker_%s_%d.webp", time.Now().Format("2006-01-02_15-04-05"), rand.Intn(1000))
}
}
if name != "" {
return name
}
if doc.MimeType != "" {
return fmt.Sprintf("file_%s_%d%s", time.Now().Format("2006-01-02_15-04-05"), rand.Intn(1000), MimeTypes.Ext(doc.MimeType))
}
return fmt.Sprintf("file_%s_%d", time.Now().Format("2006-01-02_15-04-05"), rand.Intn(1000))
}
switch f := f.(type) {
case *MessageMediaDocument:
return getDocName(f.Document.(*DocumentObj))
case *MessageMediaPhoto:
if isVid {
return fmt.Sprintf("video_%s_%d.mp4", time.Now().Format("2006-01-02_15-04-05"), rand.Intn(1000))
}
return fmt.Sprintf("photo_%s_%d.jpg", time.Now().Format("2006-01-02_15-04-05"), rand.Intn(1000))
case *MessageMediaContact:
return fmt.Sprintf("contact_%s_%d.vcf", f.FirstName, rand.Intn(1000))
case *DocumentObj:
return getDocName(f)
case *PhotoObj:
if isVid {
return fmt.Sprintf("video_%s_%d.mp4", time.Now().Format("2006-01-02_15-04-05"), rand.Intn(1000))
}
return fmt.Sprintf("photo_%s_%d.jpg", time.Now().Format("2006-01-02_15-04-05"), rand.Intn(1000))
case *InputPeerPhotoFileLocation:
return fmt.Sprintf("profile_photo_%s_%d.jpg", time.Now().Format("2006-01-02_15-04-05"), rand.Intn(1000))
case *InputPhotoFileLocation:
return fmt.Sprintf("photo_file_%s_%d.jpg", time.Now().Format("2006-01-02_15-04-05"), rand.Intn(1000))
default:
return fmt.Sprintf("file_%s_%d", time.Now().Format("2006-01-02_15-04-05"), rand.Intn(1000))
}
}
// Func to get the file size of Media
//
// Accepted types:
// *MessageMedia
func getFileSize(f any) int64 {
switch f := f.(type) {
case *MessageMediaDocument:
return f.Document.(*DocumentObj).Size
case *MessageMediaPhoto:
if photo, p := f.Photo.(*PhotoObj); p {
if len(photo.Sizes) == 0 {
return 0
}
s, _ := getPhotoSize(photo.Sizes[len(photo.Sizes)-1])
return s
} else {
return 0
}
default:
return 0
}
}
// Func to get the file extension of Media
//
// Accepted types:
// *MessageMedia
// *Document
// *Photo
func getFileExt(f any) string {
switch f := f.(type) {
case *MessageMediaDocument:
doc := f.Document.(*DocumentObj)
if e := MimeTypes.Ext(doc.MimeType); e != "" {
return e
}
for _, attr := range doc.Attributes {
switch attr.(type) {
case *DocumentAttributeAudio:
return ".mp3"
case *DocumentAttributeVideo:
return ".mp4"
case *DocumentAttributeAnimated:
return ".gif"
case *DocumentAttributeSticker:
return ".webp"
}
}
case *MessageMediaPhoto:
return ".jpg"
case *MessageMediaContact:
return ".vcf"
case *DocumentObj:
for _, attr := range f.Attributes {
switch attr := attr.(type) {
case *DocumentAttributeFilename:
return filepath.Ext(attr.FileName)
case *DocumentAttributeAudio:
return ".mp3"
case *DocumentAttributeVideo:
return ".mp4"
case *DocumentAttributeAnimated:
return ".gif"
case *DocumentAttributeSticker:
return ".webp"
}
}
return ".file"
case *PhotoObj:
return ".jpg"
case *InputPeerPhotoFileLocation:
return ".jpg"
}
return ""
}
func GenerateRandomLong() int64 {
return int64(rand.Int31())<<32 | int64(rand.Int31())
}
func getPeerUser(userID int64) *PeerUser {
return &PeerUser{
UserID: userID,
}
}
func getLogPrefix(loggerName string, sessionName string) string {
if sessionName == "" {
return fmt.Sprintf("[%s]", loggerName)
}
return fmt.Sprintf("[%s] {%s}", loggerName, sessionName)
}
func IsURL(str string) bool {
u, err := url.Parse(str)
return err == nil && u.Scheme != "" && u.Host != ""
}
var regexPhone = regexp.MustCompile(`^\+?[0-9]{10,13}$`)
func IsPhone(phone string) bool {
return regexPhone.MatchString(phone)
}
func getValue[T comparable](val, def T) T {
var zero T
if val == zero {
return def
}
return val
}
func getValueSlice[T any](val, def []T) []T {
if val == nil {
return def
}
return val
}
func getValueAny(val, def any) any {
if val == nil {
return def
}
return val
}
type Number interface {
int | int8 | int16 | int32 | int64 | uint | uint8 | uint16 | uint32 | uint64 | float32 | float64
}
func convertSlice[T2 Number, T1 Number](t1 []T1) []T2 {
t2 := make([]T2, len(t1))
for i := range t1 {
t2[i] = T2(t1[i])
}
return t2
}
func parseInt32(a any) int32 {
switch a := a.(type) {
case int32:
return a
case int:
return int32(a)
case int64:
return int32(a)
default:
return 0
}
}
func getInlineDocumentType(mimeType string, voiceNote bool) string {
if voiceNote {
return "voice"
}
switch mimeType {
case "audio/mp3", "audio/mpeg", "audio/ogg", "audio/x-flac", "audio/x-alac", "audio/x-wav", "audio/x-m4a", "audio/aac", "audio/opus":
return "audio"
case "image/gif":
return "gif"
case "image/jpeg", "image/png":
return "photo"
case "image/webp", "application/x-tgsticker":
return "sticker"
case "video/mp4", "video/x-matroksa", "video/webm":
return "video"
default:
return "file"
}
}
func SizetoHuman(size int64) string {
if size < 1024 {
return fmt.Sprintf("%d B", size)
} else if size < 1024*1024 {
return fmt.Sprintf("%.2f KB", float64(size)/1024)
} else if size < 1024*1024*1024 {
return fmt.Sprintf("%.2f MB", float64(size)/1024/1024)
} else {
return fmt.Sprintf("%.2f GB", float64(size)/1024/1024/1024)
}
}
// PackBotFileID packs a file object to a file-id
func PackBotFileID(file any) string {
var (
fID, accessHash int64
fileType, dcID int32
)
switchFileType:
switch f := file.(type) {
case *DocumentObj:
fID = f.ID
accessHash = f.AccessHash
fileType = 5
dcID = f.DcID
for _, attr := range f.Attributes {
switch attr := attr.(type) {
case *DocumentAttributeAudio:
if attr.Voice {
fileType = 3
break switchFileType
}
fileType = 9
break switchFileType
case *DocumentAttributeVideo:
if attr.RoundMessage {
fileType = 13
break switchFileType
}
fileType = 4
break switchFileType
case *DocumentAttributeSticker:
fileType = 8
break switchFileType
case *DocumentAttributeAnimated:
fileType = 10
break switchFileType
}
}
case *PhotoObj:
fID = f.ID
accessHash = f.AccessHash
fileType = 2
dcID = f.DcID
case *MessageMediaDocument:
file = f.Document
goto switchFileType
case *MessageMediaPhoto:
file = f.Photo
goto switchFileType
default:
return ""
}
if fID == 0 || accessHash == 0 || fileType == 0 || dcID == 0 {
return ""
}
buf := make([]byte, 4+8+8)
binary.LittleEndian.PutUint32(buf[0:], uint32(fileType)|uint32(dcID)<<24)
binary.LittleEndian.PutUint64(buf[4:], uint64(fID))
binary.LittleEndian.PutUint64(buf[4+8:], uint64(accessHash))
return base64.RawURLEncoding.EncodeToString(buf)
}
// UnpackBotFileID unpacks a file id to its components
func UnpackBotFileID(fileID string) (int64, int64, int32, int32) {
data, err := base64.RawURLEncoding.DecodeString(fileID)
if err != nil {
return 0, 0, 0, 0
}
if len(data) == 20 {
tmp := binary.LittleEndian.Uint32(data[0:])
fileType := int32(tmp & 0x00FFFFFF)
dcID := int32((tmp >> 24) & 0xFF)
fID := int64(binary.LittleEndian.Uint64(data[4:]))
accessHash := int64(binary.LittleEndian.Uint64(data[4+8:]))
return fID, accessHash, fileType, dcID
}
// Compatibility with old file ids
if parts := strings.SplitN(string(data), "_", 4); len(parts) == 4 {
fileType, _ := strconv.Atoi(parts[0])
dcID, _ := strconv.Atoi(parts[1])
fID, _ := strconv.ParseInt(parts[2], 10, 64)
accessHash, _ := strconv.ParseInt(parts[3], 10, 64)
return fID, accessHash, int32(fileType), int32(dcID)
}
return 0, 0, 0, 0
}
// ResolveBotFileID resolves a file id to a MessageMedia object
func ResolveBotFileID(fileId string) (MessageMedia, error) {
fID, accessHash, fileType, dcID := UnpackBotFileID(fileId)
if fID == 0 || accessHash == 0 || fileType == 0 || dcID == 0 {
return nil, errors.New("failed to resolve file id: unrecognized format")
}
switch fileType {
case 2:
return &MessageMediaPhoto{
Photo: &PhotoObj{
ID: fID,
AccessHash: accessHash,
DcID: dcID,
},
}, nil
case 3, 4, 5, 8, 9, 10, 13:
var attributes = []DocumentAttribute{}
switch fileType {
case 3:
attributes = append(attributes, &DocumentAttributeAudio{
Voice: true,
})
case 4:
attributes = append(attributes, &DocumentAttributeVideo{
RoundMessage: false,
})
case 8:
attributes = append(attributes, &DocumentAttributeSticker{})
case 9:
attributes = append(attributes, &DocumentAttributeAudio{})
case 10:
attributes = append(attributes, &DocumentAttributeAnimated{})
case 13:
attributes = append(attributes, &DocumentAttributeVideo{
RoundMessage: true,
})
}
return &MessageMediaDocument{
Document: &DocumentObj{
ID: fID,
AccessHash: accessHash,
DcID: dcID,
Attributes: attributes,
},
}, nil
}
return nil, errors.New("failed to resolve file id: unknown file type")
}
func doesSessionFileExist(filePath string) bool {
_, ol := os.Stat(filePath)
return !os.IsNotExist(ol)
}
func IsFfmpegInstalled() bool {
_, err := exec.LookPath("ffmpeg")
return err == nil
}
func NewLogger(level utils.LogLevel, prefix ...string) *utils.Logger {
return utils.NewLogger(getVariadic(prefix, "gogram")).SetLevel(level)
}