コード例 #1
0
ファイル: cast.py プロジェクト: guigeek208/mkchromecast
 def get_cc(self):
     if self.debug == True:
         print('def get_cc(self):')
     try:
         if self.ccname != None:
             self.cast_to = self.ccname
         self.cast = self._get_chromecast(self.cast_to)
         # Wait for cast device to be ready
         self.cast.wait()
         print(' ')
         print(colors.important('Information about ')+' '+colors.success(self.cast_to))
         print(' ')
         print(self.cast.device)
         print(' ')
         print(colors.important('Status of device ')+' '+colors.success(self.cast_to))
         print(' ')
         print(self.cast.status)
         print(' ')
     except pychromecast.error.NoChromecastFoundError:
         print(colors.error('No Chromecasts matching filter critera were found!'))
         if self.platform == 'Darwin':
             inputint()
             outputint()
         elif self.platform == 'Linux':
             from mkchromecast.pulseaudio import remove_sink
             remove_sink()
         if self.tray == False:  # In the case that the tray is used, we don't kill the application
             print(colors.error('Finishing the application...'))
             terminate()
             exit()
         else:
             self.stop_cast()
コード例 #2
0
ファイル: messages.py プロジェクト: sprig/mkchromecast
def print_available_devices(list_of_devices):
    """docstring for print_available_devices"""
    print(colors.important('List of Devices Available in Network:'))
    print(colors.important('-------------------------------------\n'))
    print(colors.important('Index   Types   Friendly Name '))
    print(colors.important('=====   =====   ============= '))
    for device in list_of_devices:
        device_index = device[0]
        device_name = device[1]
        device_type = device[2]
        print('%s \t%s \t%s' % (device_index, device_type, device_name))
コード例 #3
0
ファイル: messages.py プロジェクト: muammar/mkchromecast
def print_available_devices(list_of_devices):
    """docstring for print_available_devices"""
    print(colors.important('List of Devices Available in Network:'))
    print(colors.important('-------------------------------------\n'))
    print(colors.important('Index   Types   Friendly Name '))
    print(colors.important('=====   =====   ============= '))
    for device in list_of_devices:
        device_index = device[0]
        device_name = device[1]
        device_type = device[2]
        print('%s \t%s \t%s' % ( device_index, device_type, device_name))
コード例 #4
0
def print_available_devices(list_of_devices):
    """docstring for print_available_devices"""
    print(colors.important("List of Devices Available in Network:"))
    print(colors.important("-------------------------------------\n"))
    print(colors.important("Index   Types   Friendly Name "))
    print(colors.important("=====   =====   ============= "))
    for device in list_of_devices:
        device_index = device[0]
        device_name = device[1]
        device_type = device[2]
        print("%s \t%s \t%s" % (device_index, device_type, device_name))
コード例 #5
0
ファイル: mkchromecast.py プロジェクト: xmbwd/mkchromecast
 def controls_msg(self):
     """Messages shown when controls is True"""
     print('')
     print(colors.important('Controls:'))
     print(colors.important('========='))
     print('')
     print(colors.options('Volume Up:') + ' u')
     print(colors.options('Volume Down:') + ' d')
     if videoarg == True:
         print(colors.options('Pause Casting:') + ' p')
         print(colors.options('Resume Casting:') + ' r')
     print(colors.options('Quit the Application:') + ' q or Ctrl-C')
     print('')
コード例 #6
0
 def get_devices(self):
     if self.debug is True:
         print("def get_devices(self):")
     if chromecast:
         try:
             if self.device_name is not None:
                 self.cast_to = self.device_name
             self.cast = self._get_chromecast(self.cast_to)
             # Wait for cast device to be ready
             self.cast.wait()
             print(" ")
             print(
                 colors.important("Information about ")
                 + " "
                 + colors.success(self.cast_to)
             )
             print(" ")
             print(self.cast.device)
             print(" ")
             print(
                 colors.important("Status of device ")
                 + " "
                 + colors.success(self.cast_to)
             )
             print(" ")
             print(self.cast.status)
             print(" ")
         except pychromecast.error.NoChromecastFoundError:
             print(
                 colors.error(
                     "No Chromecasts matching filter criteria" " were found!"
                 )
             )
             if self.platform == "Darwin":
                 inputint()
                 outputint()
             elif self.platform == "Linux":
                 remove_sink()
             # In the case that the tray is used, we don't kill the
             # application
             if self.tray is False:
                 print(colors.error("Finishing the application..."))
                 terminate()
                 exit()
             else:
                 self.stop_cast()
         except AttributeError:
             pass
         except KeyError:
             pass
コード例 #7
0
ファイル: mkchromecast.py プロジェクト: xmbwd/mkchromecast
    def audio_linux(self):
        """This method manages all related to casting audio in Linux"""
        if self.youtubeurl == None and self.source_url == None:
            if adevice == None:
                print('Creating Pulseaudio Sink...')
                print(
                    colors.warning(
                        'Open Pavucontrol and Select the Mkchromecast Sink.'))
                create_sink()
            print(colors.important('Starting Local Streaming Server'))
            print(colors.success('[Done]'))
            self.start_backend(self.encoder_backend)
            self.cc.initialize_cast()
            self.get_cc(self.select_cc)
            self.cc.play_cast()
            self.show_control(self.control)

        elif self.youtubeurl == None and self.source_url != None:
            self.start_backend(self.encoder_backend)
            self.cc.initialize_cast()
            self.get_cc(self.select_cc)
            self.cc.play_cast()
            self.show_control(self.control)

        elif youtubeurl != None and self.videoarg == False:  # When casting youtube url, we do it through the audio module
            import mkchromecast.audio
            mkchromecast.audio.main()
            self.cc.initialize_cast()
            self.get_cc(self.select_cc)
            self.cc.play_cast()
            self.show_control(self.control)
