HritwikSinghal / Clipboard-saavn-song-downloader

Download songs from Jiosaavn by just copying song, album, playlist link to clipboard.
GNU General Public License v3.0
2 stars 0 forks source link

wl-clipboard shows "No selection" #4

Open HritwikSinghal opened 3 years ago

HritwikSinghal commented 3 years ago

if wl-clipboard package is installed, below is the output in idle condition.

Starting Program....
Songs will be Downloaded to:  ~/Downloads/Music

Waiting for url from clipboard....

Waiting for url from clipboard....
No selection
No selection
No selection
No selection
No selection
No selection
No selection
No selection
No selection
No selection
No selection
No selection
No selection
No selection
No selection
No selection
No selection
No selection
HritwikSinghal commented 3 years ago

see https://github.com/bugaevc/wl-clipboard/issues/40

see also https://github.com/asweigart/pyperclip/blob/master/src/pyperclip/__init__.py

flickering issue cant be solved since https://github.com/bugaevc/wl-clipboard/issues/90 , you can remove 'no selecction' by adding 'stderr=subprocess.DEVNULL' to 'subprocess.Popen' as done below.

HritwikSinghal commented 3 years ago
class wl_clip:

    def __init__(self):
        self.clipboardText = ''

    def check_wayland(self):
        if os.environ.get("WAYLAND_DISPLAY"):
            if _executable_exists("wl-copy"):
                return True
            print("No wayland clipboard found! Please install wl-clipboard.")
        return False

    def paste_wayland(self, primary=False):
        args = ["wl-paste", "-n"]
        if primary:
            args.append('-p')

        p = subprocess.Popen(args, close_fds=True, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL)
        stdout, _stderr = p.communicate()
        self.clipboardText = stdout.decode(ENCODING)

    def waitForPaste(self):
        """This function call blocks until a non-empty text string exists on the
        clipboard. It returns this text.
        This function raises PyperclipTimeoutException if timeout was set to
        a number of seconds that has elapsed without non-empty text being put on
        the clipboard."""

        while True:
            # clipboardText = self.paste_wayland()
            t1 = threading.Thread(target=self.paste_wayland)
            t1.start()
            t1.join()

            if self.clipboardText != '':
                print("HeLLo")
                return self.clipboardText
            time.sleep(0.1)
    def get_url(self):
        print('\nWaiting for url from clipboard....')

        if wl_clip.check_wayland(wl_clip()):
            print("TTTT")
            wayland_clip = wl_clip()
            url = wayland_clip.waitForPaste()
        else:
            url = pyperclip.waitForPaste()

        # url = 'https://www.jiosaavn.com/song/shayad-from-love-aaj-kal/GjIBdCt,UX8'
        pyperclip.copy('')

        if str(url).startswith('https://www.jiosaavn.com'):
            print('got url: ', url)

            self.set_url(url)
            self.url_type = self.url.split('/')[3]