Skip to content

Commit

Permalink
Add support for new /share/ shortened url
Browse files Browse the repository at this point in the history
  • Loading branch information
Wikidepia committed Dec 18, 2024
1 parent 86fb56a commit 2627731
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion handlers/scraper/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"log/slog"
"net/http"
"net/url"
"path"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -63,10 +64,28 @@ func init() {
}

func GetData(postID string) (*InstaData, error) {
if len(postID) == 0 || (postID[0] != 'C' && postID[0] != 'D') {
if len(postID) == 0 || (postID[0] != 'C' && postID[0] != 'D' && postID[0] != 'B') {
return nil, errors.New("postID is not a valid Instagram post ID")
}

// Shortened postID
if postID[0] == 'B' {
req, err := http.NewRequest("HEAD", "https://www.instagram.com/share/reel/"+postID+"/", nil)
if err != nil {
return nil, err
}
resp, err := http.DefaultTransport.RoundTrip(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
redirURL, err := url.Parse(resp.Header.Get("Location"))
if err != nil {
return nil, err
}
postID = path.Base(redirURL.Path)
}

i := &InstaData{PostID: postID}
err := DB.View(func(tx *bolt.Tx) error {
b := tx.Bucket([]byte("data"))
Expand Down

0 comments on commit 2627731

Please sign in to comment.