epgtools.dumpepgfromts.dataextractor.programme.ProgrammeDataExtractor.java Source code

Java tutorial

Introduction

Here is the source code for epgtools.dumpepgfromts.dataextractor.programme.ProgrammeDataExtractor.java

Source

/*
 * Copyright (C) 2016 normal
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package epgtools.dumpepgfromts.dataextractor.programme;

import epgtools.dumpepgfromts.dataextractor.AbstractDataExtractor;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import libepg.epg.section.Section;
import libepg.epg.section.TABLE_ID;
import libepg.epg.section.body.eventinformationtable.EventInformationTableBody;
import libepg.epg.section.body.eventinformationtable.EventInformationTableRepeatingPart;
import libepg.epg.section.descriptor.DESCRIPTOR_TAG;
import libepg.epg.section.descriptor.Descriptor;
import libepg.epg.section.descriptor.contentdescriptor.ContentDescriptor;
import libepg.epg.section.descriptor.contentdescriptor.Nibble;
import libepg.epg.section.descriptor.extendedeventdescriptor.ExtendedEventDescriptor;
import libepg.epg.section.descriptor.shorteventdescriptor.ShortEventDescriptor;
import org.apache.commons.codec.binary.Hex;

/**
 * EIT????????????
 * EventInformationTableBody.getTransport_stream_id
 * EventInformationTableBody.getOriginal_network_id
 * EventInformationTableBody.getService_id
 * EventInformationTableRepeatingPart.getEvent_id
 * EventInformationTableRepeatingPart.getStart_time_Object
 * EventInformationTableRepeatingPart.getStopTime_Object
 * ShortEventDescriptor.getEvent_name_String ShortEventDescriptor.getText_String
 *
 * @author normal
 */
public class ProgrammeDataExtractor extends AbstractDataExtractor<Programme> {

    public ProgrammeDataExtractor() throws IllegalArgumentException {
        super(TABLE_ID.EIT_OTHER_STREAM_8_DAYS, TABLE_ID.EIT_OTHER_STREAM_NOW_AND_NEXT,
                TABLE_ID.EIT_THIS_STREAM_8_DAYS, TABLE_ID.EIT_THIS_STREAM_NOW_AND_NEXT);
    }

    @Override
    public void makeDataSet(Section s) throws IllegalStateException {
        final boolean isPutMessage = false;

        this.checkSection(s);

        this.checkSectionBodyType(s);

        EventInformationTableBody b = (EventInformationTableBody) s.getSectionBody();

        final TABLE_ID tid = s.getTable_id_const();

        boolean this_or_other = false;
        if (tid == TABLE_ID.EIT_THIS_STREAM_8_DAYS || tid == TABLE_ID.EIT_THIS_STREAM_NOW_AND_NEXT) {
            this_or_other = true;
        } else if (tid == TABLE_ID.EIT_OTHER_STREAM_NOW_AND_NEXT || tid == TABLE_ID.EIT_OTHER_STREAM_8_DAYS) {
            this_or_other = false;
        }

        int transport_stream_id = b.getTransport_stream_id();

        int original_network_id = b.getOriginal_network_id();

        int service_id = b.getService_id();

        int event_id = Integer.MIN_VALUE;

        Timestamp start_Time = null;

        Timestamp stop_Time = null;

        String event_name = null;

        String description = null;

        List<Nibble> nibbles = null;

        final List<EventInformationTableRepeatingPart> rp = b.getEITRepeatingPartList();

        for (EventInformationTableRepeatingPart rpart : rp) {
            boolean sdtFlag = false;
            REPEATING_PART: {
                event_id = rpart.getEvent_id();

                start_Time = rpart.getStart_time_Object();
                if (start_Time == null) {
                    LOG.warn(
                            "??????? ?????????? = "
                                    + Hex.encodeHexString(s.getData()));
                    break REPEATING_PART;
                }
                if (LOG.isInfoEnabled() && isPutMessage) {
                    LOG.info(start_Time);
                }

                stop_Time = rpart.getStop_Time_Object();
                if (stop_Time == null) {
                    LOG.warn(
                            "?????????????????  = "
                                    + Hex.encodeHexString(s.getData()));
                    break REPEATING_PART;
                }
                if (LOG.isInfoEnabled() && isPutMessage) {
                    LOG.info(stop_Time);
                }

                for (Descriptor desc : rpart.getDescriptors_loop().getDescriptors_loopList()) {
                    //???(????)
                    if (desc.getDescriptor_tag_const() == DESCRIPTOR_TAG.SHORT_EVENT_DESCRIPTOR) {

                        ShortEventDescriptor sedesc = (ShortEventDescriptor) desc;

                        event_name = sedesc.getEvent_name_String();
                        if (LOG.isInfoEnabled() && isPutMessage) {
                            LOG.info(event_name);
                        }

                        description = sedesc.getText_String();
                        event_name = sedesc.getEvent_name_String();
                        if (LOG.isInfoEnabled() && isPutMessage) {
                            LOG.info(description);
                        }
                        sdtFlag = true;
                    }

                    //???
                    if (desc.getDescriptor_tag_const() == DESCRIPTOR_TAG.CONTENT_DESCRIPTOR) {

                        ContentDescriptor cdesc = (ContentDescriptor) desc;
                        try {
                            nibbles = cdesc.getNibbles();
                        } catch (IllegalStateException ex) {
                            LOG.error(
                                    "????????????????",
                                    ex);
                            nibbles = new ArrayList<>();
                        }
                    }

                }

                //sdt??EIT????????????????
                if (sdtFlag == true) {
                    //?
                    final Programme p = new Programme(event_id, start_Time, stop_Time, event_name, description,
                            nibbles, transport_stream_id, original_network_id, service_id, this_or_other);

                    if (p != null) {
                        boolean ret = this.getDataSet().add(p);
                        if ((ret == false) && LOG.isInfoEnabled() && isPutMessage) {
                            LOG.info("?\n" + p);
                        }
                    } else {
                        LOG.error("?null??  = "
                                + Hex.encodeHexString(s.getData()));
                    }
                }
            }
        }
    }
}