示例#1
0
 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
 def check_connection(self):
     """Check if the computer is connected to a network"""
     if self.cc.ip == '127.0.0.1':  # We verify the local IP.
         print(
             colors.error('Your Computer is not Connected to Any Network'))
         terminate()
     elif self.cc.ip != '127.0.0.1' and self.discover == True:
         self.cc.initialize_cast()
         terminate()
示例#3
0
 def terminate_app(self):
     """Terminate the app (kill app)"""
     self.cc.stop_cast()
     if platform == 'Darwin':
         inputint()
         outputint()
     elif platform == 'Linux' and adevice == None:
         remove_sink()
     terminate()
示例#4
0
def main():
    if encoder_backend != 'node':
        st = multi_proc()
        st.start()
    else:
        print('Starting Node')
        if platform == 'Darwin':
            PATH = './bin:./nodejs/bin:/Users/' + \
                   str(USER) + \
                   '/bin:/usr/local/bin:/usr/local/sbin:' + \
                   '/usr/bin:/bin:/usr/sbin:' + \
                   '/sbin:/opt/X11/bin:/usr/X11/bin:/usr/games:' + \
                   os.environ['PATH']
        else:
            PATH = os.environ['PATH']

        if debug is True:
            print('PATH = %s.' % PATH)

        node_names = ['node']
        nodejs_dir = ['./nodejs/']

        if platform == 'Linux':
            node_names.append('nodejs')
            nodejs_dir.append('/usr/share/mkchromecast/nodejs/')

        for name in node_names:
            if is_installed(name, PATH, debug) is True:
                for path in nodejs_dir:
                    if os.path.isdir(path):
                        path = path + 'html5-video-streamer.js'
                        webcast = [
                            name,
                            path,
                            input_file
                            ]
                        break

        if input_file == None:
            print(colors.warning('Please specify an input file with -i'))
            print(colors.warning('Closing the application...'))
            terminate()

        try:
            Popen(webcast)
        except:
            print(colors.warning('Nodejs is not installed in your system. '
                  'Please, install it to use this backend.'))
            print(colors.warning('Closing the application...'))
            terminate()
示例#5
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
示例#6
0
def main():
    if encoder_backend != "node":
        st = multi_proc()
        st.start()
    else:
        print("Starting Node")
        if platform == "Darwin":
            PATH = ("./bin:./nodejs/bin:/Users/" + str(USER) +
                    "/bin:/usr/local/bin:/usr/local/sbin:" +
                    "/usr/bin:/bin:/usr/sbin:" +
                    "/sbin:/opt/X11/bin:/usr/X11/bin:/usr/games:" +
                    os.environ["PATH"])
        else:
            PATH = os.environ["PATH"]

        if debug is True:
            print("PATH = %s." % PATH)

        node_names = ["node"]
        nodejs_dir = ["./nodejs/"]

        if platform == "Linux":
            node_names.append("nodejs")
            nodejs_dir.append("/usr/share/mkchromecast/nodejs/")

        for name in node_names:
            if is_installed(name, PATH, debug) is True:
                for path in nodejs_dir:
                    if os.path.isdir(path):
                        path = path + "html5-video-streamer.js"
                        webcast = [name, path, input_file]
                        break

        if input_file == None:
            print(colors.warning("Please specify an input file with -i"))
            print(colors.warning("Closing the application..."))
            terminate()

        try:
            Popen(webcast)
        except:
            print(
                colors.warning("Nodejs is not installed in your system. "
                               "Please, install it to use this backend."))
            print(colors.warning("Closing the application..."))
            terminate()
示例#7
0
    def reconnect_cc(self):
        """Dummy method to call  _reconnect_cc_().

        In the cast that the self.r thread is alive, we check that the
        chromecast is connected. If it is connected, we check again in
        5 seconds.
        """
        try:
            while self.r.is_alive():
                self._reconnect_cc_()
                time.sleep(5)       #FIXME: I think that this has to be set by users.
        except KeyboardInterrupt:
            self.stop_cast()
            if platform == 'Darwin':
                inputint()
                outputint()
            elif platform == 'Linux' and adevice == None:
                from mkchromecast.pulseaudio import remove_sink
                remove_sink()
            terminate()
示例#8
0
    def hijack_cc(self):
        """Dummy method to call  _hijack_cc_().

        In the cast that the self.r thread is alive, we check that the
        chromecast is connected. If it is connected, we check again in
        5 seconds.
        """
        try:
            while self.r.is_alive():
                self._hijack_cc_()
                # FIXME: I think that this has to be set by users.
                time.sleep(5)
        except KeyboardInterrupt:
            self.stop_cast()
            if self.platform == "Darwin":
                inputint()
                outputint()
            elif self.platform == "Linux" and self.adevice is None:
                remove_sink()
            terminate()
示例#9
0
    def hijack_cc(self):
        """Dummy method to call  _hijack_cc_().

        In the cast that the self.r thread is alive, we check that the
        chromecast is connected. If it is connected, we check again in
        5 seconds.
        """
        try:
            while self.r.is_alive():
                self._hijack_cc_()
                # FIXME: I think that this has to be set by users.
                time.sleep(5)
        except KeyboardInterrupt:
            self.stop_cast()
            if self.platform == 'Darwin':
                inputint()
                outputint()
            elif self.platform == 'Linux' and self.adevice is None:
                remove_sink()
            terminate()
示例#10
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
示例#11
0
 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
示例#12
0
def main():
    if encoder_backend != 'node':
        st = multi_proc()
        st.start()
    else:
        print('Starting Node')
        if platform == 'Darwin':
            PATH = './bin:./nodejs/bin:/Users/' + str(
                USER
            ) + '/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/X11/bin:/usr/games:' + os.environ[
                'PATH']
        else:
            PATH = os.environ['PATH']

        if debug == True:
            print('PATH =' + str(PATH))

        if platform == 'Darwin' and os.path.exists('./bin/node') == True:
            webcast = [
                './bin/node', './nodejs/html5-video-streamer.js', input_file
            ]
        elif platform == 'Linux':
            node_names = ['node', 'nodejs']
            nodejs_dir = ['./nodejs/', '/usr/share/mkchromecast/nodejs/']
            for name in node_names:
                if is_installed(name, PATH, debug) == True:
                    for path in nodejs_dir:
                        if os.path.isdir(path):
                            path = path + 'html5-video-streamer.js'
                            webcast = [name, path, input_file]
                            break
        try:
            p = subprocess.Popen(webcast)
        except:
            print(
                colors.warning(
                    'Nodejs is not installed in your system. Please, install it to use this backend.'
                ))
            print(colors.warning('Closing the application...'))
            terminate()
示例#13
0
    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 = []
示例#14
0
"""
Check that input file exists
"""
if input_file != None and os.path.isfile(input_file) is False:
    if platform == "Darwin":
        from mkchromecast.audio_devices import inputint, outputint

        inputint()
        outputint()
    else:
        from mkchromecast.pulseaudio import remove_sink

        remove_sink()

    print(colors.warning("File not found!"))
    terminate()

"""
Media-Type
"""
mtype = args.mtype

if args.mtype is not None and args.video is False:
    print(
        colors.warning("The media type is not supported for audio.")
        % args.encoder_backend
    )

"""
Reset
"""
示例#15
0
    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 = []
示例#16
0
    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 = []
示例#17
0
    print('Google Cast name: %s.' % device_name)

"""
Check that input file exists
"""
if input_file != None and os.path.isfile(input_file) is False:
    if platform == 'Darwin':
        from mkchromecast.audio_devices import inputint, outputint
        inputint()
        outputint()
    else:
        from mkchromecast.pulseaudio import remove_sink
        remove_sink()

    print(colors.warning('File not found!'))
    terminate()

"""
Media-Type
"""
mtype = args.mtype

if args.mtype is not None and args.video is False:
    print(colors.warning('The media type is not supported for audio.')
          % args.encoder_backend)

"""
Reset
"""
if args.reset is True:
    if platform == 'Darwin':
示例#18
0
    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 = []
示例#19
0
    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 = []