Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions internal/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,15 @@ func parseScriptData(scriptData [][]byte, keyPattern, valuePattern *regexp.Regex
keyData := keyPattern.Find(data)
valueData := valuePattern.Find(data)

parsed = append(parsed, keyPattern.ReplaceAll(keyData, []byte(`"$key":`))...)
parsed = append(parsed, valuePattern.ReplaceAll(valueData, []byte(`$value`))...)
keyDataReplaced := keyPattern.ReplaceAll(keyData, []byte(`"$key":`))
valueDataReplaced := valuePattern.ReplaceAll(valueData, []byte(`$value`))

if len(keyDataReplaced) == 0 || len(valueDataReplaced) == 0 {
continue
}

parsed = append(parsed, keyDataReplaced...)
parsed = append(parsed, valueDataReplaced...)

if idx < len(scriptData)-1 {
parsed = append(parsed, []byte(`,`)...)
Expand Down
22 changes: 22 additions & 0 deletions internal/scraper/app_method.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"context"
"fmt"
"net/url"
"strconv"
"strings"

"github.com/bots-house/google-play-parser/internal/parser"
Expand Down Expand Up @@ -41,7 +42,28 @@
}

app.Developer = strings.Split(app.Developer, "id=")[1]
app = checkDeveloperName(ctx, client, app)
app.Unquote()

return app.Assign(&models.App{AppID: spec.AppID, URL: requestURL}), nil
}

func checkDeveloperName(ctx context.Context, client sh.HTTPClient, app models.App) models.App {

Check failure on line 51 in internal/scraper/app_method.go

View workflow job for this annotation

GitHub Actions / Lint

hugeParam: app is heavy (681 bytes); consider passing it by pointer (gocritic)
name := app.Developer
if _, err := strconv.ParseInt(name, 10, strconv.IntSize); err != nil {
return app
}

devApps, err := Developer(ctx, client, models.DeveloperSpec{DevID: app.DeveloperID})
if err != nil {
return app
}

if len(devApps) == 0 {
return app
}

app.Developer = devApps[0].Developer

return app
}
3 changes: 3 additions & 0 deletions models/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package models
import (
"fmt"
"net/url"
"strings"

"github.com/bots-house/google-play-parser/internal/shared"
)
Expand Down Expand Up @@ -74,6 +75,8 @@ func (app *App) Unquote() {
developerID = app.DeveloperID
}

developer = strings.ReplaceAll(developer, "+", " ")

app.Developer = developer
app.DeveloperID = developerID
}
Expand Down
35 changes: 35 additions & 0 deletions scrapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"math/rand"
"net/url"
"strconv"
"strings"
"testing"

Expand Down Expand Up @@ -292,3 +293,37 @@ func Test_InAppPurchases(t *testing.T) {
assert.Equal(t, test.inAppPurchase, app.InAppPurchase)
}
}

func TestMissingDeveloperNames(t *testing.T) {
c := New()

tests := []struct {
id string
}{
{
id: "com.particlenews.newsbreak",
},

{
id: "com.xphotokit.chatgptassist",
},

{
id: "com.newleaf.app.android.victor",
},
}

for _, test := range tests {
t.Run(test.id, func(t *testing.T) {
app, err := c.App(context.Background(), ApplicationSpec{AppID: test.id})
if err != nil {
t.Error(err)
return
}

if _, err := strconv.ParseInt(app.Developer, 10, strconv.IntSize); err == nil {
t.Error("developer name is id")
}
})
}
}
Loading