You are not logged in.

#101 2008-12-04 10:25:02

andr3as
Member
Registered: 2008-10-06
Posts: 51

Re: Post your handy self made command line utilities

If you use MPD and a tiling WM you might find this script useful, expecially if you bind it to a shortcut:

#!/bin/bash
mpc play `mpc playlist | sed -e "s/^>/ /" | dmenu -i | grep -P -o "^ \d+" `

It lets you select any track from your current MPD playlist and plays it ;-)

Offline

#102 2008-12-04 11:50:39

crouse
Arch Linux f@h Team Member
From: Iowa - USA
Registered: 2006-08-19
Posts: 903
Website

Re: Post your handy self made command line utilities

Here is a link to a bunch of Bash Batch Image Processing Scripts I wrote a few years back.
Nothing real fancy, but very useful wink

What does this stuff do ? -- bbhelp
These commands run from the command line and edit/modify all the jpegs in a directory.

http://internap.dl.sourceforge.net/sour … lu2.tar.gz

BBIPS command line utility help

WARNING - most bbips commands work DIRECTLEY on your images !!!
It is recommended that you work on jpg COPIES ONLY to prevent loss of originals.

bbcopy | Create a directory and COPY all images into it.
------------------
bbresize | RESIZEs all images width x height
bbrotate | ROTATEs all images clockwise x number of degrees
bbflip | FLIPs images top to bottom vertically.
bbflop | FLOPs images side to side horizontally.
bbatxt | ADDS TEXT to images.
------------------
bbborder | Creates a border on all images color x size
bbgrayscale | Converts images to Black and White
bbsepia | Converts all images to SEPIA toned x percentage
bbpaint | Simulates an oil painting on all images
bbnormalize | Normalizes all images
bbcolorize | Colorizes all images. Format rgb.
bbgamma | Gamma correct for all images
bbsolarize | Solorizes all images.
------------------
bbhelp | This lists the bbips command alias's
bbindex | Creates a index.jpg of all .jpg (not .JPG) files.
bbgzip | Creates a GZIPped file containing all the images.
------------------
bbapcom | APpend COMments to the images.
bbrecom | Displays (REads) COMments on all images.
bbwrcom | WRites COMments to all images, overwriting any existing comments.

Last edited by crouse (2008-12-04 11:52:10)

Offline

#103 2008-12-04 19:09:33

whukes
Member
Registered: 2008-07-18
Posts: 34

Re: Post your handy self made command line utilities

I wrote this bash script to rip dvds I get from netflix.  The script uses dvdbackup and handbrake depending on what options you select.

I also like to quickly rip the discs and mail them back so you can copy the VOBs to your harddrive first using the dvdbackup multidisc mode. The multidisc handbrake mode skips the copying of VOBs.

Useful as hell for me smile


#!/bin/bash

#GLOBALS

DIN="/dev/dvd" #input
DOUT="/home/$USER/download/rips" #output
VBTR="4000" #bitrate
ABTR="192" #bitrate

discinfo(){
    
    dvdbackup -i ${DIN} -I > ${DOUT}/file
    TITLE=`grep information ${DOUT}/file | cut -c44-56`
    TNUM=`grep containing ${DOUT}/file | cut -c43-45`
    rm ${DOUT}/file
}

discinfoi(){
    
    dvdbackup -i ${DIN} -I > ${DOUT}/file
    TITLE[INDEX]=`grep information ${DOUT}/file | cut -c44-56`
    TNUM[INDEX]=`grep containing ${DOUT}/file | cut -c43-45`
    rm ${DOUT}/file
}

singled(){

    discinfo
    
    dvdbackup -i ${DIN} -o ${DOUT} -M
    sleep 10s
    
    handbrake -i ${DOUT}/${TITLE}/VIDEO_TS -o ${DOUT}/${TITLE}.mp4 -t ${TNUM} -U -F -f mp4 -e x264 -b ${VBTR} -B ${ABTR}
    rm -rf ${DOUT}/${TITLE}

}

