Skip to content
Browse files

Add media script which is a simple mplayer launcher.

  • Loading branch information...
1 parent 782f152 commit 359b047346c3d9006a894cca3a62b43738d1a24d @mfs committed Oct 12, 2012
Showing with 58 additions and 0 deletions.
  1. +1 −0 README.markdown
  2. +57 −0 media
View
1 README.markdown
@@ -2,3 +2,4 @@
- find-images Search for images greater than a certain dimension.
- check-repo Check a git repo's remote for new tags.
+- media A simple mplayer launcher.
View
57 media
@@ -0,0 +1,57 @@
+#!/usr/bin/env python3
+
+# Copyright 2012 Mike Sampson
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+import sys
+import glob
+import mimetypes
+import subprocess
+
+def mplayer(filename):
+ fd = open('/dev/null')
+ subprocess.Popen(['mplayer', filename], stdin = fd, stdout = fd, stderr = fd)
+ fd.close()
+
+def select_media():
+ def fn(filename):
+ mt = mimetypes.guess_type(filename)[0]
+ return mt != None and mt.startswith('video')
+
+ files = list(filter(fn, glob.glob('*')))
+
+ if not files:
+ print('No media files found in current directory.')
+ return
+
+ files.sort()
+
+ for i,f in enumerate(files):
+ print('[%2d] - %s' % (i, f))
+
+ selection = input('\nSelect file to play (0 to %d, q to quit): ' % (len(files) - 1))
+ if selection == 'q':
+ return
+
+ try:
+ selection = int(selection)
+ mplayer(files[selection])
+ except:
+ print('Invalid selection.')
+
+if len(sys.argv) == 1:
+ select_media()
+else:
+ mplayer(sys.argv[1])

0 comments on commit 359b047

Please sign in to comment.
Something went wrong with that request. Please try again.