コード例 #8
0
 def select_a_device(self):
     print(" ")
     print(
         "Please, select the "
         + colors.important("Index")
         + " of the Google Cast device that you want to use:"
     )
     self.index = input()
コード例 #9
0
ファイル: mkchromecast.py プロジェクト: xmbwd/mkchromecast
 def cast_video(self):
     """This method launches video casting"""
     print(colors.important('Starting Video Cast Process...'))
     import mkchromecast.video
     mkchromecast.video.main()
     self.cc.initialize_cast()
     self.get_cc(self.select_cc)
     self.cc.play_cast()
     self.show_control(self.control)
コード例 #10
0
ファイル: cast.py プロジェクト: xenoxaos/mkchromecast
 def get_cc(self):
     if self.debug is True:
         print('def get_cc(self):')
     if chromecast:
         try:
             if self.ccname is not None:
                 self.cast_to = self.ccname
             self.cast = self._get_chromecast(self.cast_to)
             # Wait for cast device to be ready
             self.cast.wait()
             print(' ')
             print(colors.important('Information about ') + ' ' +
                   colors.success(self.cast_to))
             print(' ')
             print(self.cast.device)
             print(' ')
             print(colors.important('Status of device ') + ' ' +
                   colors.success(self.cast_to))
             print(' ')
             print(self.cast.status)
             print(' ')
         except pychromecast.error.NoChromecastFoundError:
             print(colors.error('No Chromecasts matching filter criteria'
                                ' were found!'))
             if self.platform == 'Darwin':
                 inputint()
                 outputint()
             elif self.platform == 'Linux':
                 remove_sink()
             # In the case that the tray is used, we don't kill the
             # application
             if self.tray is False:
                 print(colors.error('Finishing the application...'))
                 terminate()
                 exit()
             else:
                 self.stop_cast()
         except AttributeError:
             pass
         except KeyError:
             pass
コード例 #11
0
ファイル: cast.py プロジェクト: muammar/mkchromecast
 def get_devices(self):
     if self.debug is True:
         print('def get_devices(self):')
     if chromecast:
         try:
             if self.device_name is not None:
                 self.cast_to = self.device_name
             self.cast = self._get_chromecast(self.cast_to)
             # Wait for cast device to be ready
             self.cast.wait()
             print(' ')
             print(colors.important('Information about ') + ' ' +
                   colors.success(self.cast_to))
             print(' ')
             print(self.cast.device)
             print(' ')
             print(colors.important('Status of device ') + ' ' +
                   colors.success(self.cast_to))
             print(' ')
             print(self.cast.status)
             print(' ')
         except pychromecast.error.NoChromecastFoundError:
             print(colors.error('No Chromecasts matching filter criteria'
                                ' were found!'))
             if self.platform == 'Darwin':
                 inputint()
                 outputint()
             elif self.platform == 'Linux':
                 remove_sink()
             # In the case that the tray is used, we don't kill the
             # application
             if self.tray is False:
                 print(colors.error('Finishing the application...'))
                 terminate()
                 exit()
             else:
                 self.stop_cast()
         except AttributeError:
             pass
         except KeyError:
             pass
コード例 #12
0
def del_tmp():
    """Delete files created in /tmp/"""
    delete_me = ["/tmp/mkchromecast.tmp", "/tmp/mkchromecast.pid"]

    print(colors.important("Cleaning up /tmp/..."))

    for f in delete_me:
        if os.path.exists(f) is True:
            os.remove(f)

    print(colors.success("[Done]"))
    return
コード例 #13
0
ファイル: utils.py プロジェクト: muammar/mkchromecast
def del_tmp():
    """Delete files created in /tmp/"""
    delete_me = ['/tmp/mkchromecast.tmp', '/tmp/mkchromecast.pid']

    print(colors.important('Cleaning up /tmp/...'))

    for f in delete_me:
        if os.path.exists(f) is True:
            os.remove(f)

    print(colors.success('[Done]'))
    return
コード例 #14
0
def del_tmp():
    """Delete files created in /tmp/"""
    delete_me = ['/tmp/mkchromecast.tmp', '/tmp/mkchromecast.pid']

    print(colors.important('Cleaning up /tmp/...'))

    for f in delete_me:
        if os.path.exists(f) is True:
            os.remove(f)

    print(colors.success('[Done]'))
    return
