Skip to content

Commit

Permalink
made sure that the tu film does download only the bigger resolution i…
Browse files Browse the repository at this point in the history
…mages
  • Loading branch information
CommanderStorm committed Nov 1, 2023
1 parent f086330 commit 689a204
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
4 changes: 3 additions & 1 deletion server/backend/cron/movie_parsers/tufilm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
8 changes: 4 additions & 4 deletions server/backend/cron/movie_parsers/tufilm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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("<b>%s<b>\n\n%s\n\n<i>%s<i>", header, description, comment),
Director: null.StringFrom("Christopher Nolan"),
Actors: null.StringFrom("Cillian Murphy, Emily Blunt, Matt Damon"),
Expand All @@ -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&#39;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("<b>%s<b>\n\n%s\n\n<i>%s<i>", header, description, comment),
Director: null.StringFrom("Damien Chazelle"),
Actors: null.StringFrom("Brad Pitt, Margot Robbie, Jean Smart"),
Expand All @@ -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 [email protected]"
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("<b>%s<b>\n\n%s", header, description),
}
info, err := parseWebsiteInformation(doc)
Expand All @@ -86,7 +86,7 @@ func TestNoExtration(t *testing.T) {
doc, err := goquery.NewDocumentFromReader(strings.NewReader("<html></html>"))
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)
Expand Down
11 changes: 8 additions & 3 deletions server/backend/cron/movies.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package cron

import (
"fmt"
"regexp"
"slices"
"strings"
"time"

"github.com/TUM-Dev/Campus-Backend/server/backend/cron/movie_parsers"
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit 689a204

Please sign in to comment.