Skip to content

Set UA as Apple Podcast in makeQuery #310

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
45 changes: 34 additions & 11 deletions service/podcastService.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ import (
)

var Logger *zap.SugaredLogger
var (
ErrInvalidContentType = errors.New("invalid content type: expected RSS/XML but got HTML")
ErrEmptyResponse = errors.New("empty response from server")
)

func init() {
zapper, _ := zap.NewProduction()
Expand All @@ -35,12 +39,12 @@ func ParseOpml(content string) (model.OpmlModel, error) {
return response, err
}

//FetchURL is
func FetchURL(url string) (model.PodcastData, []byte, error) {
body, err := makeQuery(url)
if err != nil {
return model.PodcastData{}, nil, err
}

var response model.PodcastData
err = xml.Unmarshal(body, &response)
return response, body, err
Expand Down Expand Up @@ -706,27 +710,46 @@ func DeleteTag(id string) error {
return nil

}

func makeQuery(url string) ([]byte, error) {
//link := "https://www.goodreads.com/search/index.xml?q=Good%27s+Omens&key=" + "jCmNlIXjz29GoB8wYsrd0w"
//link := "https://www.goodreads.com/search/index.xml?key=jCmNlIXjz29GoB8wYsrd0w&q=Ender%27s+Game"
fmt.Println(url)
// Create HTTP client with timeout
client := &http.Client{
Timeout: 30 * time.Second,
}

// Create request
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return nil, err
return nil, fmt.Errorf("error creating request: %w", err)
}

resp, err := http.DefaultClient.Do(req)
// Set headers to mimic apple podcast app
req.Header.Set("User-Agent", "AppleCoreMedia/1.0.0.22B82 (iPhone; U; CPU OS 18_1 like Mac OS X; en_us)")
req.Header.Set("Accept", "*/*")
// Some feeds might require these additional headers
req.Header.Set("Accept-Encoding", "gzip, deflate")
req.Header.Set("Connection", "keep-alive")
// Prevent servers from sending compressed content we can't handle
req.Header.Del("Accept-Encoding")

// Make the request
resp, err := client.Do(req)
if err != nil {
return nil, err
return nil, fmt.Errorf("error making request: %w", err)
}

defer resp.Body.Close()
fmt.Println("Response status:", resp.Status)

// Read response body
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("error reading response: %w", err)
}

return body, nil
// Check if response is empty
if len(body) == 0 {
return nil, ErrEmptyResponse
}

return body, nil
}
func GetSearchFromGpodder(pod model.GPodcast) *model.CommonSearchResultModel {
p := new(model.CommonSearchResultModel)
Expand Down