Example #1
0
def setAct(act, val):

    if checkActVal(act, val) == False:
        print('\n[xplay][setAct] invalid command: %s %s\n' % (act, val))
        return

    if act == 'stop' and val != '#':
        if os.path.exists(xdef.playlist):
            os.remove(xdef.playlist)

    if act == 'playbackMode':
        xurl.saveLocal(xdef.playbackMode, val, 0)
        if val.lower() in ['autonext', 'loopall']:
            playing = xurl.readLocal(xdef.playing, 0)
            playlist = xurl.readLocal(xdef.playlist, 0)
            nextURL = nextLine(playing, playlist)
            if nextURL:
                if os.fork() == 0:
                    xsrc.getSource(nextURL)
        return

    player = getPlayer()
    print('\n[xplay][setAct]\n\n\t' + '%s,%s,%s' % (player, act, val))

    if player == 'mpv' and xproc.checkProcessRunning('mpv'):
        return mpv.setAct(act, val)

    if player == 'omxp' and xproc.checkProcessRunning('omxplayer.bin'):
        return omxp.setAct(act, val)

    if player == 'ffplay' and xproc.checkProcessRunning('ffplay'):
        return ffplay.setAct(act, val)
Example #2
0
def isPlayerRunning():
    player = getPlayer()
    if player == 'mpv' and xproc.checkProcessRunning('mpv'):
        return True
    if player == 'omxp' and xproc.checkProcessRunning('omxplayer.bin'):
        return True
    if player == 'ffplay' and xproc.checkProcessRunning('ffplay'):
        return True
    return False
Example #3
0
def play(url, ref, cookies=None):

    xargs = '--user-agent=\'%s\'' % (xurl.defvals.ua)

    url, cookies, ref = xsrc.getSource(url, ref=ref)

    if not url:
        print('\n[omxp][play] invalid url\n')
        return

    if xproc.checkProcessRunning('omxplayer.bin'):
        setAct('stop', None)

    if cookies:
        xargs = ' '.join(
            [xargs, '--avdict headers:\"Cookie: %s\"' % (cookies)])

    if re.search(r'/hls_playlist/', url):
        cmd = 'livestreamer --player omxplayer --fifo \'hls://%s\' best 2>&1 | tee %s' % (
            url, xdef.log)
    else:
        cmd = '%s %s \'%s\' 2>&1 | tee %s' % (xdef.omxp, xargs, url, xdef.log)

    print('\n[omx][cmd]\n\n\t' + cmd + '\n')
    subprocess.Popen(cmd, shell=True).communicate()

    return
Example #4
0
File: mpv.py Project: JiasHuang/vod
def play(url, ref):

    p = None
    xargs = []

    url, cookies, ref = xsrc.getSource(url, ref=ref)

    if not url:
        print('\n[mpv][play] invalid url\n')
        return

    if cookies and re.search(r'google.com',
                             url) and xproc.checkProcessRunning('mpv'):
        os.system('echo stop > %s' % (xdef.fifo))
        while xproc.checkProcessRunning('mpv'):
            time.sleep(1)

    if not xproc.checkProcessRunning('mpv'):

        xargs.append('--user-agent=\'%s\'' % (xurl.defvals.ua))
        xargs.append('--referrer=\'%s\'' % (ref))

        if cookies:
            xargs.append('--http-header-fields="Cookie:%s"' % (cookies))

        cmd = '%s %s \'%s\'' % (xdef.mpv, ' '.join(xargs), url)
        print('\n[mpv][cmd]\n\n\t' + cmd + '\n')
        p = subprocess.Popen(cmd, shell=True)

    else:
        os.system('echo loadfile \"%s\" > %s' % (url, xdef.fifo))
        os.system('echo sub-remove > %s' % (xdef.fifo))

    sub = xsrc.getSub(ref)
    if sub:
        os.system('echo sub-add \"%s\" select > %s' % (sub, xdef.fifo))

    if p:
        p.communicate()

    return
Example #5
0
def play(url, ref):

    xargs = ''

    url, cookies, ref = xsrc.getSource(url, ref=ref)

    if not url:
        print('\n[ffplay][play] invalid url')
        return

    if cookies:
        xargs += ' -headers "Cookie: %s"' % (cookies)

    if xproc.checkProcessRunning('ffplay'):
        setAct('stop', None)

    cmd = '%s %s \'%s\'' % (xdef.ffplay, xargs, url)
    print('\n[ffplay][cmd]\n\n\t' + cmd + '\n')
    subprocess.Popen(cmd, shell=True).communicate()

    return
Example #6
0
def setAct(act, val):

    pid = xproc.checkProcessRunning('ffplay')
    if not pid:
        print('\n[ffplay][secAct] no pid')
        return

    wid = xproc.checkOutput('xdotool search --name ffplay', r'([0-9]*)$')
    if not wid:
        print('\n[ffplay][secAct] no wid')
        return

    os.system('xdotool windowactivate --sync %s' % (wid))

    if act == 'stop':
        os.system('xdotool key q')
    elif act == 'pause':
        os.system('xdotool key p')
    elif act == 'forward':
        os.system('xdotool key Up')
    elif act == 'backward':
        os.system('xdotool key Down')
    elif act == 'percent' and val:
        geometry = xproc.checkOutput('xdotool getwindowgeometry %s' % (wid),
                                     r'Geometry: ([0-9x]*)')
        if not geometry:
            print('\n[ffplay][setAct] no geometry')
            return
        w = int(geometry.split('x')[0])
        h = int(geometry.split('x')[1])
        x = str(w * int(val) / 100)
        y = str(h / 2)
        os.system('xdotool mousemove --sync --window %s %s %s click 1' %
                  (wid, x, y))
    else:
        print('\n[ffplay][setAct] unsupported: %s %s' % (act, val))
    return