singleh(){

    discinfo
    
    handbrake -i ${DIN} -o ${DOUT}/${TITLE}.mp4 -L -U -F -f mp4 -e x264 -b ${VBTR} -B ${ABTR}

}

multid(){

    main

    INDEX=0
    let INDEXA=DISC-1

    while [ $INDEX -lt $DISC ]; do
    
        discinfoi        

        dvdbackup -i ${DIN} -o ${DOUT} -M
    
        if [ "$INDEX" -ne "$INDEXA" ]; then
            echo "Please insert the next disc [enter]"
            read CHNG
        fi
    
    let INDEX=INDEX+1        
    
    done

    INDEX=0
    while [ $INDEX -lt $DISC ]; do
        handbrake -i ${DOUT}/${TITLE[INDEX]}/VIDEO_TS -o ${DOUT}/${TITLE[INDEX]}.mp4 -t ${TNUM[INDEX]} -U -F -f mp4 -e x264 -b ${VBTR} -B ${ABTR}
        rm -rf ${DOUT}/${TITLE[INDEX]}
        let INDEX=INDEX+1
    done
    
    exit
}

multih(){

    main

    INDEX=0
    let INDEXA=DISC-1

    while [ $INDEX -lt $DISC ]; do
    
        discinfoi
        
        handbrake -i ${DIN} -o ${DOUT}/${TITLE[INDEX]}.mp4 -L -U -F -f mp4 -e x264 -b ${VBTR} -B ${ABTR}
    
        if [ "$INDEX" -ne "$INDEXA" ]; then
            echo "Please insert the next disc [enter]"
            read CHNG
        fi
    
        let INDEX=INDEX+1        
    
    done

    exit
}


main(){
clear

echo "********************************************"
echo "********************************************"
echo "********************************************"
echo "******                                ******"
echo "******          rdvdp 0.1             ******"
echo "******                                ******"
echo "******        It's Automatic!         ******"
echo "******                                ******"
echo "******Will automagically rip a dvd and******"
echo "******  name it after the dvd title.  ******"
echo "******                                ******"
echo "******                                ******"
echo "******   Use dvdbackup to dump dvd    ******"
echo "******                                ******"
echo "******                                ******"
echo "******                                ******"
echo "********************************************"
echo "********************************************"
echo "**************************************whukes"
echo " "
}

#MAIN

main

printf "Multi-Disc Mode [dvdbackup] [y]: "
read MDMD
printf "Multi-Disc Mode [handbrake] [y]: "
read MDMH
printf "Single [dvdbackup] [y]: "
read SDVD
printf "Single [handbrake]: "
read SHND

if [ -n "$MDMD" ]; then
    if [ $MDMD = "y" ]; then
        echo " "
        printf "Enter the numbers of discs: "
        read DISC
        multid
    fi
fi

if [ -n "$MDMH" ]; then
    if [ $MDMH = "y" ]; then
        echo " "
        printf "Enter the numbers of discs: "
        read DISC
        multih
    fi
fi

if [ -n "$SDVD" ]; then
    if [ $SDVD = "y" ]; then
        singled
    fi
fi

singleh

Offline

#104 2008-12-04 19:15:39

Daenyth
Forum Fellow
From: Boston, MA
Registered: 2008-02-24
Posts: 1,244

Re: Post your handy self made command line utilities

Damn, that's useful. I had tried to write something similar but there were so many options available and I got a bit confused. How long does it take to run on a typical DVD?

Offline

#105 2008-12-04 19:17:34

rson451
Member
From: Annapolis, MD USA
Registered: 2007-04-15
Posts: 1,233
Website

Re: Post your handy self made command line utilities

Hell yeah.  That should go on the script wiki for sure.


archlinux - please read this and this — twice — then ask questions.
--
http://rsontech.net | http://github.com/rson

Offline

#106 2008-12-04 19:24:58

whukes
Member
Registered: 2008-07-18
Posts: 34

Re: Post your handy self made command line utilities

Daenyth wrote:

Damn, that's useful. I had tried to write something similar but there were so many options available and I got a bit confused. How long does it take to run on a typical DVD?

