def chooseEPG(self, startTime, endTime, date, recorder, id, title, index):
        self.stopped()
        utils.clearVideoFrame(self.mainWindow)
        self.mainWindow.child_position = None
        self.mainWindow.child_epg = None
        startDateTimeStr = '{};{}'.format(startTime, date)
        endDateTimeStr = '{};{}'.format(endTime, date)
        startDateTime = datetime.datetime.strptime(startDateTimeStr,
                                                   "%H:%M:%S;%d.%m.%Y")
        endDateTime = datetime.datetime.strptime(endDateTimeStr,
                                                 "%H:%M:%S;%d.%m.%Y")
        startTimesTamp = int(time.mktime(startDateTime.timetuple()))
        endTimesTamp = int(time.mktime(endDateTime.timetuple()))

        self.mainWindow.custom_epg = False

        epg_url = '{0}{1}.record?from={2}&to={3}'.format(
            config.getMediaUrl(), recorder, str(startTimesTamp),
            str(endTimesTamp))
        # self.mainWindow.current_epg['startTimesTamp'] = startTimesTamp
        # self.mainWindow.current_epg['endTimesTamp'] = endTimesTamp
        # self.mainWindow.current_epg['recorder'] =  recorder
        # self.mainWindow.current_epg['title'] = title
        # self.mainWindow.current_epg['url'] = epg_url
        self.mainWindow.current_epg = {
            'startTimesTamp': startTimesTamp,
            'endTimesTamp': endTimesTamp,
            'recorder': recorder,
            'title': title,
            'url': epg_url
        }

        self.mainWindow.current_epg_obj = self.mainWindow.listEpg.epg_list[
            index]
        self.mainWindow.selectedEPG.setSelectedEPG(
            self.mainWindow.current_epg_obj)

        self.mainWindow.videoData = (startTimesTamp, endTimesTamp)

        epg_name = '{0}_{1}-{2}'.format(id, startTimesTamp, endTimesTamp)
        try:
            code = urllib.request.urlopen(epg_url).getcode()
        except:
            code = 0
        self.mainWindow.focusState.setFocusState(0)

        if code == 200:
            # self.mainWindow.current_epg['mediaUrl'] = config.getMediaUrl()
            self.mainWindow.vlcPlayer.setMedia(epg_url)
            self.mainWindow.media_state = True
            self.mainWindow.focusState.setMediaSetState(1)
            self.mainWindow.listSegmentPostiton.deleteAllSegment()
            self.mainWindow.status.setStatusText('')
        if code == 0:
            self.mainWindow.focusState.setMediaSetState(0)
            self.mainWindow.media_state = False
            self.mainWindow.status.setStatusText(
                self.mainWindow.status.epgNotAvailable)
    def setCustomEpg(self, date, startTime, endTime, recorder):
        self.mainWindow.videoControls.stopped()
        utils.clearVideoFrame(self.mainWindow)
        startTimestamp = utils.convertToTimestamp(startTime, date)
        endTimestamp = utils.convertToTimestamp(endTime, date)
        self.mainWindow.custom_epg = True

        custom_epg = models.EPG.create(date=date,
                                       startTime=startTime,
                                       endTime=endTime,
                                       recorder=recorder)
        custom_epg_obj = EPG(custom_epg)
        self.mainWindow.current_epg_obj = custom_epg_obj

        epg_url = '{0}{1}.record?from={2}&to={3}'.format(
            config.getMediaUrl(), recorder, str(startTimestamp),
            str(endTimestamp))

        # self.mainWindow.current_epg['startTimesTamp'] = startTimestamp
        # self.mainWindow.current_epg['endTimesTamp'] = endTimestamp
        # self.mainWindow.current_epg['url'] = epg_url
        # self.mainWindow.current_epg['recorder'] = recorder
        self.mainWindow.current_epg = {
            'startTimesTamp': startTimestamp,
            'endTimesTamp': endTimestamp,
            'recorder': recorder,
            'title': None,
            'url': epg_url
        }

        epg_name = '{0}_{1}-{2}'.format(id, startTimestamp, endTimestamp)
        try:
            code = urllib.request.urlopen(epg_url).getcode()
        except:
            code = 0
        self.mainWindow.focusState.setFocusState(1)
        if code == 200:
            # self.mainWindow.current_epg['mediaUrl'] = config.getMediaUrl()
            self.mainWindow.vlcPlayer.setMedia(epg_url)
            self.mainWindow.media_state = True
            self.mainWindow.focusState.setMediaSetState(1)
            self.mainWindow.listSegmentPostiton.deleteAllSegment()
            self.mainWindow.status.setStatusText('')
        if code == 0:
            self.mainWindow.focusState.setMediaSetState(0)
            self.mainWindow.media_state = False
            self.mainWindow.status.setStatusText(
                self.mainWindow.status.fragmentNotAvailable)
示例#3
0
def changePosVideo(mainWindow, sliderPosition):
    duration_video_second = getDurationSeconds(mainWindow)
    per_slider_position = sliderPosition / 1000
    child_start_pos = int(duration_video_second * per_slider_position)
    mainWindow.timePostitonSecond = child_start_pos
    childSliderPositionStart = sliderPosition
    mainWindow.vlcPlayer.mediaplayer.pause()
    cur_epg = mainWindow.current_epg
    child_epg = {
        'startTimesTamp': cur_epg.get('startTimesTamp') + child_start_pos,
        'endTimesTamp': cur_epg.get('endTimesTamp'),
        'recorder': cur_epg.get('recorder')
    }
    mainWindow.child_epg = child_epg
    epg_url = '{0}{1}.record?from={2}&to={3}'.format(
        config.getMediaUrl(), child_epg.get('recorder'),
        str(child_epg.get('startTimesTamp')),
        str(child_epg.get('endTimesTamp')))
    mainWindow.vlcPlayer.mediaplayer.pause()
    mainWindow.vlcPlayer.setMedia(epg_url)
    mainWindow.vlcPlayer.mediaplayer.play()
    def store(self, listSegments):
        # self.mainWindow.listExtractingPlayers = []
        old_stored = self.mainWindow.listStoringPlayers
        old_items = []
        for elem in old_stored:
            old_items.append(elem.get('segment'))
        listStored = listSegments
        for item in listStored:
            if item.startTimestamp != 0 and item.endTimestamp != 0 and item not in old_items:

                url = '{0}{1}.record?from={2}&to={3}'.format(config.getMediaUrl(),
                                                             str(item.recorder),
                                                             str(int(item.startTimestamp)),
                                                             str(int(item.endTimestamp)))
                startTime = '_'.join(str(item.startTime).split(':'))
                endTime = '_'.join(str(item.endTime).split(':'))
                name = '_'.join(str(item.title).split(' '))
                name = '_'.join(str(name).split(':'))
                name = '_'.join(str(name).split('.'))
                name = '_'.join([str(name), startTime, endTime])
                home = expanduser("~")
                # dir_to_save = os.path.join(home, config.temp_media)
                dir_to_save = self.save_path
                if not os.path.exists(dir_to_save):
                    os.mkdir(dir_to_save)
                path_to_save = os.path.join(dir_to_save, '{}.ts'.format(name))
                # rec_instance = vlc.Instance('--sout=file/ts:{0}'.format(path_to_save))
                # media = rec_instance.media_new(url)
                # rec = rec_instance.media_player_new()
                # rec.set_media(media)
                # rec.play()
                downloader = Downloader(url, path_to_save)
                item.changeStateStore(1)
                self.mainWindow.listStoringPlayers.append({'rec': downloader, 'segment': item})
                downloader.start()
        self.mainWindow.listSegmentPostiton.update()