diff --git a/internal/parser/parser.go b/internal/parser/parser.go index 8ebbf4a..ff3de15 100644 --- a/internal/parser/parser.go +++ b/internal/parser/parser.go @@ -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(`,`)...) diff --git a/internal/scraper/app_method.go b/internal/scraper/app_method.go index d7cf90a..411cc7d 100644 --- a/internal/scraper/app_method.go +++ b/internal/scraper/app_method.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "net/url" + "strconv" "strings" "github.com/bots-house/google-play-parser/internal/parser" @@ -41,7 +42,28 @@ func App(ctx context.Context, client sh.HTTPClient, spec models.ApplicationSpec) } 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 { + 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 +} diff --git a/models/app.go b/models/app.go index 2838213..9f363b6 100644 --- a/models/app.go +++ b/models/app.go @@ -3,6 +3,7 @@ package models import ( "fmt" "net/url" + "strings" "github.com/bots-house/google-play-parser/internal/shared" ) @@ -74,6 +75,8 @@ func (app *App) Unquote() { developerID = app.DeveloperID } + developer = strings.ReplaceAll(developer, "+", " ") + app.Developer = developer app.DeveloperID = developerID } diff --git a/scrapper_test.go b/scrapper_test.go index c26126b..7bbbc55 100644 --- a/scrapper_test.go +++ b/scrapper_test.go @@ -5,6 +5,7 @@ import ( "fmt" "math/rand" "net/url" + "strconv" "strings" "testing" @@ -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") + } + }) + } +}