Really depends on your hardware.  On my system (E6600 duo core w/ 2gb ram) it will take slightly less time than the length of the movie.  If you use the multidisc mode that copies the VOBs it will take around 15 min per disc to copy the vobs but then rips automatically with no user intervention.

I really need to add a way to rip discs with episodes on them.  That would make the script even more useful big_smile

Offline

#107 2008-12-04 19:41:26

Zariel
Member
Registered: 2008-10-07
Posts: 446

Re: Post your handy self made command line utilities

hm, seems interesting. Though i do all my rips with dvd decryptor on windows *snickers*

Offline

#108 2008-12-05 00:39:29

Daenyth
Forum Fellow
From: Boston, MA
Registered: 2008-02-24
Posts: 1,244

Re: Post your handy self made command line utilities

whukes wrote:

Really depends on your hardware.  On my system (E6600 duo core w/ 2gb ram) it will take slightly less time than the length of the movie.  If you use the multidisc mode that copies the VOBs it will take around 15 min per disc to copy the vobs but then rips automatically with no user intervention.

I really need to add a way to rip discs with episodes on them.  That would make the script even more useful big_smile

When you say that it takes about as long as the length of the movie, is that for encoding to compressed video + container? And the other is just time taken ripping only?

Offline

#109 2008-12-05 02:49:08

whukes
Member
Registered: 2008-07-18
Posts: 34

Re: Post your handy self made command line utilities

Daenyth wrote:

When you say that it takes about as long as the length of the movie, is that for encoding to compressed video + container? And the other is just time taken ripping only?

The length of time it takes to go from dvd to x264 mp4 is slight less than the length movie. 

The time it takes to rip VOBs to your hd than goto x264 mp4 is 15 minutes longer than the previous.

So to answer your question.  Yes.  Sometimes I can't get handbrake to work with certain dvds without ripping vobs.

Offline

#110 2008-12-05 03:19:50

Daenyth
Forum Fellow
From: Boston, MA
Registered: 2008-02-24
Posts: 1,244

Re: Post your handy self made command line utilities

Does it have a setting to rip vobs only and then go back to them later? :]

I haven't looked much at the code, shouldn't be hard to do.

Offline

#111 2008-12-05 18:55:50

whukes
Member
Registered: 2008-07-18
Posts: 34

Re: Post your handy self made command line utilities

Daenyth wrote:

Does it have a setting to rip vobs only and then go back to them later? :]

I haven't looked much at the code, shouldn't be hard to do.

just do "dvdbackup -i /dev/dvd -o output -M"

Offline

#112 2008-12-05 20:04:24

Daenyth
Forum Fellow
From: Boston, MA
Registered: 2008-02-24
Posts: 1,244

Re: Post your handy self made command line utilities

So simple! Thanks for the tip.

Offline

#113 2008-12-05 20:09:07

Daenyth
Forum Fellow
From: Boston, MA
Registered: 2008-02-24
Posts: 1,244

Re: Post your handy self made command line utilities

rson451 wrote:

Hell yeah.  That should go on the script wiki for sure.

I added my MPD stat script

Offline

#114 2008-12-05 20:16:48

haxit
Member
From: /home/haxit
Registered: 2008-03-04
Posts: 1,247
Website

Re: Post your handy self made command line utilities

Guys, if you have time, post some of these to the ScriptWiki!


Archi686 User | Old Screenshots | Old .Configs
Vi veri universum vivus vici.

Offline

#115 2008-12-05 20:49:32

rson451
Member
From: Annapolis, MD USA
Registered: 2007-04-15
Posts: 1,233
Website

Re: Post your handy self made command line utilities

Daenyth wrote:
rson451 wrote:

Hell yeah.  That should go on the script wiki for sure.

I added my MPD stat script

Sweet.  I'd post some more from this thread to the wiki but I don't want to put other people's work there without them saying ok.


archlinux - please read this and this — twice — then ask questions.
--
http://rsontech.net | http://github.com/rson

Offline

