':param categories: The categories of coming episodes. See ``ComingEpisodes.categories``
:param sort: The sort to apply to the coming episodes. See ``ComingEpisodes.sorts``
:param group: ``True`` to group the coming episodes by category, ``False`` otherwise
:param paused: ``True`` to include paused shows, ``False`` otherwise
:return: The list of coming episodes'

@staticmethod
def get_coming_episodes(categories, sort, group, paused=sickbeard.COMING_EPS_DISPLAY_PAUSED):

    categories = ComingEpisodes._get_categories(categories)
    sort = ComingEpisodes._get_sort(sort)
    today = date.today().toordinal()
    recently = (date.today() - timedelta(days=sickbeard.COMING_EPS_MISSED_RANGE)).toordinal()
    next_week = (date.today() + timedelta(days=7)).toordinal()
    db = DBConnection(row_type=u'dict')
    fields_to_select = u',    '.join([u'airdate', u'airs', u'e.description    as    description', u'episode', u'imdb_id', u'e.indexer', u'indexer_id', u'e.location', u'name', u'network', u'paused', u'quality', u'runtime', u'season', u'show_name', u'showid', u'e.status    as    epstatus', u's.status'])
    status_list = ([WANTED, UNAIRED] + SNATCHED)
    sql_l = []
    for show_obj in sickbeard.showList:
        next_air_date = show_obj.nextEpisode()
        sql_l.append([(((u'SELECT    DISTINCT    {0}    '.format(fields_to_select) + u'FROM    tv_episodes    e,    tv_shows    s    WHERE    showid    =    ?    AND    airdate    <=    ?    AND    airdate    >=    ?    AND    s.indexer_id    =    e.showid    AND    e.status    IN    (') + u','.join(([u'?'] * len(status_list)))) + u')'), ([show_obj.indexerid, (next_air_date or today), recently] + status_list)])
    results = []
    for sql_i in sql_l:
        if results:
            results += db.select(*sql_i)
        else:
            results = db.select(*sql_i)
    for (index, item) in enumerate(results):
        results[index]['localtime'] = sbdatetime.convert_to_setting(parse_date_time(item['airdate'], item['airs'], item['network']))
        results[index]['snatchedsort'] = int((not (results[index]['epstatus'] in SNATCHED)))
    results.sort(key=ComingEpisodes.sorts[sort])
    if (not group):
        return results
    grouped_results = ComingEpisodes._get_categories_map(categories)
    for result in results:
        if (result['paused'] and (not paused)):
            continue
        result['airs'] = str(result['airs']).replace(u'am', u'    AM').replace(u'pm', u'    PM').replace(u'        ', u'    ')
        result['airdate'] = result['localtime'].toordinal()
        if (result['epstatus'] in SNATCHED):
            if result['location']:
                continue
            else:
                category = u'snatched'
        elif (result['airdate'] < today):
            category = u'missed'
        elif (result['airdate'] >= next_week):
            category = u'later'
        elif (result['airdate'] == today):
            category = u'today'
        else:
            category = u'soon'
        if ((len(categories) > 0) and (category not in categories)):
            continue
        if (not result['network']):
            result['network'] = u''
        result['quality'] = get_quality_string(result['quality'])
        result['airs'] = sbdatetime.sbftime(result['localtime'], t_preset=timeFormat).lstrip(u'0').replace(u'    0', u'    ')
        result['weekday'] = (1 + result['localtime'].weekday())
        result['tvdbid'] = result['indexer_id']
        result['airdate'] = sbdatetime.sbfdate(result['localtime'], d_preset=dateFormat)
        result['localtime'] = result['localtime'].toordinal()
        grouped_results[category].append(result)
    return grouped_results
