original_docstring: Merge listing data into the EPG channels data structure by channel name.
  
          This method takes an XMLTV listing object and, for every channel already loaded
          in the EPG it augments that channel's data with the data obtained from the XMLTV
          listing. This could provide additional descriptive channel data, the URL to the
          channel's logo and similar extra stuff.
  
          It then adds Programme objects to the Channel's Programme data structure.
  
          Args:
              listing(XMLTVListing): a :class:`~.xmltvlisting.XMLTVListing` object to
                  merge to the EPG.
  
          Returns:
              None
  
          Raises:
              ValueError: Raised if the XMLTVListing file cannot be found.
  
          
docstring: Merge listing data into the EPG channels data structure by channel name.
  This method takes an XMLTV listing object and, for every channel already loaded
  in the EPG it augments that channel's data with the data obtained from the XMLTV
  listing. This could provide additional descriptive channel data, the URL to the
  channel's logo and similar extra stuff.
  
  It then adds Programme objects to the Channel's Programme data structure.
docstring_tokens: Merge listing data into the EPG channels data structure by channel name . This method takes an XMLTV listing object and for every channel already loaded in the EPG it augments that channel ' s data with the data obtained from the XMLTV listing . This could provide additional descriptive channel data the URL to the channel ' s logo and similar extra stuff . It then adds Programme objects to the Channel ' s Programme data structure .
code: def apply_XMLTVListing(self, listing: XMLTVListing) -> None:
          """Merge listing data into the EPG channels data structure by channel name.
  
          This method takes an XMLTV listing object and, for every channel already loaded
          in the EPG it augments that channel's data with the data obtained from the XMLTV
          listing. This could provide additional descriptive channel data, the URL to the
          channel's logo and similar extra stuff.
  
          It then adds Programme objects to the Channel's Programme data structure.
  
          Args:
              listing(XMLTVListing): a :class:`~.xmltvlisting.XMLTVListing` object to
                  merge to the EPG.
  
          Returns:
              None
  
          Raises:
              ValueError: Raised if the XMLTVListing file cannot be found.
  
          """
          if not listing.downloaded:
              raise ValueError("No XMLTVListing file found.")
  
          # There is no guarantee that the XMLTV file will serve elements in a particular order.
          # We want to load and create _all_ the channels before we load the programmes so we use
          # a temp var to hold the programme items which we then add to the Channels _afterwards_.
  
          prog_temp = []
          for xmltv_item in listing.parse():
              if isinstance(xmltv_item, Channel):
                  sky_channel_names = [chan.name.lower() for chan in self._channels]
                  if xmltv_item.xmltv_display_name.lower() in sky_channel_names:
                      idx = sky_channel_names.index(xmltv_item.xmltv_display_name.lower())
                      new_chan = merge_channels(self._channels[idx], xmltv_item)
                      LOGGER.debug(f'New channel:{new_chan}.')
                      self._channels.append(new_chan)
                      LOGGER.debug(f'Replaced {self._channels[idx]} with {new_chan} in EPG.')
                      del self._channels[idx]
                      continue
              if isinstance(xmltv_item, Programme):
                  prog_temp.append(xmltv_item)
                  continue
  
          # We rely on the Programme's hash being the same as any previous
          # instance of this programme that is being added to the programmes
          # SortedSet as the __hash__() function relies _only_ on the programm's
          # Title, StartTime and XMLChannelID data. In this way, if we apply a
          # newer, richer XMLTV listing to an existing one, by adding this item to
          # the SortedSet we will _replace_ any previously present Programme if
          # the hash of the newer one is the same as an existing one, even if the
          # data is newer/better. This allows us to keep applying XMLTV Listing
          # over and over without risk of duplication.
          for chan in self._channels:
              chan_progs = [prog for prog in prog_temp if prog.channel_xml_id == chan.xmltv_id]
              chan.programmes.update(chan_progs)
code_tokens: def apply_XMLTVListing ( self , listing : XMLTVListing ) -> None : if not listing . downloaded : raise ValueError ( "No XMLTVListing file found." ) prog_temp = [ ] for xmltv_item in listing . parse ( ) : if isinstance ( xmltv_item , Channel ) : sky_channel_names = [ chan . name . lower ( ) for chan in self . _channels ] if xmltv_item . xmltv_display_name . lower ( ) in sky_channel_names : idx = sky_channel_names . index ( xmltv_item . xmltv_display_name . lower ( ) ) new_chan = merge_channels ( self . _channels [ idx ] , xmltv_item ) LOGGER . debug ( f'New channel:{new_chan}.' ) self . _channels . append ( new_chan ) LOGGER . debug ( f'Replaced {self._channels[idx]} with {new_chan} in EPG.' ) del self . _channels [ idx ] continue if isinstance ( xmltv_item , Programme ) : prog_temp . append ( xmltv_item ) continue for chan in self . _channels : chan_progs = [ prog for prog in prog_temp if prog . channel_xml_id == chan . xmltv_id ] chan . programmes . update ( chan_progs )
short_docstring: Merge listing data into the EPG channels data structure by channel name.
short_docstring_tokens: Merge listing data into the EPG channels data structure by channel name .
comment: """Merge listing data into the EPG channels data structure by channel name.
  
          This method takes an XMLTV listing object and, for every channel already loaded
          in the EPG it augments that channel's data with the data obtained from the XMLTV
          listing. This could provide additional descriptive channel data, the URL to the
          channel's logo and similar extra stuff.
  
          It then adds Programme objects to the Channel's Programme data structure.
  
          Args:
              listing(XMLTVListing): a :class:`~.xmltvlisting.XMLTVListing` object to
                  merge to the EPG.
  
          Returns:
              None
  
          Raises:
              ValueError: Raised if the XMLTVListing file cannot be found.
  
          """$SEP$# There is no guarantee that the XMLTV file will serve elements in a particular order.$SEP$# We want to load and create _all_ the channels before we load the programmes so we use$SEP$# a temp var to hold the programme items which we then add to the Channels _afterwards_.$SEP$# We rely on the Programme's hash being the same as any previous$SEP$# instance of this programme that is being added to the programmes$SEP$# SortedSet as the __hash__() function relies _only_ on the programm's$SEP$# Title, StartTime and XMLChannelID data. In this way, if we apply a$SEP$# newer, richer XMLTV listing to an existing one, by adding this item to$SEP$# the SortedSet we will _replace_ any previously present Programme if$SEP$# the hash of the newer one is the same as an existing one, even if the$SEP$# data is newer/better. This allows us to keep applying XMLTV Listing$SEP$# over and over without risk of duplication.