class Asset {
  constructor(
    data,
    { hostnames: hostnames = { package: 'maxdome.de', store: 'store.maxdome.de' }, protocol: protocol = 'https' } = {}
  ) {
    this._rawData = data;

    this.hostnames = hostnames;
    this.protocol = protocol;

    this.id = data.id;

    const types = {
      assetvideofilm: 'movie',
      assetvideofilmtvseries: 'episode',
      multiassettvseriesseason: 'season',
      multiassetbundletvseries: 'series',
    };
    this.type = types[data['@class'].toLowerCase()];

    this.title = data.title;
    if (this.type === 'season') {
      this.title += ` (Staffel ${data.number})`;
    }
    this.originalTitle = data.title;
    this.searchTitle = data.title.replace(' (Hot From the UK)', '').replace(' (Hot from the US)', '');
    this.hotFromTheUK = data.title.includes(' (Hot From the UK)');
    this.hotFromTheUS = data.title.includes(' (Hot from the US)');
    this.episodeTitle = data.episodeTitle;
    this.episodeNumber = data.episodeNumber;
    this.seasonNumber = data.seasonNumber || data.number;

    this.description = data.descriptionShort;

    if (data.coverList) {
      const poster = data.coverList.filter(cover => cover.usageType === 'poster')[0];
      if (poster) {
        this.image = poster.url;
      }
    }

    this.areas = [];
    if (data.fullMarkingList.includes('inPremiumIncluded')) {
      this.areas.push('package');
    }
    if (data.mediaUsageList.includes('DTO') || data.mediaUsageList.includes('TVOD')) {
      this.areas.push('store');
    }

    this.countries = data.countryList || [];
    this.duration = data.duration;
    this.fskLevels = data.fskLevelList;
    this.genres = data.genreList
      .filter(genre => genre.genreType === 'genre' || genre.genreType === '_spielfilm')
      .map(genre => genre.value);
    this.languages = data.languageList;
    this.url = `${protocol}://${hostnames.package}/${data.id}`;
    this.productionYear = data.productionYear;

    if (data.userrating) {
      this.rating = {
        averageRating: data.userrating.averageRating,
        countTotal: data.userrating.countTotal,
      };
    }

    if (data.creditList) {
      this.actors = data.creditList
        .filter(credit => credit.creditType === 'actor')
        .map(credit => ({ name: credit.value }));
      this.directors = data.creditList
        .filter(credit => credit.creditType === 'director')
        .map(credit => ({ name: credit.value }));
    }
  }

  getImage(width = 204, height = 295) {
    if (this.image) {
      return {
        height,
        url: this.image.replace('__WIDTH__', width).replace('__HEIGHT__', height),
        width,
      };
    }
  }

  getCanonicalURL() {
    let hostname = this.hostnames.package;
    if (this.areas.includes('store')) {
      hostname = this.hostnames.store;
    }
    const slug = this.originalTitle
      .replace(/ä/g, 'ae')
      .replace(/ö/g, 'oe')
      .replace(/ü/g, 'ue')
      .replace(/ß/g, 'ss')
      .replace(/[.,"'?!;:]/g, '')
      .replace(/\W/g, '-')
      .replace(/_/g, '-')
      .toLowerCase();
    return `${this.protocol}://${hostname}/${slug}-${this.id}.html`;
  }
}

module.exports = Asset;

@@ -1,12 +1,257 @@
+function slugify(title) %7B%0A  return title%0A    .replace(/%C3%A4/g, 'ae')%0A    .replace(/%C3%B6/g, 'oe')%0A    .replace(/%C3%BC/g, 'ue')%0A    .replace(/%C3%9F/g, 'ss')%0A    .replace(/%5B.,%22'?!;:%5D/g, '')%0A    .replace(/%5CW/g, '-')%0A    .replace(/_/g, '-')%0A    .toLowerCase();%0A%7D%0A%0A
 class Asset 
@@ -2959,22 +2959,20 @@
 stnames.
-packag
+stor
 e;%0A    i
@@ -2970,24 +2970,25 @@
 re;%0A    if (
+!
 this.areas.i
@@ -3035,28 +3035,30 @@
 s.hostnames.
-stor
+packag
 e;%0A    %7D%0A   
@@ -3062,256 +3062,664 @@
     
-const slug = this.originalTitle%0A      .replace(/%C3%A4/g, 'ae')
+let path = '';%0A    switch (this.type) %7B%0A      case 'episode':%0A        path = %60/$%7Bslugify(this.originalTitle)%7D/s$%7Bthis.seasonNumber%7D/e$%7Bthis.episodeNumber%7D-$%7Bslugify(this.episodeTitle)%7D-$%7Bthis.id%7D.html%60;%0A        break;%0A      case 'movie':
 %0A      
-.replace(/%C3%B6/g, 'oe')%0A      .replace(/%C3%BC/g, 'ue')%0A      .replace(/%C3%9F/g, 'ss')%0A      .replace(/%5B.,%22'?!;:%5D/g, '')%0A      .replace(/%5CW/g, '-')%0A      .replace(/_/g, '-')%0A      .toLowerCase();
+  path = %60/$%7Bslugify(this.originalTitle)%7D-$%7Bthis.id%7D.html%60;%0A        break;%0A      case 'season':%0A        let season = '';%0A        if (this.seasonNumber %3E 1) %7B%0A          season = %60-s$%7Bthis.seasonNumber%7D%60;%0A        %7D%0A        path = %60/$%7Bslugify(this.originalTitle)%7D$%7Bseason%7D-b$%7Bthis.id%7D.html%60;%0A        break;%0A      case 'series':%0A        path = %60/$%7Bslugify(this.originalTitle)%7D-b$%7Bthis.id%7D.html%60;%0A        break;%0A    %7D
 %0A   
@@ -3761,32 +3761,15 @@
 ame%7D
-/
 $%7B
-slug%7D-$%7Bthis.id%7D.html
+path%7D
 %60;%0A 

Fix canonical URL