From 689a204f384e9064a60a195ea19b3db9d6dd04e7 Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Wed, 1 Nov 2023 01:50:11 +0100 Subject: [PATCH] made sure that the tu film does download only the bigger resolution images --- server/backend/cron/movie_parsers/tufilm.go | 4 +++- server/backend/cron/movie_parsers/tufilm_test.go | 8 ++++---- server/backend/cron/movies.go | 11 ++++++++--- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/server/backend/cron/movie_parsers/tufilm.go b/server/backend/cron/movie_parsers/tufilm.go index 0024fdc8..5daee1d4 100644 --- a/server/backend/cron/movie_parsers/tufilm.go +++ b/server/backend/cron/movie_parsers/tufilm.go @@ -136,9 +136,11 @@ func parseShortenedDescription(doc *goquery.Document) string { func parseImageUrl(doc *goquery.Document) string { href, exists := doc.Find("img.poster").First().Attr("src") if !exists { - return "https://www.tu-film.de/img/film/poster/.sized.berraschungsfilm.jpg" + return "https://www.tu-film.de/img/film/poster/berraschungsfilm.jpg" } sanitisedHref := bluemonday.StrictPolicy().Sanitize(href) + sanitisedHref = strings.ReplaceAll(sanitisedHref, "/img/film/poster/.sized.", "/img/film/poster/") + sanitisedHref = strings.ReplaceAll(sanitisedHref, "/img/film/poster/.thumb.", "/img/film/poster/") return "https://www.tu-film.de" + sanitisedHref } diff --git a/server/backend/cron/movie_parsers/tufilm_test.go b/server/backend/cron/movie_parsers/tufilm_test.go index ee30dc81..27d27a8a 100644 --- a/server/backend/cron/movie_parsers/tufilm_test.go +++ b/server/backend/cron/movie_parsers/tufilm_test.go @@ -29,7 +29,7 @@ func TestOppenheimer(t *testing.T) { "In the further course of the film Lewis Strauss is to be confirmed as Secretary of Commerce in the cabinet of President Dwight D. Eisenhower. Soon it is also about his relations with Oppenheimer after the war, to whom he was superior as head of the Atomic Energy Authority. Thereby it concerns above all the reproaches to old connection to the communism which Oppenheimer is accused of." comment := "An intellectual thriller that is a masterpiece of image and word, of complex ideas made manifest, and all kept at a very human level to maintain constant immediacy. (Andrea Chase, Killer Movie Reviews)" expected := TuFilmWebsiteInformation{ - ImageUrl: "https://www.tu-film.de/img/film/poster/.sized.Oppenheimer.jpg", + ImageUrl: "https://www.tu-film.de/img/film/poster/Oppenheimer.jpg", ShortenedDescription: fmt.Sprintf("%s\n\n%s\n\n%s", header, description, comment), Director: null.StringFrom("Christopher Nolan"), Actors: null.StringFrom("Cillian Murphy, Emily Blunt, Matt Damon"), @@ -52,7 +52,7 @@ func TestBabylon(t *testing.T) { "In the end, there is one thing Hollywood does best: Make movies about themselves. Did they forget to mention that these movies were made for nazi germany? Is all this crime and perversion really ok because the movies are just that good? Don't think about it too much, you will still enjoy it." comment := "Chazelle’s film commemorates the era’s hubris as it indulges in a bit of its own. This is how a world ends. Not with a whimper but a great deal of banging, baby. And vomiting. And snorting. (Irish Times)" expected := TuFilmWebsiteInformation{ - ImageUrl: "https://www.tu-film.de/img/film/poster/.sized.Babylon.jpg", + ImageUrl: "https://www.tu-film.de/img/film/poster/Babylon.jpg", ShortenedDescription: fmt.Sprintf("%s\n\n%s\n\n%s", header, description, comment), Director: null.StringFrom("Damien Chazelle"), Actors: null.StringFrom("Brad Pitt, Margot Robbie, Jean Smart"), @@ -74,7 +74,7 @@ func TestSurpriseFilm(t *testing.T) { "Seid also gespannt, welche Perle wir für euch aus dem Zauberhut ziehen! Der Film wird zwei Wochen davor über unsere üblichen Informationskanäle bekannt gegeben.\n" + "Habt ihr Meinungen dazu? Dann lasst es uns wissen und schreibt uns an ueberraschungsfilm@tu-film.de" expected := TuFilmWebsiteInformation{ - ImageUrl: "https://www.tu-film.de/img/film/poster/.sized.berraschungsfilm.jpg", + ImageUrl: "https://www.tu-film.de/img/film/poster/berraschungsfilm.jpg", ShortenedDescription: fmt.Sprintf("%s\n\n%s", header, description), } info, err := parseWebsiteInformation(doc) @@ -86,7 +86,7 @@ func TestNoExtration(t *testing.T) { doc, err := goquery.NewDocumentFromReader(strings.NewReader("")) require.NoError(t, err) expected := TuFilmWebsiteInformation{ - ImageUrl: "https://www.tu-film.de/img/film/poster/.sized.berraschungsfilm.jpg", + ImageUrl: "https://www.tu-film.de/img/film/poster/berraschungsfilm.jpg", ShortenedDescription: "Surprise yourself", } info, err := parseWebsiteInformation(doc) diff --git a/server/backend/cron/movies.go b/server/backend/cron/movies.go index 3de7a1cf..78b84493 100644 --- a/server/backend/cron/movies.go +++ b/server/backend/cron/movies.go @@ -1,8 +1,10 @@ package cron import ( + "fmt" "regexp" "slices" + "strings" "time" "github.com/TUM-Dev/Campus-Backend/server/backend/cron/movie_parsers" @@ -68,10 +70,13 @@ func (c *CronService) movieCron() error { Trailer: movieInformation.TrailerUrl, Link: item.Link, } + // register the preview file for download + seps := strings.SplitAfter(item.Enclosure.Url, ".") previewFile := model.File{ - Name: item.Title, - Path: MovieImageDirectory, - URL: null.StringFrom(item.Enclosure.Url), + Name: fmt.Sprintf("%s.%s", strings.TrimSpace(item.Title), seps[len(seps)-1]), + Path: MovieImageDirectory, + URL: null.StringFrom(item.Enclosure.Url), + Downloaded: null.BoolFrom(false), } if movieInformation.ImdbID.ValueOrZero() != "" { omdbMovie, err := movie_parsers.GetOmdbMovie(movieInformation.ImdbID.ValueOrZero())