Esempio n. 1
0
def CopyMediaFiles():
    print "Copying files from USB to RaspMedia Player"
    clear = True
    # search for update indicator file
    for file in os.listdir(USB_MEDIA_PATH):
        if not file.endswith((SUPPORTED_IMAGE_EXTENSIONS)) and not file.endswith((SUPPORTED_VIDEO_EXTENSIONS)) and file.startswith('update'):
            # file indicating a file update found, load config and set flag
            print "File to indicate a media file update found."
            print "Current files on the player will not be deleted."
            print "Existing files with the same name as a new media file will be overwritten."
            clear = False
            config = configtool.readConfig()
            try:
                configDict = ast.literal_eval(config)
                config = configDict
            except:
                pass
            imgEnabled = config["image_enabled"]
            vidEnabled = config["video_enabled"]
    if clear:
        # delete previous files from player
        shutil.rmtree(MEDIA_PATH)
        if not os.path.isdir(MEDIA_PATH):
            os.mkdir(MEDIA_PATH)
        imgEnabled = 0
        vidEnabled = 0
    for file in os.listdir(USB_MEDIA_PATH):
        if not file.startswith('.'):
            if file.endswith((SUPPORTED_IMAGE_EXTENSIONS)):
                imgEnabled = 1
                ResizeFitAndCopyImage(file, USB_MEDIA_PATH, MEDIA_PATH)
                # OptimizeAndCopyImage(file, USB_MEDIA_PATH, MEDIA_PATH)
            elif file.endswith((SUPPORTED_VIDEO_EXTENSIONS)):
                vidEnabled = 1
                print "Copy video file: ", file
                size = (os.stat(USB_MEDIA_PATH + '/' + file).st_size)
                size /= 1024
                size /= 1024
                fileSize = str(size) + 'MB'
                print "Size: ", fileSize
                print "Please wait..."
                srcFile = USB_MEDIA_PATH + '/' + file
                dstFile = MEDIA_PATH + '/' + file
                shutil.copyfile(srcFile, dstFile)

    print "Media files copied to player successfully!"
    print "Configuring playback settings for your new media files..."
    configtool.readConfig()
    configtool.setConfigValue("image_enabled", imgEnabled)
    configtool.setConfigValue("video_enabled", vidEnabled)
    print "Done!"
Esempio n. 2
0
def setState(state):
    global playerState
    global blackout
    global filenumber
    global mp_thread
    config = configtool.readConfig()
    # 0 = stop, 1 = play
    if state == 0:
        if playerState == PLAYER_STARTED:
            stop()
        blackout = False
    elif state == 1:
        if playerState == PLAYER_STOPPED:
            play()
        elif playerState == PLAYER_STARTED and blackout:
            stop()
            time.sleep(1)
            blackout = False	    
            play()
        blackout = False
    elif state == 2:
        if playerState == PLAYER_STARTED:
            stop()
        blackout = True
        time.sleep(1)
        blackout = True
        play()
    elif state == 3:
        pause()
Esempio n. 3
0
def setState(state):
    global playerState
    global blackout
    global filenumber
    global mp_thread
    config = configtool.readConfig()
    # 0 = stop, 1 = play
    if state == 0:
        if playerState == PLAYER_STARTED:
            stop()
        blackout = False
    elif state == 1:
        if playerState == PLAYER_STOPPED:
            play()
        elif playerState == PLAYER_STARTED and blackout:
            stop()
            time.sleep(1)
            blackout = False
            play()
        blackout = False
    elif state == 2:
        if playerState == PLAYER_STARTED:
            stop()
        blackout = True
        time.sleep(1)
        blackout = True
        play()
    elif state == 3:
        pause()
Esempio n. 4
0
def identifySelf():
    global identifyFlag, mp_thread, playerState, previousState
    previousState = playerState
    if playerState == PLAYER_STARTED:
        stop()
        time.sleep(0.5)
    identifyFlag = True
    config = configtool.readConfig()
    ImageIdentifier.IdentifyImage(config['player_name'])
    print "Image prepared..."
    mp_thread.identify_event.clear()
    play()
Esempio n. 5
0
def identifySelf():
    global identifyFlag, mp_thread, playerState, previousState
    previousState = playerState
    if playerState == PLAYER_STARTED:
        stop()
        time.sleep(0.5)
    identifyFlag = True
    config = configtool.readConfig()
    ImageIdentifier.IdentifyImage(config['player_name'])
    #print "Image prepared..."
    mp_thread.identify_event.clear()
    play()
Esempio n. 6
0
def getConfigMessage():
    config = configtool.readConfig()
    configStr = str(config)
    confBytes = bytearray(configStr)

    data = bytearray()
    size = 10 + len(confBytes)
    appendInt(data, size)
    appendShort(data, CONFIG_REQUEST)
    appendInt(data, len(confBytes))
    appendBytes(data, confBytes)

    return data
Esempio n. 7
0
def getConfigMessage():
	config = configtool.readConfig()
	configStr = str(config)
	#print "Building message for CONFIG:"
	#print configStr
	confBytes = bytearray(configStr)

	data = bytearray()
	size = 10 + len(confBytes)
	appendInt(data, size)
	appendShort(data, CONFIG_REQUEST)
	appendInt(data, len(confBytes))
	appendBytes(data, confBytes)

	#print "Message size: ", size
	return data
Esempio n. 8
0
    def handle(self):
        data = self.request[0]
        inData = self.request[0].strip()
        cSocket = self.request[1]
        curThread = threading.current_thread()
        result, msg = interpreter.interpret(data)

        if result == SERVER_REQUEST:
            print "{} on {} wrote:".format(self.client_address[0], curThread.name)
            print "\nServer request received - sending response...\n"
            responseData = messages.getMessage(SERVER_REQUEST_ACKNOWLEDGE, ["-i", str(TYPE_RASPMEDIA_PLAYER), "-i", "0","-s", str(configtool.readConfig()['player_name'])])
            addr = (self.client_address[0], UDP_PORT)
            #print "Response delay..."
            #time.sleep(1)
            print "Sending response to:"
            print (addr)
            if cSocket.sendto(responseData, addr):
                print "Response sent!"
            else:
                print "Sending response failed!"
        elif result == FILELIST_REQUEST:
            files = mediaplayer.getMediaFileList()
            print files
            args = ['-i', str(len(files))]
            for file in files:
                args.append('-s')
                args.append(file)
            responseData = messages.getMessage(FILELIST_RESPONSE,args)
            if cSocket.sendto(responseData, (self.client_address[0], UDP_PORT)):
                print "Filelist sent!"
        elif result == CONFIG_REQUEST:
            responseData = messages.getConfigMessage()
            if cSocket.sendto(responseData, (self.client_address[0], UDP_PORT)):
                print "Config sent!"
        elif result == PLAYER_UPDATE_ERROR:
            responseData = messages.getMessage(PLAYER_UPDATE_ERROR, ["-s", str(msg)])
            cSocket.sendto(responseData, (self.client_address[0], UDP_PORT))
Esempio n. 9
0
 def reloadConfig(self):
     self.config = configtool.readConfig()
Esempio n. 10
0
    def handle(self):
        data = self.request[0]
        inData = self.request[0].strip()
        cSocket = self.request[1]
        curThread = threading.current_thread()
        if not self.client_address[0] in netutil.ip4_addresses():
            result, msg = interpreter.interpret(data, self.client_address[0])


            if result == SERVER_REQUEST:
                freeSpace = self.FreeDiskSpace()
                responseData = messages.getMessage(SERVER_REQUEST_ACKNOWLEDGE, ["-i", str(TYPE_RASPMEDIA_PLAYER), "-i", "0","-s", str(configtool.readConfig()['player_name']), "-i", str(freeSpace[0]), "-i", str(freeSpace[1])])
                addr = (self.client_address[0], UDP_PORT)
                print "Sending response to client:"
                print (addr)
                if cSocket.sendto(responseData, addr):
                    print "Response sent!"
                else:
                    print "Sending response failed!"
            elif result == FILELIST_REQUEST:
                files = mediaplayer.getMediaFileList()
                args = ['-i', str(len(files))]
                for file in files:
                    args.append('-s')
                    args.append(file)
                responseData = messages.getMessage(FILELIST_RESPONSE,args)
                if cSocket.sendto(responseData, (self.client_address[0], UDP_PORT)):
                    print "Filelist sent!"
            elif result == CONFIG_REQUEST:
                responseData = messages.getConfigMessage()
                if cSocket.sendto(responseData, (self.client_address[0], UDP_PORT)):
                    print "Config sent!"
            elif result == GROUP_CONFIG_REQUEST:
                response = messages.getGroupConfigMessage()
                if cSocket.sendto(response, (self.client_address[0], UDP_PORT)):
                    print "Group Config sent!"
            elif result == GROUP_CONFIG_ADD_ACTION:
                    configtool.addGroupAction(msg)
                    gConf = configtool.readGroupConfig()
                    response = messages.getMessage(GROUP_CONFIG_ADD_ACTION)
                    if cSocket.sendto(response, (self.client_address[0], UDP_PORT)):
                        print "Action saved confirmation sent!"
                    GroupManager.ReInitGroupManager(gConf)
            elif result == GROUP_CONFIG_ACTION_DELETE:
                    configtool.deleteGroupAction(msg)
                    gConf = configtool.readGroupConfig()
                    response = messages.getMessage(GROUP_CONFIG_ACTION_DELETE)
                    if cSocket.sendto(response, (self.client_address[0], UDP_PORT)):
                        print "Action deleted confirmation sent!"
                    GroupManager.ReInitGroupManager(gConf)
            elif result == PLAYER_UPDATE_ERROR:
                responseData = messages.getMessage(PLAYER_UPDATE_ERROR, ["-s", str(msg)])
                cSocket.sendto(responseData, (self.client_address[0], UDP_PORT))
            elif result == FILE_DATA_REQUEST:
                # send images from player over tcp to host in separate thread to not block other udp handling
                t = threading.Thread(target=self.SendImagesOverTCP, args=[self.client_address[0]])
                t.daemon = True
                t.start()
            elif result == DISK_INFO_REQUEST:
                freeSpace = self.FreeDiskSpace()
                responseData = messages.getMessage(DISK_INFO_REQUEST, ["-i", str(freeSpace[0]), "-i", str(freeSpace[1])])
                addr = (self.client_address[0], UDP_PORT)
                if cSocket.sendto(responseData, addr):
                    print "Disk Info sent!"
                else:
                    print "Sending disk info failed!"
        else:
            print "Received own broadcast... ignored."
