Author: ygrego Date: 2015-06-18 07:51:44 +0000 (Thu, 18 Jun 2015) New Revision: 1741 Url: http://forge.nuiton.org/projects/sandbox/repository/revisions/1741 Log: Use of icon for channel this will be more friendly in emulator. Manage additionals channels information. No more necessary to modify the channel mapping between channel real name and channel identifier. Modified: oipf/lib/js/utils/ProgrammeHelper.js Modified: oipf/lib/js/utils/ProgrammeHelper.js =================================================================== --- oipf/lib/js/utils/ProgrammeHelper.js 2015-06-17 16:04:19 UTC (rev 1740) +++ oipf/lib/js/utils/ProgrammeHelper.js 2015-06-18 07:51:44 UTC (rev 1741) @@ -5,37 +5,33 @@ */ class ProgrammeHelper { - constructor(channelService) { + constructor(channelService, channels) { this.map = { "title": "name", "start": "startTime", + "stop": "duration", "desc": "description", - "length#text": "duration", "episode-num#text": "episode", "title#text": "name" }; - this.channelNameMap = { - "ART1.kazer.org": "ARTE", - "EUR2.kazer.org": "D17", - "FRA2.kazer.org": "FRANCE_2", - "FRA3.kazer.org": "FRANCE_3", - "FRA4.kazer.org": "FRANCE_4", - "FRA5.kazer.org": "FRANCE_5", - "M61.kazer.org": "M6", - "NRJ1.kazer.org": "NRJ_12", - "NT11.kazer.org": "NT1", - "RTL2.kazer.org": "RTL9", - "TF11.kazer.org": "TF1", - "TMC1.kazer.org": "TMC", - "W91.kazer.org": "W9" - }; + this.channelsLogoAndRealName = {}; + this.setChannelsLogoAndRealName(channels) - this.programmes = null; this.channelService = channelService; this.programmes = []; } + setChannelsLogoAndRealName(channelsArray) { + var self = this; + if (channelsArray) { + channelsArray.forEach(function(item) { + if (item.id) { + self.channelsLogoAndRealName[item.id] = item; + } + }); + } + } /* * Description: * Don't take in charge the "credits" property of a xmlTv programmes for the moment. @@ -57,14 +53,14 @@ if (key == "start") { element = self.transformInSecondSince01011970(element); } + if (key == "stop") { + element = self.transformInSecondSince01011970(element); + } if (key == "channel") { - channelName = self.channelNameMap[element]; + channelName = element; } if (key == "#text") { key = parentKey + key; - if (key == "length#text") { - element = self.minutesToSeconds(element); - } } var mapping = self.map[key]; if (mapping) { @@ -75,7 +71,22 @@ }; createProgramme(object, programme); - programme.channel = this.initChannel(channelName); + var realChannelName = this.channelsLogoAndRealName[channelName]["display-name"]; + var channelLogoUrl = this.channelsLogoAndRealName[channelName].icon.src; + + if (realChannelName) { + var channel = this.channelService.getChannelSimplyByName(realChannelName); + if (!channel) { + channel = this.initChannel(realChannelName); + } + channel.logoUrl = channelLogoUrl; + programme.channel = channel; + } + + if (programme.startTime && programme.duration) { + programme.duration = programme.duration - programme.startTime; + } + programme.programmeID = OipfUtils.createUUID(); var programmeObject = new Programme(programme); this.programmes.push(programmeObject); @@ -95,7 +106,7 @@ tmpDate = pattern.exec(tmpDate); var year = parseInt(tmpDate[1]); - var month = parseInt(tmpDate[2]); + var month = parseInt(tmpDate[2]) - 1; var day = parseInt(tmpDate[3]); var hs = parseInt(tmpDate[4]); var mins = parseInt(tmpDate[5]);