Esempio n. 1
0
    def parse_element(self, element, uri=None):
        Element.parse_element(self, element, uri)
        # Extract Loop attribute
        try:
            loop = int(self.extract_attribute_value("loop", 1))
        except ValueError:
            loop = 1
        if loop < 0:
            raise RESTFormatException("Play 'loop' must be a positive integer or 0")
        self.loop_times = loop
        # Pull out the text within the element
        audio_path = element.text.strip()

        if not audio_path:
            raise RESTFormatException("No File to play set !")

        if not is_valid_url(audio_path):
            if file_exists(audio_path):
                self.sound_file_path = audio_path
        else:
            if url_exists(audio_path):
                if audio_path[-4:].lower() != '.mp3':
                    raise RESTFormatException("Only mp3 files allowed for remote file play")
                if audio_path[:7].lower() == "http://":
                    audio_path = audio_path[7:]
                elif audio_path[:8].lower() == "https://":
                    audio_path = audio_path[8:]
                elif audio_path[:6].lower() == "ftp://":
                    audio_path = audio_path[6:]
                else:
                    pass
                self.sound_file_path = "shout://%s" % audio_path
Esempio n. 2
0
    def parse_grammar(self, element, uri=None):
        Grammar.parse_grammar(self, element, uri)

        # Extract Loop attribute
        loop = int(self.extract_attribute_value("loop"))
        if loop < 0:
            raise RESTFormatException("Play loop must be a positive integer")
        self.loop_times = loop
        # Pull out the text within the element
        audio_path = element.text.strip()

        if audio_path is None:
            raise RESTFormatException("No File for play given!")

        if not is_valid_url(audio_path):
            if file_exists(audio_path):
                self.sound_file_path = audio_path
        else:
            if url_exists(audio_path):
                if audio_path[-4:].lower() != '.mp3':
                    error_msg = "Only mp3 files allowed for remote file play"
                    print error_msg
                if audio_path[:7].lower() == "http://":
                    audio_path = audio_path[7:]
                elif audio_path[:8].lower() == "https://":
                    audio_path = audio_path[8:]
                elif audio_path[:6].lower() == "ftp://":
                    audio_path = audio_path[6:]
                else:
                    pass
                self.sound_file_path = "shout://%s" % audio_path
Esempio n. 3
0
 def _prepare_moh(self):
     mohs = []
     if not self.dial_music:
         return mohs
     for audio_path in self.dial_music.split(','):
         if not is_valid_url(audio_path):
             if file_exists(audio_path):
                 mohs.append(audio_path)
         else:
             if url_exists(audio_path):
                 if audio_path[-4:].lower() != '.mp3':
                     raise RESTFormatException("Only mp3 files allowed for remote file play")
                 if audio_path[:7].lower() == "http://":
                     audio_path = audio_path[7:]
                 elif audio_path[:8].lower() == "https://":
                     audio_path = audio_path[8:]
                 elif audio_path[:6].lower() == "ftp://":
                     audio_path = audio_path[6:]
                 else:
                     pass
                 mohs.append("shout://%s" % audio_path)
     return mohs