#116 2008-12-07 17:35:37

Daenyth
Forum Fellow
From: Boston, MA
Registered: 2008-02-24
Posts: 1,244

Re: Post your handy self made command line utilities

I wrote this irssi script to tab complete to the nick who most recently spoke in a channel http://rafb.net/p/StDVwR51.html

I submitted it for scripts.irssi.org, it should be up there at some point.
EDIT: Uploaded
download
view source

Last edited by Daenyth (2008-12-07 18:06:27)

Offline

#117 2008-12-11 04:17:30

lldmer
Member
From: Amsterdam
Registered: 2008-05-17
Posts: 119

Re: Post your handy self made command line utilities

So many nice scripts in here!

I kind of want to learn some 'real' scripting language like python or ruby, so here are my first steps in ruby. It copies some of my favourite config files to a remote directory (with sshfs), and then adds them to my git repository.
Plz give me your tips and improvements:P

#!/usr/bin/env ruby
MNTDIR = "/mnt/slaaf"
# [user@]remotehost:/remote/destination/dir
@rmtdir = "user@slaaf:/home/user/config_home"
@config_home = "user@slaaf:/home/user/config_home"
@config_system = "user@slaaf:/home/user/config_whuuza"

def ask()
    answer = STDIN.gets.chomp
    answer.downcase
    if !((answer == "y") or (answer == "yes"))
        puts "Aborting Mission."
        return 1
    else
        return 0
    end
end

def togit(file)
    for f in file
        system("cp -r #{f} #{MNTDIR}/#{f} && cd #{MNTDIR} && git add #{f}")
        if $? == 0
            puts "Copied #{f} to #{MNTDIR} and added it to GIT."
        end
    end
end

def mount(rmtdir, mntdir)
    `mount | grep " on #{MNTDIR} "` 
    if not $? == 0
        system("sshfs #{rmtdir} #{mntdir}")
        status = $?
        return status    
    else 
        puts "It seems something is already mounted on #{mntdir}. Do you still want to copy your stuff there (y/n)?"
        status = ask()
        return status    
    end    
end

def check_dirvar(dir, var_name)
    if !dir.nil?
        @rmtdir = dir
        return 0
    else
        puts "You chose to use a preset remote directory #{var_name}, but it is not set."
        puts "Do you want to continue using the default remote directory " + @rmtdir + "?"
        answer = ask()
        return answer
    end
end

def checkargs()
    if ARGV[0] == "-h"
        ARGV.delete_at(0)
        status = check_dirvar(@config_home, "@config_home")
        return status
    elsif ARGV[0] == "-s"
        ARGV.delete_at(0)
        status = check_dirvar(@config_system, "@config_system")
        return status        
    end
end

begin 

if not ARGV.empty?
    argerr = checkargs()    
    if argerr == 0
        mnterr = mount(@rmtdir, MNTDIR)
        if (mnterr == 0)
            togit(ARGV)
            system("fusermount -u #{MNTDIR}")
            if !($? == 0)
                puts "unmount failed"
            end           
        else
            puts "error mounting filesystem"
        end
    end
else
    puts "Usage: #{$0} <file1> <file2> ..."
end

end

For lack of better words: chair, never, toothbrush, really. Ohw, and fish!

Offline

#118 2008-12-11 12:20:22

crouse
Arch Linux f@h Team Member
From: Iowa - USA
Registered: 2006-08-19
Posts: 903
Website

Re: Post your handy self made command line utilities

A simple python phonebook app. Trying to learn python...still lol.

#!/usr/bin/env python
# Author: Crouse
# A Simple Python Phone Book v2

import os

# Full path to the file containing the data - Adjust to your needs.
addressbook = "phonebook.txt"

# Write and Search functions
def WriteEntry_():
    name = raw_input("        Enter name: ")
    phone = raw_input("        Enter phone number: ")
    f=open(addressbook, 'a')
    f.write(name + "    " + phone + '\n')
    f.close()
    print "\n"
    print "        Added: " + name + "   " + phone + " to the phone list.\n"