コード例 #15
0
ファイル: cast.py プロジェクト: jamincollins/mkchromecast
    def initialize_cast(self):
        # This fixes the `No handlers could be found for logger
        # "pychromecast.socket_client` warning"`.
        # See commit 18005ebd4c96faccd69757bf3d126eb145687e0d.
        from pychromecast import socket_client
        self.cclist = self._get_chromecasts()
        self.cclist = [[i, _, 'Gcast'] for i, _ in enumerate(self.cclist)]

        if sonos is True:
            try:
                self.sonos_list = list(soco.discover())
                for self.index, device in enumerate(self.sonos_list):
                    add_sonos = [self.index, device, 'Sonos']
                    self.cclist.append(add_sonos)
            except TypeError:
                pass

        if self.debug is True:
            print('self.cclist', self.cclist)

        if (len(self.cclist) != 0 and self.select_cc is False
                and self.ccname is None):
            if self.debug is True:
                print('if len(self.cclist) != 0 and self.select_cc == False:')
            print(' ')
            print(colors.important('List of Devices Available in Network:'))
            print(colors.important('-------------------------------------\n'))
            print(colors.important('Index   Types   Friendly Name '))
            print(colors.important('=====   =====   ============= '))
            self.availablecc()
            print(' ')
            if self.discover is False:
                print(colors.important('Casting to first device shown above!'))
                print(colors.important('Select devices by using the -s flag.'))
                print(' ')
                self.cast_to = self.cclist[0][1]
                if self.cclist[0][2] == 'Sonos':
                    print(colors.success(self.cast_to.player_name))
                else:
                    print(colors.success(self.cast_to))
                print(' ')

        elif (len(self.cclist) != 0 and self.select_cc is True
              and self.tray is False and self.ccname is None):
            if self.debug is True:
                print('elif len(self.cclist) != 0 and self.select_cc == True'
                      ' and self.tray == False:')
            if os.path.exists('/tmp/mkchromecast.tmp') is False:
                self.tf = open('/tmp/mkchromecast.tmp', 'wb')
                print(' ')
                print(
                    colors.important('List of Devices Available in Network:'))
                print(
                    colors.important(
                        '-------------------------------------\n'))
                print(colors.important('Index   Types   Friendly Name '))
                print(colors.important('=====   =====   ============= '))
                self.availablecc()
            else:
                if self.debug is True:
                    print('else:')
                self.tf = open('/tmp/mkchromecast.tmp', 'rb')
                self.index = pickle.load(self.tf)
                self.cast_to = self.cclist[int(self.index)]
                print(' ')
                print(
                    colors.options('Casting to:') + ' ' +
                    colors.success(self.cast_to))
                print(' ')

        elif (len(self.cclist) != 0 and self.select_cc is True
              and self.tray is True):
            if self.debug is True:
                print('elif len(self.cclist) != 0 and self.select_cc == True'
                      '  and self.tray == True:')
            if os.path.exists('/tmp/mkchromecast.tmp') is False:
                self.tf = open('/tmp/mkchromecast.tmp', 'wb')
                print(' ')
                print(
                    colors.important('List of Devices Available in Network:'))
                print(
                    colors.important(
                        '-------------------------------------\n'))
                print(colors.important('Index   Types   Friendly Name '))
                print(colors.important('=====   =====   ============= '))
                self.availablecc()
            else:
                if self.debug is True:
                    print('else:')
                self.tf = open('/tmp/mkchromecast.tmp', 'rb')
                self.cast_to = pickle.load(self.tf)
                self.availablecc()
                print(' ')
                print(
                    colors.options('Casting to:') + ' ' +
                    colors.success(self.cast_to))
                print(' ')

        elif len(self.cclist) == 0 and self.tray is False:
            if self.debug is True:
                print('elif len(self.cclist) == 0 and self.tray == False:')
            print(colors.error('No devices found!'))
            if self.platform == 'Linux' and self.adevice is None:
                remove_sink()
            elif self.platform == 'Darwin':
                inputint()
                outputint()
            terminate()
            exit()

        elif len(self.cclist) == 0 and self.tray is True:
            print(colors.error(':::Tray::: No devices found!'))
            self.availablecc = []
コード例 #16
0
ファイル: cast.py プロジェクト: muammar/mkchromecast
    def initialize_cast(self):
        # This fixes the `No handlers could be found for logger
        # "pychromecast.socket_client` warning"`.
        # See commit 18005ebd4c96faccd69757bf3d126eb145687e0d.
        if chromecast:
            from pychromecast import socket_client
            self.cclist = self._get_chromecasts()
            self.cclist = [[i, _, 'Gcast'] for i, _ in enumerate(self.cclist)]
        else:
            self.cclist = []

        if sonos:
            try:
                self.sonos_list = list(soco.discover())
                for self.index, device in enumerate(self.sonos_list):
                    add_sonos = [self.index, device, 'Sonos']
                    self.cclist.append(add_sonos)
            except TypeError:
                pass

        if self.debug is True:
            print('self.cclist', self.cclist)

        if (len(self.cclist) != 0 and self.select_device is False and
                self.device_name is None):
            if self.debug is True:
                print('if len(self.cclist) != 0 and self.select_device == False:')
            print(' ')
            print_available_devices(self.available_devices())
            print(' ')
            if self.discover is False:
                print(colors.important('Casting to first device shown above!'))
                print(colors.important('Select devices by using the -s flag.'))
                print(' ')
                self.cast_to = self.cclist[0][1]
                if self.cclist[0][2] == 'Sonos':
                    print(colors.success(self.cast_to.player_name))
                else:
                    print(colors.success(self.cast_to))
                print(' ')

        elif (len(self.cclist) != 0 and self.select_device is True and
                self.tray is False and self.device_name is None):
            if self.debug is True:
                print('elif len(self.cclist) != 0 and self.select_device == True'
                      ' and self.tray == False:')
            if os.path.exists('/tmp/mkchromecast.tmp') is False:
                self.tf = open('/tmp/mkchromecast.tmp', 'wb')
                print(' ')
                print_available_devices(self.available_devices())
            else:
                if self.debug is True:
                    print('else:')
                self.tf = open('/tmp/mkchromecast.tmp', 'rb')
                self.index = pickle.load(self.tf)
                self.cast_to = self.cclist[int(self.index)]
                print(' ')
                print(colors.options('Casting to:') + ' ' +
                      colors.success(self.cast_to))
                print(' ')

        elif (len(self.cclist) != 0 and self.select_device is True and
                self.tray is True):
            if self.debug is True:
                print('elif len(self.cclist) != 0 and self.select_device == True'
                      '  and self.tray == True:')
            if os.path.exists('/tmp/mkchromecast.tmp') is False:
                self.tf = open('/tmp/mkchromecast.tmp', 'wb')
                print(' ')
                print_available_devices(self.available_devices())
            else:
                if self.debug is True:
                    print('else:')
                self.tf = open('/tmp/mkchromecast.tmp', 'rb')
                self.cast_to = pickle.load(self.tf)
                print_available_devices(self.available_devices())
                print(' ')
                print(colors.options('Casting to:') + ' ' +
                      colors.success(self.cast_to))
                print(' ')

        elif len(self.cclist) == 0 and self.tray is False:
            if self.debug is True:
                print('elif len(self.cclist) == 0 and self.tray == False:')
            print(colors.error('No devices found!'))
            if self.platform == 'Linux' and self.adevice is None:
                remove_sink()
            elif self.platform == 'Darwin':
                inputint()
                outputint()
            terminate()
            exit()

        elif len(self.cclist) == 0 and self.tray is True:
            print(colors.error(':::Tray::: No devices found!'))
            self.available_devices = []
