Esempio n. 1
0
class VLC:
    def __init__(self, active_video_file, idle_video_file):
        self.active_video_file = active_video_file
        self.idle_video_file = idle_video_file
        self.vlc = VLCClient("::1")
        subprocess.Popen("vlc --intf telnet --telnet-pass admin",
                         shell=True,
                         stdout=subprocess.PIPE)
        time.sleep(2)
        self.vlc.connect()

    def play_active(self):
        self._play_videofile(self.active_video_file)

    def play_idle_video(self):
        self.vlc.add(self.idle_video_file)
        # self.vlc.loop()
        self.vlc.set_fullscreen(True)

    def enqueue_idle_video(self):
        self.vlc.enqueue(self.idle_video_file)

    def rewind_video(self):
        self.vlc.rewind()

    def _play_videofile(self, videofile, loop=False):
        print('Now playing videofile', videofile)
        self.vlc.add(videofile)
        self.vlc.set_fullscreen(True)
Esempio n. 2
0
import time
from vlcclient import VLCClient

stream = "http://nhkwglobal-i.akamaihd.net/hls/live/222714/nhkwglobal/index_1180.m3u8"

sleepdelay = 3

vlc = VLCClient("::1")
vlc.connect()

print "connected to vlc ", vlc.server_version

print "adding stream", stream
print vlc.add(stream)

print "sleeping", sleepdelay
time.sleep(sleepdelay)

print "snapshot 1"
print vlc.snapshot()

print "sleeping", sleepdelay
time.sleep(sleepdelay)

print "snapshot 2"
print vlc.snapshot()

print "sleeping", sleepdelay
time.sleep(sleepdelay)

print "snapshot 3"
Esempio n. 3
0
from vlcclient import VLCClient


stream = "http://nhkwglobal-i.akamaihd.net/hls/live/222714/nhkwglobal/index_1180.m3u8"

sleepdelay = 3

vlc = VLCClient("::1")
vlc.connect()


print "connected to vlc ", vlc.server_version


print "adding stream", stream
print vlc.add(stream)


print "sleeping", sleepdelay
time.sleep(sleepdelay)


print "snapshot 1"
print vlc.snapshot()

print "sleeping", sleepdelay
time.sleep(sleepdelay)


