Skip to content
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

bug:Unflexible TUFilm Parser #268

Merged
merged 17 commits into from
Oct 30, 2023
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ The following environment variables need to be set for the server to work proper
* [REQUIRED] `DB_ROOT_PASSWORD`: The password of the root user.
* [OPTIONAL] `DB_PORT`: The port of the database server. Defaults to `3306`.
* [OPTIONAL] `SENTRY_DSN`: The Sentry [Data Source Name](https://sentry-docs-git-patch-1.sentry.dev/product/sentry-basics/dsn-explainer/) for reporting issues and crashes.
* [OPTIONAL] `OMDB_API_KEY`: The key to get more information for tu-film movies from [omdbapi](https://omdbapi.com/). See [omdbapi](https://omdbapi.com/apikey.aspx) for a key.
* **[iOS Push Notification Service [OPTIONAL]](#ios-push-notifications-service)**:
* [REQUIRED] `APNS_KEY_ID`: The key ID of the APNs key => APNs Key needs to be downloaded from the Apple Developer Portal the name of the file also contains the key ID.
* [REQUIRED] `APNS_TEAM_ID`: The team ID of the iOS app can be found in AppStoreConnect.
Expand Down
670 changes: 352 additions & 318 deletions server/api/tumdev/campus_backend.pb.go

Large diffs are not rendered by default.

27 changes: 20 additions & 7 deletions server/api/tumdev/campus_backend.proto
Original file line number Diff line number Diff line change
Expand Up @@ -487,25 +487,38 @@ message ListMoviesReply {
}

message Movie {
reserved /*string cover_name = */ 1;
reserved /*string cover_path =*/ 2;
// the id of the movie
int64 movie_id = 3;
// the date of the movie
google.protobuf.Timestamp date = 4;
// when the movie was created in OUR database
google.protobuf.Timestamp created = 5;
// title of the movie if available, empty otherwise
string title = 6;
// release year of the movie
// Where the movie is shown
string location = 18;
// release year of the movie if available, empty otherwise
string release_year = 7;
// runtime of the movie if available, empty otherwise
string runtime = 8;
// genre of the movie if available, empty otherwise
string genre = 9;
// director of the movie as by omdb(/tu-film), empty otherwise
string director = 10;
// actors of the movie as by omdb(/tu-film), empty otherwise
string actors = 11;
// imdb rating
// imdb rating for the movie if available, empty otherwise
string imdb_rating = 12;
// short description of the movie including limited html tags (only <b>, <i>)
string description = 13;
int64 cover_id = 14;
reserved /*string trailer*/ 15;
// Where to find a trailer for this movie
string trailer_url = 15;
// Where to find additional information about this movie
string link = 16;
string additional_information_url = 16;

reserved /*cover_name,cover_path = */ 1, 2;
// the id of the cover image
int64 cover_id = 14;
// Where to find a cover image for this movie
string cover_url = 17;
}
Expand Down
46 changes: 32 additions & 14 deletions server/api/tumdev/campus_backend.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1483,50 +1483,68 @@
"properties": {
"movieId": {
"type": "string",
"format": "int64"
"format": "int64",
"title": "the id of the movie"
},
"date": {
"type": "string",
"format": "date-time"
"format": "date-time",
"title": "the date of the movie"
},
"created": {
"type": "string",
"format": "date-time"
"format": "date-time",
"title": "when the movie was created in OUR database"
},
"title": {
"type": "string"
"type": "string",
"title": "title of the movie if available, empty otherwise"
},
"location": {
"type": "string",
"title": "Where the movie is shown"
},
"releaseYear": {
"type": "string",
"title": "release year of the movie"
"title": "release year of the movie if available, empty otherwise"
},
"runtime": {
"type": "string"
"type": "string",
"title": "runtime of the movie if available, empty otherwise"
},
"genre": {
"type": "string"
"type": "string",
"title": "genre of the movie if available, empty otherwise"
},
"director": {
"type": "string"
"type": "string",
"title": "director of the movie as by omdb(/tu-film), empty otherwise"
},
"actors": {
"type": "string"
"type": "string",
"title": "actors of the movie as by omdb(/tu-film), empty otherwise"
},
"imdbRating": {
"type": "string",
"title": "imdb rating"
"title": "imdb rating for the movie if available, empty otherwise"
},
"description": {
"type": "string"
"type": "string",
"title": "short description of the movie including limited html tags (only \u003cb\u003e, \u003ci\u003e)"
},
"coverId": {
"trailerUrl": {
"type": "string",
"format": "int64"
"title": "Where to find a trailer for this movie"
},
"link": {
"additionalInformationUrl": {
"type": "string",
"title": "Where to find additional information about this movie"
},
"coverId": {
"type": "string",
"format": "int64",
"title": "the id of the cover image"
},
"coverUrl": {
"type": "string",
"title": "Where to find a cover image for this movie"
Expand Down
60 changes: 60 additions & 0 deletions server/backend/cron/movie_parsers/omdb.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package movie_parsers

import (
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
"os"

log "github.com/sirupsen/logrus"
)

type OmdbResults struct {
ReleaseYear string `json:"Year"`
Runtime string
Genre string
Director string
Actors string
Plot string
ImdbRating string `json:"imdbRating"`
}

func GetOmdbMovie(id string) (*OmdbResults, error) {
url := fmt.Sprintf("https://www.omdbapi.com/?r=json&v=1&i=%s&apikey=%s", id, os.Getenv("OMDB_API_KEY"))
resp, err := http.Get(url)
if err != nil {
log.WithField("url", url).WithError(err).Error("Error while getting response for request")
return nil, err
}
// check if the api key is valid
if resp.StatusCode == http.StatusUnauthorized {
return nil, errors.New("missing or invalid api key for omdb (environment variable OMDB_API_KEY)")
}
// other errors
if resp.StatusCode != http.StatusOK {
body, err := io.ReadAll(resp.Body)
if err != nil {
log.WithError(err).Warn("Unable to read http body")
return nil, err
} else {
log.WithField("status", resp.StatusCode).WithField("status", resp.Status).WithField("body", string(body)).Error("error while getting omdb movie")
return nil, errors.New("error while getting omdb movie")
}
}
defer func(Body io.ReadCloser) {
err := Body.Close()
if err != nil {
log.WithField("url", url).WithError(err).Error("Error while closing body")
}
}(resp.Body)
// parse the response body
var res OmdbResults
err = json.NewDecoder(resp.Body).Decode(&res)
if err != nil {
log.WithField("url", url).WithError(err).Error("Error while unmarshalling omdbResults")
return nil, err
}
return &res, nil
}
Loading