コード例 #17
0
ファイル: cast.py プロジェクト: muammar/mkchromecast
    def play_cast(self):
        if self.debug is True:
            print('def play_cast(self):')
        localip = self.ip

        try:
            print(colors.options('The IP of ') +
                  colors.success(self.cast_to) + colors.options(' is:') +
                  ' ' + self.cast.host)
        except TypeError:
            print(colors.options('The IP of ') +
                  colors.success(self.cast_to.player_name) +
                  colors.options(' is:') + ' ' + self.cast_to.ip_address)
        except AttributeError:
            for _ in self.sonos_list:
                if self.cast_to == _.player_name:
                    self.cast_to = _
            print(colors.options('The IP of ') +
                  colors.success(self.cast_to.player_name) +
                  colors.options(' is:') + ' ' + self.cast_to.ip_address)

        if self.host is None:
            print(colors.options('Your local IP is:') + ' ' + localip)
        else:
            print(colors.options('Your manually entered local IP is:') +
                  ' ' + localip)

        try:
            media_controller = self.cast.media_controller

            if self.tray is True:
                config = ConfigParser.RawConfigParser()
                # Class from mkchromecast.config
                from mkchromecast.config import config_manager
                configurations = config_manager()
                configf = configurations.configf

                if os.path.exists(configf) and self.tray is True:
                    print(self.tray)
                    print(colors.warning('Configuration file exists'))
                    print(colors.warning('Using defaults set there'))
                    config.read(configf)
                    self.backend = ConfigSectionMap('settings')['backend']

            if self.source_url is not None:
                if args.video is True:
                    import mkchromecast.video
                    mtype = mkchromecast.video.mtype
                else:
                    import mkchromecast.audio
                    mtype = mkchromecast.audio.mtype
                print(' ')
                print(colors.options('Casting from stream URL:') + ' ' +
                      self.source_url)
                print(colors.options('Using media type:') + ' ' +
                      mtype)
                media_controller.play_media(
                        self.source_url,
                        mtype,
                        title=self.title,
                        stream_type='LIVE'
                        )
                media_controller.play()
            elif (self.backend == 'ffmpeg' or self.backend == 'node' or
                    self.backend == 'avconv' or self.backend == 'parec' or
                    self.backend == 'gstreamer' and self.source_url is None):
                if args.video is True:
                    import mkchromecast.video
                    mtype = mkchromecast.video.mtype
                else:
                    import mkchromecast.audio
                    mtype = mkchromecast.audio.mtype
                print(' ')
                print(colors.options('The media type string used is:') +
                      ' ' + mtype)
                media_controller.play_media(
                        'http://' + localip + ':' + self.port + '/stream',
                        mtype,
                        title=self.title,
                        stream_type='LIVE'
                        )

            if media_controller.is_active:
                import time
                time.sleep(2)
                media_controller.play()

            print(' ')
            print(colors.important('Cast media controller status'))
            print(' ')
            print(self.cast.status)
            print(' ')
            if self.hijack is True:
                self.r = Thread(target=self.hijack_cc)
                # This has to be set to True so that we catch
                # KeyboardInterrupt.
                self.r.daemon = True
                self.r.start()
        except AttributeError:
            self.sonos = self.cast_to
            self.sonos.play_uri('x-rincon-mp3radio://' + localip +
                                ':' + self.port + '/stream',
                                title=self.title)
            if self.tray is True:
                self.cast = self.sonos
コード例 #18
0
ファイル: cast.py プロジェクト: GustavMauler/mkchromecast
    def play_cast(self):
        if self.debug is True:
            print("def play_cast(self):")
        localip = self.ip

        try:
            print(
                colors.options("The IP of ") + colors.success(self.cast_to) +
                colors.options(" is:") + " " + self.cast.host)
        except TypeError:
            print(
                colors.options("The IP of ") +
                colors.success(self.cast_to.player_name) +
                colors.options(" is:") + " " + self.cast_to.ip_address)
        except AttributeError:
            for _ in self.sonos_list:
                if self.cast_to == _.coordinator.player_name:
                    self.cast_to = _
            print(
                colors.options("The IP of ") +
                colors.success(self.cast_to.coordinator.player_name) +
                colors.options(" is:") + " " +
                self.cast_to.coordinator.ip_address)

        if self.host is None:
            print(colors.options("Your local IP is:") + " " + localip)
        else:
            print(
                colors.options("Your manually entered local IP is:") + " " +
                localip)

        try:
            media_controller = self.cast.media_controller

            if self.tray is True:
                config = ConfigParser.RawConfigParser()
                # Class from mkchromecast.config
                from mkchromecast.config import config_manager

                configurations = config_manager()
                configf = configurations.configf

                if os.path.exists(configf) and self.tray is True:
                    print(self.tray)
                    print(colors.warning("Configuration file exists"))
                    print(colors.warning("Using defaults set there"))
                    config.read(configf)
                    self.backend = ConfigSectionMap("settings")["backend"]

            if self.source_url is not None:
                if args.video is True:
                    import mkchromecast.video

                    mtype = mkchromecast.video.mtype
                else:
                    import mkchromecast.audio

                    mtype = mkchromecast.audio.mtype
                print(" ")
                print(
                    colors.options("Casting from stream URL:") + " " +
                    self.source_url)
                print(colors.options("Using media type:") + " " + mtype)
                media_controller.play_media(self.source_url,
                                            mtype,
                                            title=self.title,
                                            stream_type="LIVE")
                media_controller.play()
            elif (self.backend == "ffmpeg" or self.backend == "node"
                  or self.backend == "avconv" or self.backend == "parec"
                  or self.backend == "gstreamer" and self.source_url is None):
                if args.video is True:
                    import mkchromecast.video

                    mtype = mkchromecast.video.mtype
                else:
                    import mkchromecast.audio

                    mtype = mkchromecast.audio.mtype
                print(" ")
                print(
                    colors.options("The media type string used is:") + " " +
                    mtype)
                media_controller.play_media(
                    "http://" + localip + ":" + self.port + "/stream",
                    mtype,
                    title=self.title,
                    stream_type="LIVE",
                )

            if media_controller.is_active:
                media_controller.play()

            print(" ")
            print(colors.important("Cast media controller status"))
            print(" ")
            print(self.cast.status)
            print(" ")

            time.sleep(5.0)
            media_controller.play()

            if self.hijack is True:
                self.r = Thread(target=self.hijack_cc)
                # This has to be set to True so that we catch
                # KeyboardInterrupt.
                self.r.daemon = True
                self.r.start()

        except AttributeError:
            self.sonos = self.cast_to
            self.sonos.coordinator.play_uri(
                "x-rincon-mp3radio://" + localip + ":" + self.port + "/stream",
                title=self.title,
            )
            if self.tray is True:
                self.cast = self.sonos