print "snapshot 2"
print vlc.snapshot()
Esempio n. 4
0
class PlayerCtl:
    """
    VLC Media Player controller. This class contains the logic to interact
    with vlcclient and manage current playlist and status.
    """

    # TODO: play/pause syncronisation with VLC
    # TODO: MP3 tag access

    def __init__(self, startVol=70):

        self.vlc = VLCClient("::1")
        # VLC connection for monitoring thread to avoid multiple telnet send commands
        # at the same time, i.e. when user is changing songs while check is in
        # progress. This scenario would cause a telnet timeout and crash
        self.vlc_monitoring = VLCClient("::1")

        self.current_playing = ""
        self.current_playing_from_vlc = ""
        self.current_vlc_playlist_id = 4 - 1  # The Vlc playlist index starts with 4
        self.vlc_is_playing = ""
        self.next_playing = []
        self.thread_stopper = False

        try:
            self.vlc.connect(
            )  # Esthablishing a connection via VLCClient class
            self.vlc_monitoring.connect(
            )  # Seperate connection for monitoring thread
            logger.disp_log_entry("info", "connected to vlc media player")
        except ConnectionRefusedError:
            # TODO: Further error handling
            logger.error("Connection to vlc could not be established!")

        self.volume(startVol)  # Setting start value from config
        self.start_monitoring_thread()

    def _monitoring_thread(self):

        time.sleep(0.5)
        self.current_playing_from_vlc = self.get_vlc_internal_current_title()
        while not self.thread_stopper:
            try:  # Fixing inconsistency in Vlc playback status
                if self.current_playing_from_vlc != self.get_vlc_internal_current_title() \
                   and int(self.get_vlc_is_currently_playing()) == 1:
                    # Playing title has changed
                    if self.next_playing:  # If Playlist is not empty
                        self.current_playing = self.next_playing.pop(0)
                        self.delete_from_vlc_playlist(
                            self.current_vlc_playlist_id)
                        self.current_vlc_playlist_id = self.current_vlc_playlist_id + 1

                    self.current_playing_from_vlc = self.get_vlc_internal_current_title(
                    )
                    logger.disp_log_entry(
                        "playlist", "Now playing: " +
                        self.get_clean_title(self.current_playing))

                if int(self.get_vlc_is_currently_playing()
                       ) == 0 and not self.next_playing:
                    # Playback is stopped and playlist is empty
                    self.current_playing = ""
                    self.delete_from_vlc_playlist(self.current_vlc_playlist_id)

            except ValueError:
                # TODO: This might be fixed with second vlc connection thread
                logger.warning("Inconsistency in VLC output detected")
                logger.warning("Playlist might be asynchronous!")

            self.vlc_is_playing = self.get_vlc_is_currently_playing()

            time.sleep(0.1)

    def start_monitoring_thread(self):
        """
        Starts the monitoring thread
        """
        Thread(target=self._monitoring_thread).start()

    def stop_monitoring_thread(self):
        """
        Stops the monitoring thread
        """
        self.thread_stopper = True

    def add(self, filepath):
        """
        Adds and plays the given file to the playlist
        """
        self.vlc.add(filepath)
        self.current_playing = filepath
        self.next_playing.insert(0, self.current_playing)
        self.vlc_is_playing = self.get_vlc_is_currently_playing()

    def enqueue(self, filepath):
        """
        Adds the given file to the end of the playlist
        """
        self.vlc.enqueue(filepath)
        self.next_playing.append(filepath)
        logger.disp_log_entry(
            "playlist", "Added to queue: " + self.get_clean_title(filepath))

    def next(self):
        """
        Plays the next title in the playlist
        """
        self.vlc.next()

    def skip(self, amount):
        """
        Skips a given amount of titles
        """
        for i in range(0, amount):
            self.next()
            time.sleep(0.5)  # FIXME: Direct access to playlist

    def volume(self, vol):
        """
        Sets the volume to the given input
        """
        self.vlc.volume(vol)
        logger.disp_log_entry("info", "setting volume to " + str(vol))

    def volup(self):
        """
        Increases the volume by 10 percent
        """
        self.vlc.volup()
        logger.disp_log_entry("info", "raising volume")

    def voldown(self):
        """
        Lowers the volume by 10 percent
        """
        self.vlc.voldown()
        logger.disp_log_entry("info", "lowering volume")

    def stop(self):
        """
        Stops the playback
        """
        self.vlc.stop()

    def clear(self):
        """
        Clears the playlist
        """
        self.vlc.clear()
        self.next_playing = []
        self.current_playing = None
        logger.disp_log_entry("warning", "cleared playlist")

    def shutdown(self):
        """
        Terminates VLC and the title monitoring Thread
        """
        self.vlc.raw("shutdown")
        self.stop_monitoring_thread()
        logger.disp_log_entry("info", "Shutting down vlc client")

    def raw(self, command):
        """
        Executes a raw telnet command
        """
        self.vlc.raw(command)

    def get_volume(self):
        """
        Returns the current playback volume
        """
        current_volume = float(self.vlc.volume().decode("utf-8").replace(
            ",", "."))
        while current_volume == 1.0:  # Fix for inconsistent vlc output
            current_volume = float(self.vlc.volume().decode("utf-8").replace(
                ",", "."))
        return current_volume

    def get_vlc_internal_current_title(self):
        """
        Returns the internal name of the current playing title
        """
        return self.vlc_monitoring.raw("get_title")

    def get_vlc_is_currently_playing(self):
        """
        Returns 1 when playing, 0 when not
        """
        return self.vlc_monitoring.raw("is_playing")

    def delete_from_vlc_playlist(self, trackid):
        """
        Deletes the Song with the given id from VLC internal playlist
        """
        self.vlc_monitoring.raw("delete " + str(trackid))

    def get_current_playing(self):
        """
        Returns the current title in a formatted form
        """
        return self.get_clean_title(self.current_playing)

    def get_playlist(self):
        """
        Returns the current playlist
        """
        returnlist = self.next_playing
        # returnlist.insert(0,self.currentPlaying)
        return returnlist

    def get_clean_title(self, filepath):
        """
        Returns the clean title of a given filepath
        """
        # TODO: Add Mp3-Tag reader instead of using file names
        if filepath != "":
            return filepath.split("/")[-1].split(".")[-2].strip()
        else:
            return ""