Paste: randomfile
Author: | redline6561 |
Mode: | factor |
Date: | Fri, 6 Nov 2009 03:48:48 |
Plain Text |
USING: kernel namespaces sequences arrays random command-line
combinators io io.pathnames io.launcher io.directories.search ;
IN: randomfile
: display-usage ( -- ) "Usage: randomfile <path>" print ;
: video? ( extension -- ? )
{ "avi" "mp4" "mov" "flv" "m4v" "mpg" "mkv" "ogm" "ogv" } member? ;
: image? ( extension -- ? )
{ "jpg" "png" } member? ;
: mp3? ( extension -- ? ) "mp3" = ;
: ogg? ( extension -- ? ) "ogg" = ;
: play ( filepath -- process )
{
{ [ dup video? ] [ { "smplayer" "-fullscreen" } swap suffix run-process ] }
{ [ dup image? ] [ { "feh" "--bg-scale" } swap suffix run-process ] }
{ [ dup mp3? ] [ "mpg123" swap 2array run-process ] }
{ [ dup ogg? ] [ "ogg123" swap 2array run-process ] }
[ "Error: Not implemented yet." ]
} cond ;
: choose-file ( dirpath -- filepath )
t recursive-directory-files 1 sample first ;
: randomfile ( -- object )
command-line get
[ current-directory get choose-file ]
[ choose-file ]
if-empty play ;
MAIN: randomfile
Author: | redline6561 |
Mode: | factor |
Date: | Fri, 6 Nov 2009 04:06:13 |
Plain Text |
USING: kernel namespaces sequences arrays random command-line
combinators io io.pathnames io.launcher io.directories.search ;
IN: randomfile
: display-usage ( -- ) "Usage: randomfile <path>" print ;
: video? ( extension -- ? )
{ "avi" "mp4" "mov" "flv" "m4v" "mpg" "mkv" "ogm" "ogv" } member? ;
: image? ( extension -- ? )
{ "jpg" "png" } member? ;
: mp3? ( extension -- ? ) "mp3" = ;
: ogg? ( extension -- ? ) "ogg" = ;
: play ( filepath -- process )
{
{ [ dup file-extension video? ] [ { "smplayer" "-fullscreen" } ] }
{ [ dup file-extension image? ] [ { "feh" "--bg-scale" } ] }
{ [ dup file-extension mp3? ] [ { "mpg123" } ] }
{ [ dup file-extension ogg? ] [ { "ogg123" } ] }
[ "Error: Not implemented yet." ]
} cond swap suffix run-process ;
: choose-file ( dirpath -- filepath )
t recursive-directory-files 1 sample first ;
: randomfile ( -- object )
command-line get
[ current-directory get choose-file ]
[ choose-file ]
if-empty play ;
MAIN: randomfile
New Annotation