def SearchEntry_():
    os.system(['clear','cls'][os.name == 'nt'])
    print "-------------------------------------------\n"
    print "------ A Simple Python Phone Book v2 ------\n"
    print "-----------------------------------Crouse--\n\n"
    searchfor= raw_input("        Enter search term: ")
    print "\n"
    print "--------- RESULTS --------\n"
    searchforlower=searchfor.lower()
    try:
        f=open(addressbook, 'r')
        for line in f:
            if line.lower().startswith(searchforlower):
                print line.rstrip("\n")
        f.close()
    except:
        print "Sorry - There doesn't appear to be a database yet."
        print "Please create an entry first and then retry searching."
    print "--------------------------\n"

 # The Menu
while True:
        os.system(['clear','cls'][os.name == 'nt'])
        # Menu Displayed
        print "-------------------------------------------\n"
        print "------ A Simple Python Phone Book v2 ------\n"
        print "-----------------------------------Crouse--\n"
        selection = raw_input("\n\
        s) Search Phonebook\n\
        a) Add to Phonebook\n\
        q) Quit\n\n\
        What would you like to do?  ")
        print"\n"
        # Returned Answer acted upon.
        if selection == "s":
                SearchEntry_()
        elif selection == "a":
                WriteEntry_()
        elif selection == "e":
                break
        elif selection == "q":
                break
        else:
                print "        Not a valid Choice."
        raw_input("        Hit any key to continue") 
exit

A screenshot
phonebook.jpg

Offline

#119 2008-12-11 14:02:42

mentallaxative
Member
From: Australia
Registered: 2008-07-14
Posts: 134
Website

Re: Post your handy self made command line utilities

Not much of a Ruby presence here, except for lldmer. tongue

I've been learning my way around Hpricot and applied my knowledge to a Wikipedia screen scraper. When given an argument, it searches Wikipedia and prints back a list of search results. It also only prints out the overview of an article, not everything.

#!/usr/bin/env ruby
# Wikiscraper
# written by mentallaxative
#

require 'rubygems'
require 'hpricot'
require 'open-uri'

class Wikiscraper

  def initialize(arguments)
    #ARGV needs to be cleared else it ends up in 'gets'
    @keyword = arguments.join(" ")
    substitutions = {' ' => '+', '(' => '%28', ')' => '%29'}
    substitutions.each_pair {|a,b| @keyword.gsub!(a, b) }
    arguments.clear
    
    @search_links = []
  end

  def main
    process_search
    populate_arrays
    get_selection
    final_page_processing
  end

  #open our search
  def process_search
    search_uri = "http://en.wikipedia.org/wiki/Special:Search?search=#{@keyword}&fulltext=Search"
    @s_page = Hpricot(open(search_uri))
  end

  def populate_arrays
    #results_data contains all search result names
    results_data = (@s_page/"ul.mw-search-results/li/:not(div.mw-search-result-data)").inner_text

    #search_links is an array of links of search results
    (@s_page/"ul.mw-search-results"/:a).each do |ah|
      @search_links << ah.attributes['href'].sub!('/wiki/', 'http://en.wikipedia.org/wiki/') 
    end

    s_entries = []
    results_data.each_line {|x| s_entries << "#{x}\r"}
    #print out the search results
    s_entries.each_index {|x| print "#{x+1}: #{s_entries[x]}"}
  end

  def get_selection
    toc_string = '<table class="toc" id="toc" summary="Contents">'

    puts "\nType in a entry number:"
    @number = gets.chomp!.to_i-1
    selection = Hpricot(open(@search_links[@number]))

    #gets rid of everything after the table of contents
    if selection.to_s.index(toc_string) == nil
      @wiki_results = selection
    else
      @wiki_results = Hpricot(selection.to_s.slice(1..selection.to_s.index(toc_string)))
    end
  end

  def final_page_processing
    (@wiki_results/"table.infobox").remove
    @text_body = (@wiki_results/"#bodyContent/p/:not(#coordinates)")

    no_article_found = (@wiki_results/"div.noarticletext")

    if not no_article_found.empty?
      puts no_article_found.inner_text
    else
      puts((@wiki_results/"div.dablink").inner_text) #disambig info
      puts "\n"
      #get rid of citation marks like [1], [3], [12]
      @text_body.inner_text.gsub(/\[[\w\d]{0,3}\]/, "").each {|c| puts c}
    end
  end

