How can I convert an irregular PWM signal with a duty cycle of 95 to 99% to an analog signal?
Although one could use a simple RC filter, I think one would do better to use some sort of digital filtering.  The time scales you're looking at look well within the range of what a processor could handle.  I would suggest that your best bet is probably to do something like sample the input pin once per millisecond and keep track of how many times the input has been low during each somewhat longer time interval (maybe one second or five seconds), and then use a digital FIR filter to add up those readings.  A simple way to perform the filter FIR filter is to scale up each reading so as to be a bit short of the full range of a 16- or 32-bit integer, and then do something like (pseudo-code):


temp = new_reading
for each item in an array
  new_temp = (temp + array_item)/2
  array_item = temp
  temp = new_temp
loop  


The final value of new_temp will represent a low-pass filtered value of the input; one can vary the number of seconds per reading and the length of the array to adjust the filter characteristics.  Note that if one uses e.g. a sampling interval of two seconds and an array that's 16 elements long, only the last 32 seconds of input will be considered in producing the output (meaning that the output will fully respond to any change in input conditions within 32 seconds) but relatively "stable" input conditions will yield a relatively stable output (much more stable than with an RC filter that converges reasonably fast).