コード例 #1
0
ファイル: default.py プロジェクト: WPettersson/GOMstreamer
handle = int(sys.argv[1])

def setting_defined(id):
  s = xbmcplugin.getSetting(handle, id)
  return s is not None and len(s) > 0


if not setting_defined("username") or not setting_defined("password"):
  xbmcgui.Dialog().ok("Missing configuration", 
      "Enter your credentials in the options menu")
else:
  quality = "SQTest"
  if xbmcplugin.getSetting(handle,"quality") == True:
    quality = "HQ"
  g = GOMPlayer(xbmcplugin.getSetting(handle,"username"),
                xbmcplugin.getSetting(handle,"password"))
  g.signIn()                
  quality, streams = g.getStreams(quality,'first')
  userAgent = "|User-agent=KPeerClient"
  if len(streams) == 0:
    xbmcgui.Dialog().ok("No streams found",
        "No streams were found. Is the GSL on?")
  for stream in streams:
    name = stream['title']
    li = xbmcgui.ListItem(name, thumbnailImage="DefaultVideo.png")
    li.setInfo( type="Video", infoLabels={ "Title": name } )
    #li.setProperty('mimetype', 'video/x
    xbmcplugin.addDirectoryItem(handle=handle,
            url = "%s%s"%(stream['url'],userAgent),
            listitem = li)
  xbmcplugin.endOfDirectory(handle=int(sys.argv[1]), succeeded=True)
コード例 #2
0
def main():
    curlCmd = 'curl -s -A KPeerClient "$url" -o "$output"'
    wgetCmd = 'wget -q -U KPeerClient --tries 1 "$url" -O "$output"'
    vlcPath, webCmdDefault = getDefaultLocations(curlCmd, wgetCmd)
    vlcCmdDefault = vlcPath + ' --file-caching $cache $debug - vlc://quit'
    options, args = parseOptions(vlcCmdDefault, webCmdDefault)

    # Printing out parameters
    logging.debug('Email: %s', options.email)
    logging.debug('Password: %s', options.password)
    logging.debug('Mode: %s', options.mode)
    logging.debug('Quality: %s', options.quality)
    logging.debug('VlcCmd: %s', options.vlcCmd)
    logging.debug('WebCmd: %s', options.webCmd)

    # Stopping if email and password are defaults found in *.sh/command/cmd
    if options.email == '*****@*****.**' and options.password == 'PASSWORD':
        errMsg = 'Enter your GOMtv email and password into your *.sh, *.command, or *.cmd file.'
        errMsg = errMsg + '\nThis script will not work correctly without a valid account.'
        logging.error(errMsg)
        sys.exit(1)

    g = GOMPlayer(options.email, options.password)
    # Seeing if we're running the latest version of GOMstreamer
    g.checkForUpdate()

    if options.mode == 'scheduled-play':
        # Delaying execution until necessary
        delay(options.kt)

    # Sign in
    g.signIn()
    # Get all streams
    options.quality, urls = g.getStreams(options.quality,options.streamChoice)
    numberOfStreams = len(urls)
    # Put variables into VLC command
    vlcCmd = Template(options.vlcCmd).substitute(
            {'cache': options.cache, 
             'debug' : ('', '--verbose=2')[debug]})

    # Create shell commands
    cmds = []
    for i in range(numberOfStreams):
        url = urls[i]['url']

        webCmd = Template(options.webCmd).substitute(
                {'url' : url, 'output' : '-'})
    
        # Add verbose output for VLC if we are debugging
        if debug:
            webCmd = webCmd + ' -v'
    
        # When playing, pipe wget/curl into VLC
        # We have already substituted $output with correct target.
        cmds.append(webCmd + ' | ' + vlcCmd)

    if numberOfStreams > 1:
        logging.info('Stream URLs: %s' % urls)
        logging.info('Commands: %s' % cmds)
    else:
        logging.info('Stream URL: %s' % urls[0])
        logging.info('Command: %s' % cmds[0])

    if options.mode == 'play':
        if numberOfStreams > 1:
            print 'Playing streams...'
        else:
            print 'Playing stream...'
    elif options.mode == 'dumpURLs':
        for url in urls:
            print url
    else:
        print 'Playing stream...'


    if options.mode == 'dumpURLs':
        sys.exit(0)
    # Executing command
    procs = []
    try:
        for i in range(numberOfStreams):
            procs.append(subprocess.Popen(cmds[i], shell = True))
        for i in range(numberOfStreams):
            procs[i].wait()
    except KeyboardInterrupt:
        # Swallow it, we are terminating anyway and don't want a stack trace.
        for i in range(numberOfStreams):
            procs[i].kill()
    except OSError:
        # If wget/curl fails to grab the stream, give up
        for i in range(numberOfStreams):
            procs[i].kill()
    finally:
        sys.exit(0)