コード例 #19
0
ファイル: cast.py プロジェクト: guigeek208/mkchromecast
    def play_cast(self):
        if self.debug == True:
            print('def play_cast(self):')
        localip = self.ip

        print(colors.options('The IP of ')+colors.success(self.cast_to)+colors.options(' is:')+' '+self.cast.host)
        if self.host == None:
            print(colors.options('Your local IP is:')+' '+localip)
        else:
            print(colors.options('Your manually entered local IP is:')+' '+localip)

        """
        if self.youtubeurl != None:
            print(colors.options('The Youtube URL chosen:')+' '+self.youtubeurl)
            import pychromecast.controllers.youtube as youtube
            yt = youtube.YouTubeController()
            self.cast.register_handler(yt)

            try:
                import urlparse
                url_data = urlparse.urlparse(self.youtubeurl)
                query = urlparse.parse_qs(url_data.query)
            except ImportError:
                import urllib.parse
                url_data = urllib.parse.urlparse(self.youtubeurl)
                query = urllib.parse.parse_qs(url_data.query)
            video = query["v"][0]
            print(colors.options('Playing video:')+' '+video)
            yt.play_video(video)
        else:
        """
        media_controller = self.cast.media_controller

        if self.tray == True:
            config = ConfigParser.RawConfigParser()
            configurations = config_manager()    # Class from mkchromecast.config
            configf = configurations.configf

            if os.path.exists(configf) and self.tray == True:
                print(tray)
                print(colors.warning('Configuration file exists'))
                print(colors.warning('Using defaults set there'))
                config.read(configf)
                self.backend = ConfigSectionMap('settings')['backend']

        if self.sourceurl != None:
            if args.video == True:
                import mkchromecast.video
                mtype = mkchromecast.video.mtype
            else:
                import mkchromecast.audio
                mtype = mkchromecast.audio.mtype
            print(' ')
            print(colors.options('Casting from stream URL:')+' '+self.sourceurl)
            print(colors.options('Using media type:')+' '+mtype)
            media_controller.play_media(self.sourceurl, mtype, title = self.title)
        elif (self.backend == 'ffmpeg' or self.backend == 'node' or self.backend == 'avconv' or
                self.backend == 'parec' or self.backend == 'gstreamer' and self.sourceurl == None):
            if args.video == True:
                import mkchromecast.video
                mtype = mkchromecast.video.mtype
            else:
                import mkchromecast.audio
                mtype = mkchromecast.audio.mtype
            print(' ')
            print(colors.options('The media type string used is:')+' '+mtype)
            media_controller.play_media('http://'+localip+':5000/stream', mtype, title = self.title)
        print(' ')
        print(colors.important('Cast media controller status'))
        print(' ')
        print(self.cast.status)
        print(' ')
        if self.reconnect == True:
            self.r = Thread(target = self.reconnect_cc)
            self.r.daemon = True   # This has to be set to True so that we catch KeyboardInterrupt.
            self.r.start()