end

if ARGV.empty?
  puts "Please supply a subject to search Wikipedia for."
else
  scrape = Wikiscraper.new(ARGV)
  scrape.main
end

Offline

#120 2008-12-11 14:38:18

mentallaxative
Member
From: Australia
Registered: 2008-07-14
Posts: 134
Website

Re: Post your handy self made command line utilities

lldmer wrote:

So many nice scripts in here!

I kind of want to learn some 'real' scripting language like python or ruby, so here are my first steps in ruby. It copies some of my favourite config files to a remote directory (with sshfs), and then adds them to my git repository.
Plz give me your tips and improvements:P

You used Python before, didn't you? wink The de facto indenting style for Ruby is two spaces, not four as in Python. You don't need to use the return keyword that often--Ruby always returns the last statement made, so you can just write 'status' instead of 'return status'. I think you also forgot a ! at the end of 'answer.downcase' otherwise the answer variable won't get modified, or you could stick it at the end of gets.chomp and save one line. Your use of 0's and 1's is a bit strange to me too... personally I'd use true and false, but you're happy with it, that's okay.

Offline

#121 2008-12-11 15:55:22

Daenyth
Forum Fellow
From: Boston, MA
Registered: 2008-02-24
Posts: 1,244

Re: Post your handy self made command line utilities

mentallaxative wrote:

You don't need to use the return keyword that often--Ruby always returns the last statement made, so you can just write 'status' instead of 'return status'.

While this may be true (perl does the same), I consider it bad style. Implicitness is nice, but I find a nice mental aid for both the coder and anyone reading the code to explicitly return. It's very easy to forget that something returns and then get the wrong result from a function.

Offline

#122 2008-12-11 18:07:05

anrxc
Member
From: Croatia
Registered: 2008-03-22
Posts: 833
Website

Re: Post your handy self made command line utilities

These could be useful to others,
subconvert.py -- Converts between MicroDVD (sub) and SubRip (srt) subtitle formats
http://sysphere.org/~anrxc/local/scr/sources/subconvert

rybackup.sh -- rsync based backup script with rotating backup-snapshots and hard-links
http://sysphere.org/~anrxc/local/scr/so … ybackup.sh

sput.py -- scp upload, I got tired of tracking ports and it's quicker to edit than ~/.ssh/config
http://sysphere.org/~anrxc/local/scr/sources/sput.py


You need to install an RTFM interface.

Offline

#123 2008-12-11 18:32:32

Daenyth
Forum Fellow
From: Boston, MA
Registered: 2008-02-24
Posts: 1,244

Re: Post your handy self made command line utilities

What's the point of backing up if you're using a hardlink? If the drive dies then you lose the backup too... The point is usually to put the backup on a DIFFERENT drive tongue

Offline

#124 2008-12-11 18:37:59

Dieter@be
Forum Fellow
From: Belgium
Registered: 2006-11-05
Posts: 1,958
Website

Re: Post your handy self made command line utilities

Daenyth wrote:

What's the point of backing up if you're using a hardlink? If the drive dies then you lose the backup too... The point is usually to put the backup on a DIFFERENT drive tongue

he makes hardlinks on the destination. eg with the goal of doing de-duplication when storing multiple snapshots.
I think he just wanted to re-implement rsnapshot ( http://www.rsnapshot.org/ ) ;-)


< Daenyth> and he works prolifically
4 8 15 16 23 42

Offline

#125 2008-12-11 18:41:15

Daenyth
Forum Fellow
From: Boston, MA
Registered: 2008-02-24
Posts: 1,244

Re: Post your handy self made command line utilities

I got sig'd!

Offline

Board footer

Powered by FluxBB