original_docstring: Processes `archives` to splice out an
          instance of `XMMarker` if it exists
docstring: Processes `archives` to splice out an
  instance of `XMMarker` if it exists
docstring_tokens: Processes ` archives ` to splice out an instance of ` XMMarker ` if it exists
code: def _process_cut(
          self, archives: Dict[str, str], cut: Union[XMCutMarker, XMEpisodeMarker]
      ) -> bool:
          """Processes `archives` to splice out an
          instance of `XMMarker` if it exists"""
  
          if (
              self.processed_folder is None
              or self._state.stream_channel is None
              or self._state.db is None
          ):
              return False
  
          archive = None
          start = cut.time + CUT_PADDING
          splice_start = timedelta(seconds=0)
          padded_duration = cut.duration + CUT_PADDING
          end = start + padded_duration
          splice_end = timedelta(seconds=0)
  
          for archive_key, archive_file in archives.items():
              archive_start, archive_end = [
                  from_fs_datetime(i) for i in archive_key.split(".")
              ]
  
              if archive_start < start and archive_end > end:
                  archive = archive_file
                  splice_start = start - archive_start
                  splice_end = splice_start + padded_duration
                  break
  
          if archive is not None:
              self._log.debug(f"found archive {archive}")
  
              title = None
              album_or_show = None
              album_url = None
              artist = None
              filename = None
              folder = os.path.join(self.processed_folder, self._state.stream_channel)
  
              if isinstance(cut, XMEpisodeMarker):
                  title = self._path_filter(
                      cut.episode.long_title or cut.episode.medium_title
                  )
  
                  if cut.episode.show is not None:
                      album_or_show = self._path_filter(
                          cut.episode.show.long_title or cut.episode.show.medium_title
                      )
                      album_url = get_art_thumb_url(cut.episode.show.arts)
  
                  filename = (
                      f'{title}.{cut.time.strftime("%Y-%m-%d-%H.%M")}' f".{cut.guid}.mp3"
                  )
                  folder = os.path.join(folder, "shows")
              elif isinstance(cut.cut, XMSong):
                  title = self._path_filter(cut.cut.title)
                  artist = self._path_filter(cut.cut.artists[0].name)
  
                  if cut.cut.album is not None and cut.cut.album.title is not None:
                      album_or_show = self._path_filter(cut.cut.album.title)
                      album_url = get_art_url_by_size(cut.cut.album.arts, "MEDIUM")
  
                  filename = f"{title}.{cut.guid}.mp3"
                  folder = os.path.join(folder, "songs", artist)
              else:
                  return False
  
              if album_or_show is not None:
                  folder = os.path.join(folder, album_or_show)
  
              os.makedirs(folder, exist_ok=True)
              path: Optional[str] = os.path.join(folder, filename)
              self._log.debug(f"{cut.duration}: {path}")
              if path is not None:
                  self._log.debug(
                      f"Splice song: (Song: {start}, {end}, {cut.duration}), "
                      f"(Archive: {archive}, {splice_start}, {splice_end}"
                  )
                  path = splice_file(
                      archive,
                      path,
                      int(splice_start.total_seconds()),
                      int(splice_end.total_seconds()),
                  )
  
              if path is not None:
                  if os.path.getsize(path) < 1000:
                      self._log.error(
                          f"spliced file too small, deleting {path}: {archive}"
                      )
                      os.remove(path)
                      return False
  
                  is_song = False
                  if isinstance(cut, XMEpisodeMarker):
                      db_item: Union[DBSong, DBEpisode] = DBEpisode(
                          guid=cut.guid,
                          title=title,
                          show=album_or_show,
                          air_time=cut.time,
                          channel=self._state.stream_channel,
                          file_path=path,
                          image_url=album_url,
                      )
                  elif isinstance(cut.cut, XMSong):
                      is_song = True
                      db_item = DBSong(
                          guid=cut.guid,
                          title=title,
                          artist=artist,
                          album=album_or_show,
                          air_time=cut.time,
                          channel=self._state.stream_channel,
                          file_path=path,
                          image_url=album_url,
                      )
                  else:
                      return False
  
                  self._state.db.add(db_item)
                  self._state.db.commit()
                  self._log.debug(f"inserted cut {is_song}: {db_item.guid}")
                  return True
          return False