コード例 #20
0
ファイル: cast.py プロジェクト: guigeek208/mkchromecast
    def initialize_cast(self):
        import mkchromecast.__init__            # This is to verify against some needed variables.
        from pychromecast import socket_client  # This fixes the `No handlers could be found for logger "pychromecast.socket_client` warning"`.
                                                # See commit 18005ebd4c96faccd69757bf3d126eb145687e0d.
        self.cclist = self._get_chromecasts()
        if self.debug == True:
            print('self.cclist', self.cclist)

        """
        This block was used for casting youtube with pychromecast, but it does not work
        """
        """
        try:
            self.youtubeurl = mkchromecast.__init__.youtubeurl
        except AttributeError:
            self.youtubeurl = None
        """

        if len(self.cclist) != 0 and self.select_cc == False and self.ccname == None:
            if self.debug == True:
                print('if len(self.cclist) != 0 and self.select_cc == False:')
            print(' ')
            print(colors.important('List of Google Cast devices available in your network:'))
            print(colors.important('------------------------------------------------------'))
            print(' ')
            print(colors.important('Index   Friendly name'))
            print(colors.important('=====   ============= '))
            for self.index,device in enumerate(self.cclist):
                try:
                    print(str(self.index)+'      ', str(device))
                except UnicodeEncodeError:
                    print(str(self.index)+'      ', str(unicode(device).encode("utf-8")))
            print(' ')
            if self.discover == False:
                print(colors.important('We will cast to first device in the list above!'))
                print(' ')
                self.cast_to = self.cclist[0]
                print(colors.success(self.cast_to))
                print(' ')

        elif len(self.cclist) != 0 and self.select_cc == True and self.tray == False and self.ccname == None:
            if self.debug == True:
                print('elif len(self.cclist) != 0 and self.select_cc == True and self.tray == False:')
            if os.path.exists('/tmp/mkchromecast.tmp') == False:
                self.tf = open('/tmp/mkchromecast.tmp', 'wb')
                print(' ')
                print(colors.important('List of Google Cast devices available in your network:'))
                print(colors.important('------------------------------------------------------'))
                print(' ')
                print(colors.important('Index   Friendly name'))
                print(colors.important('=====   ============= '))
                self.availablecc()
            else:
                if self.debug == True:
                    print('else:')
                self.tf = open('/tmp/mkchromecast.tmp', 'rb')
                self.index=pickle.load(self.tf)
                self.cast_to = self.cclist[int(self.index)]
                print(' ')
                print(colors.options('Casting to:')+' '+colors.success(self.cast_to))
                print(' ')

        elif len(self.cclist) != 0 and self.select_cc == True and self.tray == True:
            if self.debug == True:
                print('elif len(self.cclist) != 0 and self.select_cc == True and self.tray == True:')
            if os.path.exists('/tmp/mkchromecast.tmp') == False:
                self.tf = open('/tmp/mkchromecast.tmp', 'wb')
                print(' ')
                print(colors.important('List of Google Cast devices available in your network:'))
                print(colors.important('------------------------------------------------------'))
                print(' ')
                print(colors.important('Index   Friendly name'))
                print(colors.important('=====   ============= '))
                self.availablecc()
            else:
                if self.debug == True:
                    print('else:')
                self.tf = open('/tmp/mkchromecast.tmp', 'rb')
                self.cast_to=pickle.load(self.tf)
                self.availablecc()
                print(' ')
                print(colors.options('Casting to:')+' '+colors.success(self.cast_to))
                print(' ')

        elif len(self.cclist) == 0 and self.tray == False:
            if self.debug == True:
                print('elif len(self.cclist) == 0 and self.tray == False:')
            print(colors.error('No devices found!'))
            if self.platform == 'Linux' and self.adevice == None:
                from mkchromecast.pulseaudio import remove_sink
                remove_sink()
            elif self.platform == 'Darwin':
                inputint()
                outputint()
            terminate()
            exit()

        elif len(self.cclist) == 0 and self.tray == True:
            print(colors.error(':::Tray::: No devices found!'))
            self.availablecc = []
コード例 #21
0
ファイル: cast.py プロジェクト: guigeek208/mkchromecast
 def sel_cc(self):
     print(' ')
     print('Please, select the '+colors.important('Index')+' of the Google Cast device that you want to use:')
     self.index = input()
コード例 #22
0
    print(colors.error("This option is not implemented yet."))
    sys.exit(0)

"""
Version
"""
if args.version is True:
    print("mkchromecast " + "v" + colors.success(__version__))
    sys.exit(0)

"""
Update
"""
if args.update is True:
    print(colors.warning("Updating Mkchromecast"))
    print(colors.important("git pull --all"))
    pull = subprocess.Popen(
        ["git", "pull", "--all"], stdout=subprocess.PIPE, stderr=subprocess.PIPE
    )

    print(pull.stdout.read().decode("utf-8").strip())
    print(colors.important("git fetch -p"))
    prune = subprocess.Popen(
        ["git", "fetch", "-p"], stdout=subprocess.PIPE, stderr=subprocess.PIPE
    )
    print(prune.stdout.read().decode("utf-8").strip())
    sys.exit(0)

