Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- video_ext="avi mkv"
- player="smplayer -fullscreen"
- items_per_page=15
- more_label="More"
- playlist_enable=1
- playlist_minimum=5
- playlist_label="[Playlist]"
- list_dir()
- {
- local dir=$1
- local names="-iname '*.iso'"
- for ext in $video_ext; do
- names="$names -or -iname '*.${ext}'"
- done
- eval find -s "\"$dir\"" -mindepth 1 -maxdepth 1 -type d -or $names | while read item; do
- if [ `basename "$item" | cut -c 1` = '.' ]; then
- continue
- fi
- if [ -d "$item" -a `count_video "$item"` -eq 0 ]; then
- continue
- fi
- echo "$item"
- done
- }
- count_video()
- {
- local dir=$1
- local names="-name 'VIDEO_TS' -or -iname '*.iso'"
- for ext in $video_ext; do
- names="$names -or -iname '*.${ext}'"
- done
- eval find "\"$dir\"" $names | wc -l
- }
- remove_ext()
- {
- basename "$1" | sed 's/^\(.*\)\..*$/\1/' | sed 's/_/ /g'
- }
- xml_escape()
- {
- echo "$1" | sed 's/&/\&/g'
- }
- print_video()
- {
- local file=$1
- local label=`remove_ext "$file"`
- echo "<item label=\"`xml_escape "$label"`\">"
- echo " <action name=\"Execute\">"
- echo " <command>$player "`xml_escape "$file"`"</command>"
- echo " </action>"
- echo "</item>"
- }
- print_playlist()
- {
- local files=$1
- echo "<item label=\"`xml_escape "$playlist_label"`\">"
- echo " <action name=\"Execute\">"
- echo " <command>$player `xml_escape "$files"`</command>"
- echo " </action>"
- echo "</item>"
- }
- print_dvd()
- {
- local file=$1
- if [ -d "$file" ]; then
- local label=`basename "$file"`
- else
- local label=`remove_ext "$file"`
- fi
- echo "<item label=\"`xml_escape "$label"`\">"
- echo " <action name=\"Execute\">"
- echo " <command>$player "dvdnav:///`xml_escape "$file"`"</command>"
- echo " </action>"
- echo "</item>"
- }
- print_dir()
- {
- local dir=$1
- local wrap_in_menu=$2
- if [ -d "$dir/VIDEO_TS" ]; then
- print_dvd "$dir"
- return 0
- fi
- local basename=`basename "$dir"`
- local items=`list_dir "$dir" | wc -l`
- local pages=$(($items / $items_per_page))
- if [ `expr $items % $items_per_page` = "0" ]; then
- pages=$(($pages - 1))
- fi
- if [ $items -le 1 ]; then
- wrap_in_menu="no"
- fi
- if [ "$wrap_in_menu" != "no" ]; then
- local menu_id=`echo "x$dir" | sed 's/\([^a-z0-9]\)//gI'`
- echo "<menu id=\"$menu_id\" label=\"`xml_escape "$basename"`\">"
- fi
- local item_count=0
- local pages_count=0
- local playlist=""
- local playlist_count=0
- list_dir "$dir" | while read item; do
- if [ $item_count -gt 0 -a $(($item_count % $items_per_page)) -eq 0 ]; then
- echo
- echo "<menu id=\"${menu_id}More${pages_count}\" label=\"`xml_escape "$more_label"`\">"
- pages_count=$(($pages_count + 1))
- fi
- if [ -d "$item" ]; then
- print_dir "$item"
- elif [ `echo "$item" | grep '^.*\.iso$' | wc -l` -eq 1 ]; then
- print_dvd "$item"
- else
- print_video "$item"
- if [ $playlist_enable -eq 1 ]; then
- for ext in $video_ext; do
- if [ `echo "$item" | grep "^.*\\.${ext}\$" | wc -l` -eq 1 ]; then
- playlist="$playlist \"$item\""
- playlist_count=$(($playlist_count + 1))
- break
- fi
- done
- fi
- fi
- item_count=$(($item_count + 1))
- if [ $playlist_enable -eq 1 -a $item_count -ge $items -a $playlist_count -ge $playlist_minimum ]; then
- print_playlist "$playlist"
- fi
- done
- while [ "$pages" -gt 0 ]; do
- echo "</menu>"
- pages=$(($pages - 1))
- done
- if [ "$wrap_in_menu" != "no" ]; then
- echo "</menu>"
- fi
- }
- echo "<openbox_pipe_menu>"
- print_dir "$1" no
- echo "</openbox_pipe_menu>"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement