def _download_from_client(client, client_type, catalog, data_pad, process_len,
                          available_stations=[], all_channels=False, debug=0):
    """
    Internal function to handle downloading from either seishub or fdsn client
    """
    st = Stream()
    catalog = Catalog(sorted(catalog, key=lambda e: e.origins[0].time))
    all_waveform_info = []
    for event in catalog:
        for pick in event.picks:
            if not pick.waveform_id:
                debug_print(
                    "Pick not associated with waveforms, will not use:"
                    " {0}".format(pick), 1, debug)
                continue
            if all_channels:
                channel_code = pick.waveform_id.channel_code[0:2] + "?"
            else:
                channel_code = pick.waveform_id.channel_code
            all_waveform_info.append((
                pick.waveform_id.network_code, pick.waveform_id.station_code,
                channel_code, pick.waveform_id.location_code))
    starttime = UTCDateTime(
        catalog[0].origins[0].time - data_pad)
    endtime = starttime + process_len
    # Check that endtime is after the last event
    if not endtime > catalog[-1].origins[0].time + data_pad:
        raise TemplateGenError(
            'Events do not fit in processing window')
    all_waveform_info = sorted(list(set(all_waveform_info)))
    dropped_pick_stations = 0
    for waveform_info in all_waveform_info:
        net, sta, chan, loc = waveform_info
        if client_type == 'seishub' and sta not in available_stations:
            debug_print("Station not found in SeisHub DB", 0, debug)
            dropped_pick_stations += 1
            continue
        debug_print('Downloading for \n\tstart-time: %s\n\tend-time: %s' %
                    (str(starttime), str(endtime)), 0, debug)
        debug_print('.'.join([net, sta, loc, chan]), 0, debug)
        try:
            st += client.get_waveforms(net, sta, loc, chan,
                                       starttime, endtime)
        except Exception:
            debug_print('Found no data for this station', 2, debug)
            dropped_pick_stations += 1
    if not st and dropped_pick_stations == len(event.picks):
        raise Exception('No data available, is the server down?')
    st.merge()
    # clients download chunks, we need to check that the data are
    # the desired length
    final_channels = []
    for tr in st:
        tr.trim(starttime, endtime)
        if len(tr.data) == (process_len * tr.stats.sampling_rate) + 1:
            tr.data = tr.data[1:len(tr.data)]
        if tr.stats.endtime - tr.stats.starttime < 0.8 * process_len:
            debug_print(
                "Data for {0}.{1} is {2} hours long, which is less than 80 "
                "percent of the desired length, will not pad".format(
                    tr.stats.station, tr.stats.channel,
                    (tr.stats.endtime - tr.stats.starttime) / 3600), 4, debug)
        elif not pre_processing._check_daylong(tr):
            print("Data are mostly zeros, removing trace: {0}".format(tr.id))
        else:
            final_channels.append(tr)
    st.traces = final_channels
    return st