import logging
import re

from gi.repository import Gst

from lib.config import Config
from lib.sources.avsource import AVSource


class VideoLoopSource(AVSource):
    def __init__(self, name):
        super().__init__('VideoLoopSource', name, False, True)
        self.location = Config.getLocation(name)
        self.build_pipeline()

    def __str__(self):
        return 'VideoLoopSource[{name}] displaying {location}'.format(
            name=self.name,
            location=self.location
        )

    def port(self):
        m = re.search('.*/([^/]*)', self.location)
        return self.location

    def num_connections(self):
        return 1

    def video_channels(self):
        return 1

    def build_source(self):
        return """
             multifilesrc
                name=videoloop-{name}
               location={location}
               loop=true
            ! decodebin
            ! videoconvert
            ! videoscale
                name=videoloop
            """.format(
            name=self.name,
            location=self.location
        )

    def build_videoport(self):
        return 'videoloop.'

    def build_audioport(self, audiostream):
        return 'audioloop.'

import logging
import re

from gi.repository import Gst

from lib.config import Config
from lib.sources.avsource import AVSource


class VideoLoopSource(AVSource):
    timer_resolution = 0.5

    def __init__(self, name, has_audio=True, has_video=True,
                 force_num_streams=None):
        super().__init__('VideoLoopSource', name, has_audio, has_video, show_no_signal=True)
        self.location = Config.getLocation(name)
        self.build_pipeline()

    def __str__(self):
        return 'VideoLoopSource[{name}] displaying {location}'.format(
            name=self.name,
            location=self.location
        )

    def port(self):
        m = re.search('.*/([^/]*)', self.location)
        return self.location

    def num_connections(self):
        return 1

    def video_channels(self):
        return 1

    def build_source(self):
        return """
             multifilesrc
               location={location}
               loop=true
            ! decodebin
               name=videoloop-{name}
            """.format(
            name=self.name,
            location=self.location
        )

    def build_videoport(self):
        return """
              videoloop-{name}.
            ! videoconvert
            ! videoscale
            """.format(name=self.name)

    def build_audioport(self):
        return """
              videoloop-{name}.
            ! audioconvert
            ! audioresample
            """.format(name=self.name)
Modify videoloop to allow for audio
Modify videoloop to allow for audio

  import logging
  import re
  
  from gi.repository import Gst
  
  from lib.config import Config
  from lib.sources.avsource import AVSource
  
  
  class VideoLoopSource(AVSource):
-     def __init__(self, name):
-         super().__init__('VideoLoopSource', name, False, True)
+     timer_resolution = 0.5
+ 
+     def __init__(self, name, has_audio=True, has_video=True,
+                  force_num_streams=None):
+         super().__init__('VideoLoopSource', name, has_audio, has_video, show_no_signal=True)
          self.location = Config.getLocation(name)
          self.build_pipeline()
  
      def __str__(self):
          return 'VideoLoopSource[{name}] displaying {location}'.format(
              name=self.name,
              location=self.location
          )
  
      def port(self):
          m = re.search('.*/([^/]*)', self.location)
          return self.location
  
      def num_connections(self):
          return 1
  
      def video_channels(self):
          return 1
  
      def build_source(self):
          return """
               multifilesrc
-                 name=videoloop-{name}
                 location={location}
                 loop=true
              ! decodebin
-             ! videoconvert
-             ! videoscale
-                 name=videoloop
+                name=videoloop-{name}
              """.format(
              name=self.name,
              location=self.location
          )
  
      def build_videoport(self):
-         return 'videoloop.'
+         return """
+               videoloop-{name}.
+             ! videoconvert
+             ! videoscale
+             """.format(name=self.name)
  
-     def build_audioport(self, audiostream):
+     def build_audioport(self):
-         return 'audioloop.'
- 
+         return """
+               videoloop-{name}.
+             ! audioconvert
+             ! audioresample
+             """.format(name=self.name)
Modify videoloop to allow for audio
## Code Before:
import logging
import re

from gi.repository import Gst

from lib.config import Config
from lib.sources.avsource import AVSource


class VideoLoopSource(AVSource):
    def __init__(self, name):
        super().__init__('VideoLoopSource', name, False, True)
        self.location = Config.getLocation(name)
        self.build_pipeline()

    def __str__(self):
        return 'VideoLoopSource[{name}] displaying {location}'.format(
            name=self.name,
            location=self.location
        )

    def port(self):
        m = re.search('.*/([^/]*)', self.location)
        return self.location

    def num_connections(self):
        return 1

    def video_channels(self):
        return 1

    def build_source(self):
        return """
             multifilesrc
                name=videoloop-{name}
               location={location}
               loop=true
            ! decodebin
            ! videoconvert
            ! videoscale
                name=videoloop
            """.format(
            name=self.name,
            location=self.location
        )

    def build_videoport(self):
        return 'videoloop.'

    def build_audioport(self, audiostream):
        return 'audioloop.'

## Instruction:
Modify videoloop to allow for audio
## Code After:
import logging
import re

from gi.repository import Gst

from lib.config import Config
from lib.sources.avsource import AVSource


class VideoLoopSource(AVSource):
    timer_resolution = 0.5

    def __init__(self, name, has_audio=True, has_video=True,
                 force_num_streams=None):
        super().__init__('VideoLoopSource', name, has_audio, has_video, show_no_signal=True)
        self.location = Config.getLocation(name)
        self.build_pipeline()

    def __str__(self):
        return 'VideoLoopSource[{name}] displaying {location}'.format(
            name=self.name,
            location=self.location
        )

    def port(self):
        m = re.search('.*/([^/]*)', self.location)
        return self.location

    def num_connections(self):
        return 1

    def video_channels(self):
        return 1

    def build_source(self):
        return """
             multifilesrc
               location={location}
               loop=true
            ! decodebin
               name=videoloop-{name}
            """.format(
            name=self.name,
            location=self.location
        )

    def build_videoport(self):
        return """
              videoloop-{name}.
            ! videoconvert
            ! videoscale
            """.format(name=self.name)

    def build_audioport(self):
        return """
              videoloop-{name}.
            ! audioconvert
            ! audioresample
            """.format(name=self.name)