Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # file name = ffplayer ( build using ffmpeg multimedia library )
- # developer :: Shishtpal
- import os, glob, shutil, sys, tempfile, subprocess, ctypes, time
- import Tkinter as tk
- import tkFileDialog
- vlist = set()
- index_no = 0
- # < Program Code #10001@ >
- # Code Block used to add files to vlist, that we use as an argument with this script.
- try:
- if len(sys.argv) == 1:
- cwd = ''
- else:
- cwd = sys.argv[1:]
- for i in cwd:
- print i
- vlist.add(i)
- print "\n\n"
- except:
- print "Error in Program Code #10001@"
- def tk_gui():
- global root, cwd
- global index_no
- root = tk.Tk()
- root.wm_geometry(newGeometry='250x0+10+10')
- root.wm_title("Ffplayer ( Video Player )")
- menubar = tk.Menu(root)
- root.config(menu=menubar)
- # Creating a menu button
- filemenu1 = tk.Menu(menubar)
- filemenu2 = tk.Menu(menubar)
- filemenu3 = tk.Menu(menubar)
- menubar.add_cascade(label='Player', menu=filemenu1)
- menubar.add_cascade(label='Control', menu=filemenu2)
- menubar.add_cascade(label='Help', menu=filemenu3)
- def button1Click():
- """
- this code block is used to play a single video file,
- this video file will be added to vlist playlist
- """
- global cwd, vlist
- print "Opening Video File :-)\n\n"
- openfilename = tkFileDialog.askopenfilename(title="Select Video/Mp3 File..", initialdir="C:\\")
- cwd = openfilename
- vlist.add(cwd)
- vid_player(cwd)
- def button2Click():
- """
- this code block is used to open a window dialog box asked you to select
- a folder and filter all video files in your defined location,
- and add all of them to your vlist
- """
- global cwd
- print "Open a folder with Video File :-)\n\n"
- openfoldername = tkFileDialog.askdirectory()
- b = openfoldername.split("/")
- cwd = ''
- for i in range(len(b)):
- cwd = cwd + "\\" + b[i]
- cwd = cwd[1:]
- print cwd
- vid_player(cwd)
- play_video()
- """
- def button3Click():
- print "Open Settings Panel :-)\n\n\n"
- #p1 = subproecess.call([])
- """
- def button4Click():
- print "Bye Bye!!"
- sys.exit()
- # create action for button 'Quit'
- filemenu1.add_command(label='Open File (o)', command=button1Click)
- filemenu1.add_command(label='Open Folder (f)', command=button2Click)
- #filemenu1.add_command(label='Settings', command=button3Click)
- filemenu1.add_separator()
- filemenu1.add_command(label='Quit (q)', command=button4Click) # bind a event using command method
- #
- root.bind("<o>", lambda e: button1Click()) # bind a shortcut using lambda method
- root.bind("<O>", lambda e: button1Click())
- root.bind("<f>", lambda e: button2Click())
- root.bind("<F>", lambda e: button2Click())
- root.bind("<Q>", lambda e: button4Click())
- root.bind("<q>", lambda e: button4Click())
- #
- def next_video():
- global p1
- try:
- p1.kill()
- except:
- print "\n\nThere is NO ffplay.exe subprocess Exists!!\n\n"
- play_video()
- def play_video():
- global index_no, p1
- print "\n", "##"*35
- print "vlist contents :: ", len(vlist)
- print " # Current Video file Index Number Is :: ", index_no, "\n"
- if len(vlist) > 0:
- try:
- print "##"*35, "\n\n"
- p1 = subprocess.Popen(["ffplay.exe", "-autoexit", list(vlist)[index_no]])
- except:
- pass
- else:
- print "\n\nHello, There is no Video File in your PlayList !!!\n\n\n"
- if index_no <= len(vlist):
- index_no += 1
- def read_manual():
- try:
- subprocess.call(["notepad.exe", "source\\ffplay.help.txt"])
- except:
- print "Manual for ffplay Not Exists!!!"
- def start_ffmpeg_web():
- root1 = tk.Tk()
- myContainer2 = tk.Frame(root1)
- myContainer2.pack()
- myLabel1 = tk.Label(myContainer2)
- myLabel1.configure(text="Go to http://trac.ffmpeg.org", background="yellow")
- myLabel1.pack()
- button1 = tk.Button(myContainer2)
- button1.configure(text="OK", background="green")
- button1.pack()
- root1.update()
- time.sleep(2)
- root1.destroy()
- def about_ffplayer():
- print "\n FFPLAYER is a video player build using ffmpeg library..\n\t Build By ( Shishtpal )"
- root1 = tk.Tk()
- myContainer2 = tk.Frame(root1)
- myContainer2.pack()
- myLabel1 = tk.Label(myContainer2)
- myLabel1.configure(text="\n FFPLAYER is a video player build using ffmpeg library..\n\t Build By ( Shishtpal )", background="cyan")
- myLabel1.pack()
- button1 = tk.Button(myContainer2)
- button1.configure(text="OK", background="green")
- button1.pack()
- root1.update()
- time.sleep(4)
- root1.destroy()
- def explore_video_folder():
- loop_player()
- global index_no, vlist, cwd, p1
- print "\n##"*10
- print "\n ## After Exploring Video Folder I Found", len(vlist), "Files.."
- print " # Current Video file Index Number Is :: ", index_no
- print " # Your Working Directory is ::", cwd, "\n\n"
- if len(vlist) > 0:
- index_no = 0
- if p1.poll() == None:
- p1.kill()
- if True:
- for i in range(len(vlist)):
- print "\n", "##"*35
- print "\n #Playing Video File :: ", list(vlist)[index_no], "\n"
- p1 = subprocess.Popen(["ffplay.exe", "-autoexit", list(vlist)[index_no]])
- print "\n # Current Video file Index Number Is :: ", index_no, "\n"
- print "\n", "##"*35
- index_no += 1
- p1.wait()
- else:
- pass
- def loop_video():
- global index_no, p1, vlist
- try:
- if p1.poll() == None:
- p1.kill()
- print "\n", "##"*35
- print "\n # Current Video file Index Number Is :: ", index_no-1, "\n\n"
- p1 = subprocess.Popen(["ffplay.exe", "-autoexit", list(vlist)[index_no-1]])
- elif len(vlist) == 1:
- print "\n", "##"*35
- print "\n # Current Video file Index Number Is :: ", index_no, "\n\n"
- p1 = subprocess.Popen(["ffplay.exe", "-autoexit", list(vlist)[index_no]])
- else:
- print "\n", "##"*35
- print "\n # Current Video file Index Number Is :: ", index_no-1, "\n\n"
- p1 = subprocess.Popen(["ffplay.exe", "-autoexit", list(vlist)[index_no-1]])
- except:
- print " # Error in loop_video Function. #"
- def previous_video():
- global index_no, p1, vlist
- if index_no > 1:
- try:
- if p1.poll() == None:
- p1.kill()
- p1 = subprocess.Popen(["ffplay.exe", "-autoexit", list(vlist)[index_no-2]])
- else:
- p1 = subprocess.Popen(["ffplay.exe", "-autoexit", list(vlist)[index_no-2]])
- print "\n # Current Video file Index Number Is :: ", index_no-2, "\n"
- print "##"*35, "\n"
- if index_no != 0:
- index_no -= 1
- except:
- print "Error While playing Previous Video File.."
- else:
- print "There is No Previous Video File Exists..."
- index_no = 0
- root.bind("<m>", lambda e: play_video())
- root.bind("<M>", lambda e: play_video())
- root.bind("<n>", lambda e: next_video())
- root.bind("<N>", lambda e: next_video())
- root.bind("<k>", lambda e: previous_video())
- root.bind("<K>", lambda e: previous_video())
- root.bind("<l>", lambda e: loop_video())
- root.bind("<L>", lambda e: loop_video())
- filemenu2.add_command(label='Play Video (m)', command=play_video)
- filemenu2.add_command(label='Next Video (n)', command=next_video)
- filemenu2.add_command(label='Previous Video (k)', command=previous_video)
- filemenu2.add_command(label='Loop Video (l)', command=loop_video)
- filemenu2.add_separator()
- def print_playlist():
- print "\n", "@#"*30
- print "Play-list Contents :: ", "\n"
- for i, j in enumerate(vlist, 1):
- print i, j
- print "@#"*30, "\n"
- filemenu2.add_command(label='Print Playlist', command=print_playlist)
- def open_playlist_file():
- global vlist, index_no, p1
- print "Opening Play-list File :: "
- try:
- openfilename = tkFileDialog.askopenfilename(filetypes=[("PLT", "*.plt" )], title="Select Your Playlist File..", initialdir="C:\\")
- print "\n", "@#"*30
- print "You Select :: \n(", openfilename, ") \n\tPlay-list File..", "\n"
- y = open(openfilename)
- while True:
- a = y.readline()[:-1]
- if len(a) == 0:
- break
- else:
- vlist.add(a)
- y.close()
- print "\n", "@#"*30, "\n"
- except:
- print "No Play-List has been Selected..\n"
- filemenu2.add_command(label='Open Playlist File', command=open_playlist_file)
- def write_playlist_file():
- global vlist
- print "\n", "**"*30
- print "We have Write your Current Play-List File To Disk.."
- print "ffplayer_current_playlist.plt", "\n"
- x = open("ffplayer_current_playlist.plt", "w")
- for i in vlist:
- w = i+"\n"
- x.write(w)
- x.close()
- print "**"*30, "\n"
- filemenu2.add_command(label='Write Playlist File', command=write_playlist_file)
- def custom_playlist():
- print "Customizing Play-list Contents :: "
- #filemenu2.add_command(label='Custom Playlist', command=custom_playlist)
- filemenu2.add_separator()
- filemenu2.add_command(label='Explore Video Folder', command=explore_video_folder)
- filemenu3.add_command(label='Manual', command=read_manual)
- filemenu3.add_command(label='About FFMPEG', command=start_ffmpeg_web)
- def ffmpeg_howto():
- try:
- subprocess.Popen(["notepad.exe", "source\\ffmpeg.howto.txt"])
- except:
- print "FFMPEG How To Documentation File Not Exists.."
- filemenu3.add_command(label='FFMPEG How TO ', command=ffmpeg_howto)
- filemenu3.add_command(label='About ffplayer', command=about_ffplayer)
- def screen_resolution():
- """
- this code block is used to get Screen resolution of your desktop Screen.
- """
- global screensize
- user32 = ctypes.windll.user32
- screensize = user32.GetSystemMetrics(0), user32.GetSystemMetrics(1)
- print "Screen Resolution is :: ", screensize, "\n\n"
- screen_resolution()
- def vid_filter(filename):
- if os.path.isdir(filename) | filename.endswith(".jpg") | \
- filename.endswith(".png") | filename.endswith(".jpeg") | \
- filename.endswith(".JPG") | filename.endswith(".PNG") | \
- filename.endswith(".JPEG") | filename.endswith(".txt") | \
- filename.endswith(".tar.gz") | filename.endswith(".zip") | \
- filename.endswith(".7z") | filename.endswith(".exe") | \
- filename.endswith(".pdf") | filename.endswith(".htm") | \
- filename.endswith(".html") | filename.endswith(".mhtm") | \
- filename.endswith(".mhtml") | filename.endswith(".lnk") | \
- filename.endswith(".mht") | filename.endswith(".ini") | \
- filename.endswith(".db") | filename.endswith(".img") | \
- filename.endswith(".iso") | filename.endswith(".pkg") | \
- filename.endswith(".sh") | filename.endswith(".tgz") | \
- filename.endswith(".css") | filename.endswith(".gif") | \
- filename.endswith(".c4d") | filename.endswith(".xml") | \
- filename.endswith(".apk") | filename.endswith(".dat") | \
- filename.endswith(".doc") | filename.endswith(".docx") | \
- filename.endswith(".ppt") | filename.endswith(".pptx") | \
- filename.endswith(".xls") | filename.endswith(".xlsx") | \
- filename.endswith(".py") | filename.endswith(".pyw") | \
- filename.endswith(".pyc") | filename.endswith(".pyo") | \
- filename.endswith(".chm") | filename.endswith(".js") | \
- filename.endswith(".gz") | filename.endswith(".cfg") | \
- filename.endswith(".inf") | filename.endswith(".sys") | \
- filename.endswith(".dll"):
- return True
- def vid_player(cwd):
- global p1, vlist
- if os.path.isfile(cwd):
- vlist.add(cwd)
- p1 = subprocess.Popen(["ffplay.exe", "-autoexit", cwd])
- elif os.path.isdir(cwd):
- for i in os.listdir(cwd):
- try:
- filename = os.path.join(cwd, i)
- if vid_filter(filename):
- pass
- else:
- vlist.add(filename)
- except:
- print "Error While Filtering File Formats..\n\t In vid_player Function..\n"
- pass
- else:
- print "Hi, I Do not Know, what you Defined !!\n\t as a video file or a folder which contains video files..\n"
- def loop_player():
- """
- This code Block create a list of each and every file recursively,
- But we have used a filter So that wrong File Formats will not be used with
- ffplayer, because this just gives you an error,
- we can also use ffrpobe to know if supplied file is a video file, but this is just
- time consuming process, this would be great if you just use a filter.
- """
- global files, vlist, index_no, cwd
- files = []
- for i in zip(os.walk(cwd)):
- files.append(i)
- for i in range(len(files)):
- for j in files[i][0][2]:
- try:
- filename = os.path.join(files[i][0][0], str(j))
- if vid_filter(filename):
- pass
- else:
- vlist.add(filename)
- except:
- print "Error While Filtering File Formats !! In explore video folder Function !!"
- pass
- #
- tk_gui()
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement