2023-01-04 16:21:00 +00:00
|
|
|
package instagram
|
2023-01-03 02:30:01 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
2023-01-04 16:36:25 +00:00
|
|
|
"net/http"
|
2023-01-03 02:30:01 +00:00
|
|
|
"net/url"
|
2023-01-03 02:45:37 +00:00
|
|
|
"strings"
|
2023-01-03 02:30:01 +00:00
|
|
|
|
|
|
|
"nulo.in/dlbot/common"
|
|
|
|
)
|
|
|
|
|
2023-01-04 16:36:25 +00:00
|
|
|
type Instagram struct {
|
|
|
|
http.Client
|
|
|
|
}
|
|
|
|
|
|
|
|
var Responder *Instagram = &Instagram{}
|
|
|
|
|
2023-01-04 16:53:23 +00:00
|
|
|
func (r *Instagram) Respond(url *url.URL) (*common.Uploadable, common.Error) {
|
2023-01-03 02:30:01 +00:00
|
|
|
if url.Hostname() != "instagram.com" && url.Hostname() != "www.instagram.com" {
|
2023-01-04 16:53:23 +00:00
|
|
|
return nil, common.NotValid
|
2023-01-03 02:30:01 +00:00
|
|
|
}
|
2023-08-08 18:06:12 +00:00
|
|
|
if strings.Index(url.Path, "/reel/") != 0 && strings.Index(url.Path, "/p/") != 0 {
|
2023-01-04 16:53:23 +00:00
|
|
|
return nil, common.NotValid
|
2023-01-03 02:45:37 +00:00
|
|
|
}
|
2023-01-03 02:30:01 +00:00
|
|
|
|
2023-01-04 16:36:25 +00:00
|
|
|
lookup, err := r.lookup(url.String())
|
2023-01-03 02:30:01 +00:00
|
|
|
if err != nil {
|
2023-01-03 02:45:46 +00:00
|
|
|
log.Println(err)
|
2023-09-05 19:11:27 +00:00
|
|
|
if strings.Index(url.Path, "/p/") == 0 {
|
2023-08-13 17:09:58 +00:00
|
|
|
return nil, common.NotValid
|
|
|
|
}
|
2023-01-04 16:53:23 +00:00
|
|
|
return nil, common.HadError
|
2023-01-03 02:30:01 +00:00
|
|
|
}
|
|
|
|
|
2023-01-04 16:53:23 +00:00
|
|
|
return &common.Uploadable{
|
|
|
|
Url: lookup.VideoUrl,
|
2023-01-04 16:53:48 +00:00
|
|
|
Caption: "instagram.com/" + lookup.Author,
|
2023-01-04 16:53:23 +00:00
|
|
|
}, common.OK
|
2023-01-03 02:30:01 +00:00
|
|
|
}
|