Esempio n. 11
0
    def handle(self):
        data = self.request[0]
        inData = self.request[0].strip()
        cSocket = self.request[1]
        curThread = threading.current_thread()
        if not self.client_address[0] in netutil.ip4_addresses():
            result, msg = interpreter.interpret(data, self.client_address[0])

            if result == SERVER_REQUEST:
                freeSpace = self.FreeDiskSpace()
                responseData = messages.getMessage(
                    SERVER_REQUEST_ACKNOWLEDGE, [
                        "-i",
                        str(TYPE_RASPMEDIA_PLAYER), "-i", "0", "-s",
                        str(configtool.readConfig()['player_name']), "-i",
                        str(freeSpace[0]), "-i",
                        str(freeSpace[1])
                    ])
                addr = (self.client_address[0], UDP_PORT)
                print "Sending response to client:"
                print(addr)
                if cSocket.sendto(responseData, addr):
                    print "Response sent!"
                else:
                    print "Sending response failed!"
            elif result == FILELIST_REQUEST:
                files = mediaplayer.getMediaFileList()
                args = ['-i', str(len(files))]
                for file in files:
                    args.append('-s')
                    args.append(file)
                responseData = messages.getMessage(FILELIST_RESPONSE, args)
                if cSocket.sendto(responseData,
                                  (self.client_address[0], UDP_PORT)):
                    print "Filelist sent!"
            elif result == CONFIG_REQUEST:
                responseData = messages.getConfigMessage()
                if cSocket.sendto(responseData,
                                  (self.client_address[0], UDP_PORT)):
                    print "Config sent!"
            elif result == GROUP_CONFIG_REQUEST:
                response = messages.getGroupConfigMessage()
                if cSocket.sendto(response,
                                  (self.client_address[0], UDP_PORT)):
                    print "Group Config sent!"
            elif result == GROUP_CONFIG_ADD_ACTION:
                configtool.addGroupAction(msg)
                gConf = configtool.readGroupConfig()
                response = messages.getMessage(GROUP_CONFIG_ADD_ACTION)
                if cSocket.sendto(response,
                                  (self.client_address[0], UDP_PORT)):
                    print "Action saved confirmation sent!"
                GroupManager.ReInitGroupManager(gConf)
            elif result == GROUP_CONFIG_ACTION_DELETE:
                configtool.deleteGroupAction(msg)
                gConf = configtool.readGroupConfig()
                response = messages.getMessage(GROUP_CONFIG_ACTION_DELETE)
                if cSocket.sendto(response,
                                  (self.client_address[0], UDP_PORT)):
                    print "Action deleted confirmation sent!"
                GroupManager.ReInitGroupManager(gConf)
            elif result == PLAYER_UPDATE_ERROR:
                responseData = messages.getMessage(PLAYER_UPDATE_ERROR,
                                                   ["-s", str(msg)])
                cSocket.sendto(responseData,
                               (self.client_address[0], UDP_PORT))
            elif result == FILE_DATA_REQUEST:
                # send images from player over tcp to host in separate thread to not block other udp handling
                t = threading.Thread(target=self.SendImagesOverTCP,
                                     args=[self.client_address[0]])
                t.daemon = True
                t.start()
            elif result == DISK_INFO_REQUEST:
                freeSpace = self.FreeDiskSpace()
                responseData = messages.getMessage(
                    DISK_INFO_REQUEST,
                    ["-i", str(freeSpace[0]), "-i",
                     str(freeSpace[1])])
                addr = (self.client_address[0], UDP_PORT)
                if cSocket.sendto(responseData, addr):
                    print "Disk Info sent!"
                else:
                    print "Sending disk info failed!"
        else:
            print "Received own broadcast... ignored."
Esempio n. 12
0
 def reloadConfig(self):
     self.config = configtool.readConfig()