Modifing filename building + pathname definition.
authorDavid Testé <soonum@gnu.org>
Mon, 14 Mar 2016 15:54:29 +0000 (16:54 +0100)
committerDavid Testé <soonum@gnu.org>
Mon, 14 Mar 2016 15:54:29 +0000 (16:54 +0100)
Cleaning code

stream_2016/abyss.py
stream_2016/gstconf.py

index bade6d6..e592403 100755 (executable)
@@ -308,6 +308,8 @@ class Streamgui(object):
 ##                    print('RAWFILENAME: ', raw_filename, ' <--')  # [DEBUG]
             elif streamfailed:
                 self.pipel.set_filenames(raw_filename, streamfailed=True)
+            else:
+                self.pipel.set_filenames(raw_filename,)
             return True
         elif not streamfailed:
             self.entryfield_info.run()
index f183b83..115c2d0 100755 (executable)
@@ -22,6 +22,7 @@
 from os import rename
 from os import listdir
 from os import path
+from os import mkdir
 from time import localtime, strftime
 import configparser
 
@@ -29,10 +30,10 @@ import gi
 from gi.repository import Gst
 from gi.repository import GstVideo
 
-# Pathname has to be defined
-AUDIO_DEFAULT = 'AUDIO_DEFAULT'
-RAWVIDEO_DEFAULT = 'RAWVIDEO_DEFAULT'
-STREAM_DEFAULT = 'STREAM_DEFAULT'
+DIR_NAME = 'FILES_RECORDED'
+AUDIO_DEFAULT = './' + DIR_NAME + '/' + 'AUDIO_DEFAULT'
+RAWVIDEO_DEFAULT = './' + DIR_NAME + '/' + 'RAWVIDEO_DEFAULT'
+STREAM_DEFAULT = './' + DIR_NAME + '/' + 'STREAM_DEFAULT'
 BACKUP_SUFFIX = '_BACKUP'
 FAILED_SUFFIX = '_FAILED_'
 fail_counter = 1
@@ -68,6 +69,8 @@ if path.exists(CONFIG):
 else:
     print(ERROR, gettime(), '".abyss" config file doesn\'t exist.')
 
+if not path.isdir(DIR_NAME):
+    mkdir(DIR_NAME)
 
 class New_user_pipeline():
 
@@ -131,7 +134,6 @@ class New_user_pipeline():
     def create_filesink(self):
         """Create storable output elements."""
         self.disksink_rawvideo = Gst.ElementFactory.make('filesink')
-        #[TO DO]: File location has to be defined 
         self.disksink_rawvideo.set_property('location', RAWVIDEO_DEFAULT)
         self.disksink_audio = Gst.ElementFactory.make('filesink')
         self.disksink_audio.set_property('location', AUDIO_DEFAULT)
@@ -154,16 +156,16 @@ class New_user_pipeline():
         # To icecast server:
         self.icecastsink_audio = Gst.ElementFactory.make('shout2send', 'icecastsink_audio')
         self.icecastsink_audio.set_property('sync', False)
-        self.icecastsink_audio.set_property('ip', sinks['STREAM_SERVER_IP']) #'live2.fsf.org')
+        self.icecastsink_audio.set_property('ip', sinks['STREAM_SERVER_IP'])
         self.icecastsink_audio.set_property('port', int(sinks['SERVER_PORT']))
-        self.icecastsink_audio.set_property('mount', sinks['AUDIO_MOUNT'])# 'testaudio.ogg')
-        self.icecastsink_audio.set_property('password', sinks['PASSWORD'])#'thahw3Wiez')
+        self.icecastsink_audio.set_property('mount', sinks['AUDIO_MOUNT'])
+        self.icecastsink_audio.set_property('password', sinks['PASSWORD'])
         self.icecastsink_stream = Gst.ElementFactory.make('shout2send', 'icecastsink_stream')
         self.icecastsink_stream.set_property('sync', False)
