willprice / python-omxplayer-wrapper

:tv: Control OMXPlayer, the Raspberry Pi media player, from Python
http://python-omxplayer-wrapper.readthedocs.io
GNU Lesser General Public License v3.0
253 stars 71 forks source link

youtube-dl as source #82

Closed varadig closed 7 years ago

varadig commented 7 years ago

Can I use, and if I can, how to pass source as youtube link. From cli I can play the video on this way: omxplayer $(youtube-dl -g https://www.youtube.com/watch?v=zAoWcs6d75Q) But with python-omxplayer-wrapper I got this error:

  File "/usr/local/lib/python2.7/dist-packages/omxplayer_wrapper-0.2.1-py2.7.egg/omxplayer/player.py", line 114, in _setup_omxplayer_process
    raise FileNotFoundError("Could not find: {}".format(source))
FileNotFoundError: Could not find: $(youtube-dl -g https://www.youtube.com/watch?v=zAoWcs6d75Q)

There is any option to play youtube video with the wrapper, or there is any chance to add support to play it?

willprice commented 7 years ago

Because python does not delegate to the shell when running omxplayer you cannot use shell construct slike "$(youtube-dl -g ...)".

I'd create a named FIFO (https://docs.python.org/3/library/os.html#os.mkfifo), you can then invoke youtube-dl piping to the FIFO, pass then pass the FIFO path to omxplayer in place of a normal file.

varadig commented 7 years ago

Thanks, i will check ;)

varadig commented 7 years ago

Hmmm with commandline I can do the job, but with wrapper I thing I miss something. Can you show me your example of the usage?

python:

import os

import thread
from threading import Thread
from time import sleep

from omxplayer import OMXPlayer

try:
    os.mkfifo("/home/pi/ytpy.fifo",0o666)
except:
    print 'fifo is exists'

def download():
    os.system("youtube-dl -o - QWY-Obragek > /home/pi/ytpy.fifo")

def play():
    try:
        player = OMXPlayer("/home/pi/ytpy.fifo")
        player.play()
    except:
        sleep(1)
        play()

thread = Thread(target = download)
thread.start()

thread2 = Thread(target = play)
thread2.start()

cli: youtube-dl -o - QWY-Obragek > /home/pi/ytpy.fifo & omxplayer -o local /home/pi/ytpy.fifo

jambonmcyeah commented 7 years ago

This is my solution:

    url= 'https://www.youtube.com/watch?v=_GuOjXYl5ew'

    import subprocess

    proc = subprocess.Popen(['youtube-dl','-f','best', '-g', url], stdout=subprocess.PIPE)
    realurl=proc.stdout.read()
    from omxplayer import OMXPlayer
    player= OMXPlayer(realurl.decode("utf-8", "strict")[:-1])
jehutting commented 7 years ago

@jambonmcyeah Works like a charme. Thanks.

jambonmcyeah commented 7 years ago

@jehutting You're welcome :)