gnash-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-dev] youtube script


From: Andrea Palmatè
Subject: [Gnash-dev] youtube script
Date: Fri, 18 Sep 2009 16:19:53 +0200
User-agent: Thunderbird 2.0.0.23 (Windows/20090812)

Hi,
i've made a new youtube script in python.
It works on amiga and so it shoudl work also on Linux
please test it, and maybe change the wiki page

Andrea
import os
import getopt
import sys

def usage():
        print "usage:"
        print "    youtube.py -m url [-d]\n"
        print "-m: media to play. For example: t3s-mG5yUjY"
        print "-d: turn on debug messages"

def main():
        resultstring = '"flashvars='
        entirefile = ""
        file = ""
        debug = 0

        if len(sys.argv) < 2:
                usage()
                sys.exit(2)
                
        try:    
                opts, args = getopt.getopt(sys.argv[1:], "hm:d", ["help", 
"movie=", "debug"])
        except getopt.GetoptError, err:
                print str(err)
                usage()
                sys.exit(2)
        for o, a in opts:
                if o in ("-h", "--help"):
                        usage()
                elif o in ("-d", "--debug"):
                        debug = 1
                elif o in ("-m", "--movie"):
                        file = "wget --quiet -O - 
http://www.youtube.com/watch?v="; + a + " >youtube.txt"
        if file == "":
                usage()
                sys.exit(2)
                
        if debug == 1:
                print "file=" + file
        os.system(file)

        f = open("youtube.txt","r")
        entirefile = f.read()
        f.close()

        startline = entirefile.find('swfArgs')
        if startline > 0:
                endline = entirefile.find('\n',startline)
                if endline > 0:
                        swfArgs = entirefile[startline+11:endline]
                        if debug == 1:
                                print "swfArgs=" + swfArgs
                        result = swfArgs.split(',')
                        i = 0
                        for t in result:
                                result2 = t.split(':')
                                for x in result2:
                                        i = i + 1
                                        x = x.replace('"','')
                                        x = x.replace(' ','')
                                        if i == 1:
                                                resultstring = resultstring + x 
+ '='
                                        else:
                                                resultstring = resultstring + x 
+ '&'
                                                i = 0
                        resultstring = resultstring[0:len(resultstring)-3]
                        resultstring = resultstring + '"'
                        os.system('gtk-gnash -F 2 -P ' + resultstring + ' 
http://www.youtube.com/player2.swf')
                        if debug == 1:
                                f = open("flashvars.txt","w")
                                f.write(resultstring)
                                f.close()
                else:
                        print "Invalid movie!"
        else:
                print "Invalid movie!"
if __name__ == "__main__":
    main()

reply via email to

[Prev in Thread] Current Thread [Next in Thread]