-        self.icecastsink_stream.set_property('ip', sinks['STREAM_SERVER_IP'])#'live2.fsf.org')
-        self.icecastsink_stream.set_property('port', int(sinks['SERVER_PORT']))#80)
-        self.icecastsink_stream.set_property('mount', sinks['VIDEO_MOUNT'])#'teststream.webm')
-        self.icecastsink_stream.set_property('password', sinks['PASSWORD'])#'thahw3Wiez')
+        self.icecastsink_stream.set_property('ip', sinks['STREAM_SERVER_IP'])
+        self.icecastsink_stream.set_property('port', int(sinks['SERVER_PORT']))
+        self.icecastsink_stream.set_property('mount', sinks['VIDEO_MOUNT'])
+        self.icecastsink_stream.set_property('password', sinks['PASSWORD'])
 
     def create_payloader_elements(self):
         pass
@@ -450,49 +452,48 @@ class New_user_pipeline():
         self.streampipe.set_state(Gst.State.PLAYING)
         if self.feed == 'backup':
             print(WARN, gettime(), 'Backup pipeline started.')
-        print(INFO, gettime(), 'PLAYING State resquested')
+        print(INFO, gettime(), 'PLAYING State resquested.')
         
     def stream_stop(self):
         self.streampipe.set_state(Gst.State.NULL)
-        print(INFO, gettime(), 'STOPPED State resquested')
+        print(INFO, gettime(), 'STOPPED State resquested.')
         
     def set_filenames(self, string, streamfailed=False):
         """Sets filename and location for each sink."""
         global fail_counter
         filename = string
-        audio = sources['DIR'] + filename + '_AUDIO'
-        rawvideo = sources['DIR'] + filename + '_RAWVIDEO'
-        stream = sources['DIR'] + filename + '_STREAM'
-        print('FEED STATE: ', self.feed) 
+        audio = './' + DIR_NAME + '/' + filename + '_AUDIO'
+        rawvideo = './' + DIR_NAME + '/' + filename + '_RAWVIDEO'
+        stream = './' + DIR_NAME + '/' + filename + '_STREAM'
         if self.feed == 'main':
             if streamfailed and filename:
                 audio = audio + FAILED_SUFFIX + str(fail_counter)
                 rawvideo = rawvideo + FAILED_SUFFIX + str(fail_counter)
                 stream = stream + FAILED_SUFFIX + str(fail_counter)
-                rename(AUDIO_DEFAULT, audio)
-                rename(RAWVIDEO_DEFAULT, rawvideo)
-                rename(STREAM_DEFAULT, stream)
+                self.rename_files(audio, rawvideo, stream)
                 fail_counter += 1
             elif streamfailed:
                 audio = AUDIO_DEFAULT + FAILED_SUFFIX + str(fail_counter)
                 rawvideo = RAWVIDEO_DEFAULT + FAILED_SUFFIX + str(fail_counter)
                 stream = STREAM_DEFAULT + FAILED_SUFFIX + str(fail_counter)
-                rename(AUDIO_DEFAULT, audio)
-                rename(RAWVIDEO_DEFAULT, rawvideo)
-                rename(STREAM_DEFAULT, stream)
+                self.rename_files(audio, rawvideo, stream)
                 fail_counter += 1
             else:
-                rename(AUDIO_DEFAULT, audio)
-                rename(RAWVIDEO_DEFAULT, rawvideo)
-                rename(STREAM_DEFAULT, stream)
+                self.rename_files(audio, rawvideo, stream)
         elif self.feed == 'backup':
-            print('INSIDE BACKUP RENAMING')
+##            print('INSIDE BACKUP RENAMING')
             rename(AUDIO_BACKUP, audio)
             rename(RAWVIDEO_BACKUP, rawvideo)
             rename(STREAM_BACKUP, stream)
 
-        def rename_files():
-            pass
+        print(INFO, gettime(), 'Audio file written on disk.')
+        print(INFO, gettime(), 'Raw video file written on disk.')
+        print(INFO, gettime(), 'Streamed file written on disk.')
+        
+    def rename_files(self, audio_name, rawvideo_name, stream_name):
+        rename(AUDIO_DEFAULT, audio_name)
+        rename(RAWVIDEO_DEFAULT, rawvideo_name)
+        rename(STREAM_DEFAULT, stream_name)
 
 def get_gstreamer_bus():
     return bus