code_tokens: def _process_cut ( self , archives : Dict [ str , str ] , cut : Union [ XMCutMarker , XMEpisodeMarker ] ) -> bool : if ( self . processed_folder is None or self . _state . stream_channel is None or self . _state . db is None ) : return False archive = None start = cut . time + CUT_PADDING splice_start = timedelta ( seconds = 0 ) padded_duration = cut . duration + CUT_PADDING end = start + padded_duration splice_end = timedelta ( seconds = 0 ) for archive_key , archive_file in archives . items ( ) : archive_start , archive_end = [ from_fs_datetime ( i ) for i in archive_key . split ( "." ) ] if archive_start < start and archive_end > end : archive = archive_file splice_start = start - archive_start splice_end = splice_start + padded_duration break if archive is not None : self . _log . debug ( f"found archive {archive}" ) title = None album_or_show = None album_url = None artist = None filename = None folder = os . path . join ( self . processed_folder , self . _state . stream_channel ) if isinstance ( cut , XMEpisodeMarker ) : title = self . _path_filter ( cut . episode . long_title or cut . episode . medium_title ) if cut . episode . show is not None : album_or_show = self . _path_filter ( cut . episode . show . long_title or cut . episode . show . medium_title ) album_url = get_art_thumb_url ( cut . episode . show . arts ) filename = ( f'{title}.{cut.time.strftime("%Y-%m-%d-%H.%M")}' f".{cut.guid}.mp3" ) folder = os . path . join ( folder , "shows" ) elif isinstance ( cut . cut , XMSong ) : title = self . _path_filter ( cut . cut . title ) artist = self . _path_filter ( cut . cut . artists [ 0 ] . name ) if cut . cut . album is not None and cut . cut . album . title is not None : album_or_show = self . _path_filter ( cut . cut . album . title ) album_url = get_art_url_by_size ( cut . cut . album . arts , "MEDIUM" ) filename = f"{title}.{cut.guid}.mp3" folder = os . path . join ( folder , "songs" , artist ) else : return False if album_or_show is not None : folder = os . path . join ( folder , album_or_show ) os . makedirs ( folder , exist_ok = True ) path : Optional [ str ] = os . path . join ( folder , filename ) self . _log . debug ( f"{cut.duration}: {path}" ) if path is not None : self . _log . debug ( f"Splice song: (Song: {start}, {end}, {cut.duration}), " f"(Archive: {archive}, {splice_start}, {splice_end}" ) path = splice_file ( archive , path , int ( splice_start . total_seconds ( ) ) , int ( splice_end . total_seconds ( ) ) , ) if path is not None : if os . path . getsize ( path ) < 1000 : self . _log . error ( f"spliced file too small, deleting {path}: {archive}" ) os . remove ( path ) return False is_song = False if isinstance ( cut , XMEpisodeMarker ) : db_item : Union [ DBSong , DBEpisode ] = DBEpisode ( guid = cut . guid , title = title , show = album_or_show , air_time = cut . time , channel = self . _state . stream_channel , file_path = path , image_url = album_url , ) elif isinstance ( cut . cut , XMSong ) : is_song = True db_item = DBSong ( guid = cut . guid , title = title , artist = artist , album = album_or_show , air_time = cut . time , channel = self . _state . stream_channel , file_path = path , image_url = album_url , ) else : return False self . _state . db . add ( db_item ) self . _state . db . commit ( ) self . _log . debug ( f"inserted cut {is_song}: {db_item.guid}" ) return True return False
short_docstring: Processes `archives` to splice out an
  instance of `XMMarker` if it exists
short_docstring_tokens: Processes ` archives ` to splice out an instance of ` XMMarker ` if it exists
comment: """Processes `archives` to splice out an
          instance of `XMMarker` if it exists"""