"""
Check that encoders exist in the list
"""
コード例 #23
0
"""
if args.config is True:
    print(colors.error('This option is not implemented yet.'))
    sys.exit(0)
"""
Version
"""
if args.version is True:
    print('mkchromecast ' + 'v' + colors.success(__version__))
    sys.exit(0)
"""
Update
"""
if args.update is True:
    print(colors.warning('Updating Mkchromecast'))
    print(colors.important('git pull --all'))
    pull = subprocess.Popen(['git', 'pull', '--all'],
                            stdout=subprocess.PIPE,
                            stderr=subprocess.PIPE)

    print(pull.stdout.read().decode('utf-8').strip())
    print(colors.important('git fetch -p'))
    prune = subprocess.Popen(['git', 'fetch', '-p'],
                             stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE)
    print(prune.stdout.read().decode('utf-8').strip())
    sys.exit(0)
"""
Check that encoders exist in the list
"""
screencast = args.screencast
コード例 #24
0
ファイル: __init__.py プロジェクト: muammar/mkchromecast
    print(colors.error('This option is not implemented yet.'))
    sys.exit(0)

"""
Version
"""
if args.version is True:
    print('mkchromecast '+'v'+colors.success(__version__))
    sys.exit(0)

"""
Update
"""
if args.update is True:
    print(colors.warning('Updating Mkchromecast'))
    print(colors.important('git pull --all'))
    pull = subprocess.Popen(
        ['git', 'pull', '--all'],
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE
        )

    print(pull.stdout.read().decode('utf-8').strip())
    print(colors.important('git fetch -p'))
    prune = subprocess.Popen(
        ['git', 'fetch', '-p'],
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE
        )
    print(prune.stdout.read().decode('utf-8').strip())
    sys.exit(0)
コード例 #25
0
ファイル: cast.py プロジェクト: jamincollins/mkchromecast
    def play_cast(self):
        if self.debug is True:
            print('def play_cast(self):')
        localip = self.ip

        try:
            print(
                colors.options('The IP of ') + colors.success(self.cast_to) +
                colors.options(' is:') + ' ' + self.cast.host)
        except TypeError:
            print(
                colors.options('The IP of ') +
                colors.success(self.cast_to.player_name) +
                colors.options(' is:') + ' ' + self.cast_to.ip_address)
        except AttributeError:
            for _ in self.sonos_list:
                if self.cast_to in _.player_name:
                    self.cast_to = _
            print(
                colors.options('The IP of ') +
                colors.success(self.cast_to.player_name) +
                colors.options(' is:') + ' ' + self.cast_to.ip_address)

        if self.host is None:
            print(colors.options('Your local IP is:') + ' ' + localip)
        else:
            print(
                colors.options('Your manually entered local IP is:') + ' ' +
                localip)

        try:
            media_controller = self.cast.media_controller

            if self.tray is True:
                config = ConfigParser.RawConfigParser()
                # Class from mkchromecast.config
                from mkchromecast.config import config_manager
                configurations = config_manager()
                configf = configurations.configf

                if os.path.exists(configf) and self.tray is True:
                    print(self.tray)
                    print(colors.warning('Configuration file exists'))
                    print(colors.warning('Using defaults set there'))
                    config.read(configf)
                    self.backend = ConfigSectionMap('settings')['backend']

            if self.sourceurl is not None:
                if args.video is True:
                    import mkchromecast.video
                    mtype = mkchromecast.video.mtype
                else:
                    import mkchromecast.audio
                    mtype = mkchromecast.audio.mtype
                print(' ')
                print(
                    colors.options('Casting from stream URL:') + ' ' +
                    self.sourceurl)
                print(colors.options('Using media type:') + ' ' + mtype)
                media_controller.play_media(self.sourceurl,
                                            mtype,
                                            title=self.title)
            elif (self.backend == 'ffmpeg' or self.backend == 'node'
                  or self.backend == 'avconv' or self.backend == 'parec'
                  or self.backend == 'gstreamer' and self.sourceurl is None):
                if args.video is True:
                    import mkchromecast.video
                    mtype = mkchromecast.video.mtype
                else:
                    import mkchromecast.audio
                    mtype = mkchromecast.audio.mtype
                print(' ')
                print(
                    colors.options('The media type string used is:') + ' ' +
                    mtype)
                media_controller.play_media('http://' + localip + ':' +
                                            self.port + '/stream',
                                            mtype,
                                            title=self.title)
            print(' ')
            print(colors.important('Cast media controller status'))
            print(' ')
            print(self.cast.status)
            print(' ')
            if self.hijack is True:
                self.r = Thread(target=self.hijack_cc)
                # This has to be set to True so that we catch
                # KeyboardInterrupt.
                self.r.daemon = True
                self.r.start()
        except AttributeError:
            self.sonos = self.cast_to
            self.sonos.play_uri('x-rincon-mp3radio://' + localip + ':' +
                                self.port + '/stream',
                                title=self.title)
            if self.tray is True:
                self.cast = self.sonos
コード例 #26
0
ファイル: cast.py プロジェクト: muammar/mkchromecast
 def select_a_device(self):
     print(' ')
     print('Please, select the ' + colors.important('Index') +
           ' of the Google Cast device that you want to use:')
     self.index = input()
コード例 #27
0
ファイル: cast.py プロジェクト: GustavMauler/mkchromecast
    def initialize_cast(self):
        # This fixes the `No handlers could be found for logger
        # "pychromecast.socket_client` warning"`.
        # See commit 18005ebd4c96faccd69757bf3d126eb145687e0d.
        if chromecast:
            from pychromecast import socket_client

            self.cclist = self._get_chromecasts()
            self.cclist = [[i, _, "Gcast"] for i, _ in enumerate(self.cclist)]
        else:
            self.cclist = []

        if sonos:
            try:
                # Checking groups
                zone = soco.discovery.any_soco()

                self.sonos_list = zone.all_groups

                for self.index, group in enumerate(self.sonos_list):
                    add_sonos = [self.index, group.coordinator, "Sonos"]
                    self.cclist.append(add_sonos)
            except (TypeError, AttributeError):
                pass

        if self.debug is True:
            print("self.cclist", self.cclist)

        if (len(self.cclist) != 0 and self.select_device is False
                and self.device_name is None):
            if self.debug is True:
                print(
                    "if len(self.cclist) != 0 and self.select_device == False:"
                )
            print(" ")
            print_available_devices(self.available_devices())
            print(" ")
            if self.discover is False:
                print(colors.important("Casting to first device shown above!"))
                print(colors.important("Select devices by using the -s flag."))
                print(" ")
                self.cast_to = self.cclist[0][1]
                if self.cclist[0][2] == "Sonos":
                    print(colors.success(self.cast_to.coordinator.player_name))
                else:
                    print(colors.success(self.cast_to))
                print(" ")

        elif (len(self.cclist) != 0 and self.select_device is True
              and self.tray is False and self.device_name is None):
            if self.debug is True:
                print(
                    "elif len(self.cclist) != 0 and self.select_device == True"
                    " and self.tray == False:")
            if os.path.exists("/tmp/mkchromecast.tmp") is False:
                self.tf = open("/tmp/mkchromecast.tmp", "wb")
                print(" ")
                print_available_devices(self.available_devices())
            else:
                if self.debug is True:
                    print("else:")
                self.tf = open("/tmp/mkchromecast.tmp", "rb")
                self.index = pickle.load(self.tf)
                self.cast_to = self.cclist[int(self.index)]
                print(" ")
                print(
                    colors.options("Casting to:") + " " +
                    colors.success(self.cast_to))
                print(" ")

        elif len(self.cclist
                 ) != 0 and self.select_device is True and self.tray is True:
            if self.debug is True:
                print(
                    "elif len(self.cclist) != 0 and self.select_device == True"
                    "  and self.tray == True:")
            if os.path.exists("/tmp/mkchromecast.tmp") is False:
                self.tf = open("/tmp/mkchromecast.tmp", "wb")
                print(" ")
                print_available_devices(self.available_devices())
            else:
                if self.debug is True:
                    print("else:")
                self.tf = open("/tmp/mkchromecast.tmp", "rb")
                self.cast_to = pickle.load(self.tf)
                print_available_devices(self.available_devices())
                print(" ")
                print(
                    colors.options("Casting to:") + " " +
                    colors.success(self.cast_to))
                print(" ")

        elif len(self.cclist) == 0 and self.tray is False:
            if self.debug is True:
                print("elif len(self.cclist) == 0 and self.tray == False:")
            print(colors.error("No devices found!"))
            if self.platform == "Linux" and self.adevice is None:
                remove_sink()
            elif self.platform == "Darwin":
                inputint()
                outputint()
            terminate()
            exit()

        elif len(self.cclist) == 0 and self.tray is True:
            print(colors.error(":::Tray::: No devices found!"))
            self.available_devices = []
コード例 #28
0
ファイル: cast.py プロジェクト: thebryman/mkchromecast
    def initialize_cast(self):
        import mkchromecast.__init__  # This is to verify against some needed variables.
        from pychromecast import socket_client  # This fixes the `No handlers could be found for logger "pychromecast.socket_client` warning"`.
        # See commit 18005ebd4c96faccd69757bf3d126eb145687e0d.
        self.cclist = self._get_chromecasts()
        self.cclist = [[index, _, 'Gcast']
                       for index, _ in enumerate(self.cclist)]

        if sonos == True:
            try:
                self.sonos_list = list(soco.discover())
                length = len(self.cclist)
                for self.index, device in enumerate(self.sonos_list):
                    add_sonos = [self.index, device, 'Sonos']
                    self.cclist.append(add_sonos)
            except TypeError:
                pass

        if self.debug == True:
            print('self.cclist', self.cclist)
        """
        This block was used for casting youtube with pychromecast, but it does not work
        """
        """
        try:
            self.youtubeurl = mkchromecast.__init__.youtubeurl
        except AttributeError:
            self.youtubeurl = None
        """

        if (len(self.cclist) != 0 and self.select_cc == False
                and self.ccname == None):
            if self.debug == True:
                print('if len(self.cclist) != 0 and self.select_cc == False:')
            print(' ')
            print(
                colors.important('List of Devices Available in your Network:'))
            print(
                colors.important(
                    '------------------------------------------\n'))
            print(colors.important('Index \tTypes \tFriendly Name '))
            print(colors.important('===== \t===== \t============= '))
            self.availablecc()
            print(' ')
            if self.discover == False:
                print(
                    colors.important(
                        'We will cast to first device in the list above!'))
                print(' ')
                self.cast_to = self.cclist[0][1]
                print(colors.success(self.cast_to))
                print(' ')

        elif (len(self.cclist) != 0 and self.select_cc == True
              and self.tray == False and self.ccname == None):
            if self.debug == True:
                print(
                    'elif len(self.cclist) != 0 and self.select_cc == True and self.tray == False:'
                )
            if os.path.exists('/tmp/mkchromecast.tmp') == False:
                self.tf = open('/tmp/mkchromecast.tmp', 'wb')
                print(' ')
                print(
                    colors.important(
                        'List of Devices Available in your Network:'))
                print(
                    colors.important(
                        '------------------------------------------\n'))
                print(colors.important('Index \tTypes \tFriendly Name '))
                print(colors.important('===== \t===== \t============= '))
                self.availablecc()
            else:
                if self.debug == True:
                    print('else:')
                self.tf = open('/tmp/mkchromecast.tmp', 'rb')
                self.index = pickle.load(self.tf)
                self.cast_to = self.cclist[int(self.index)]
                print(' ')
                print(
                    colors.options('Casting to:') + ' ' +
                    colors.success(self.cast_to))
                print(' ')

        elif (len(self.cclist) != 0 and self.select_cc == True
              and self.tray == True):
            if self.debug == True:
                print(
                    'elif len(self.cclist) != 0 and self.select_cc == True and self.tray == True:'
                )
            if os.path.exists('/tmp/mkchromecast.tmp') == False:
                self.tf = open('/tmp/mkchromecast.tmp', 'wb')
                print(' ')
                print(
                    colors.important(
                        'List of Devices Available in your Network:'))
                print(
                    colors.important(
                        '------------------------------------------\n'))
                print(colors.important('Index \tTypes \tFriendly Name '))
                print(colors.important('===== \t===== \t============= '))
                self.availablecc()
            else:
                if self.debug == True:
                    print('else:')
                self.tf = open('/tmp/mkchromecast.tmp', 'rb')
                self.cast_to = pickle.load(self.tf)
                self.availablecc()
                print(' ')
                print(
                    colors.options('Casting to:') + ' ' +
                    colors.success(self.cast_to))
                print(' ')

        elif len(self.cclist) == 0 and self.tray == False:
            if self.debug == True:
                print('elif len(self.cclist) == 0 and self.tray == False:')
            print(colors.error('No devices found!'))
            if self.platform == 'Linux' and self.adevice == None:
                remove_sink()
            elif self.platform == 'Darwin':
                inputint()
                outputint()
            terminate()
            exit()

        elif len(self.cclist) == 0 and self.tray == True:
            print(colors.error(':::Tray::: No devices found!'))
            self.availablecc = []