Archive for the ‘python’ Category

vuze crashes after some time

April 12, 2016 Leave a comment

I like the bittorrent client Vuze but it crashes on some of my machines after a while.

I wrote a monitoring script that is checking if vuze is running. If vuze dies, the script restarts vuze automatically.

The source code is here: .

Categories: linux, manjaro, python

dropbox: command-line interface

September 12, 2015 Leave a comment

I wanted to test the status of my Dropbox client from the terminal. Actually, I wanted to write a script that executes an action when my Dropbox folder is fully synced. So I wanted to test the status if it’s “working” or “synced”.

I found the solution here. It turned out that Dropbox has an official command-line script that can do this and much more. First, get it:

wget -O ~/
chmod u+x ~/
~/ status

This is a Python script, written in Python 2, thus I modified the first line to be “#!/usr/bin/env python2“.

This script can do several things for you:

Dropbox command-line interface


Note: use dropbox help  to view usage for a specific command.

 status       get current status of the dropboxd
 help         provide help
 puburl       get public url of a file in your dropbox
 stop         stop dropboxd
 running      return whether dropbox is running
 start        start dropboxd
 filestatus   get current sync status of one or more files
 ls           list directory contents with current sync status
 autostart    automatically start dropbox at login
 exclude      ignores/excludes a directory from syncing
 lansync      enables or disables LAN sync

Some years ago I wrote a simple script to get the public URL of a file in my Dropbox folder. This script can do that too with the “puburl” command.

Categories: bash, python Tags: , ,

reddit from the terminal

September 7, 2015 Leave a comment

There is a command line interface for Reddit called “rtv” (reddit terminal viewer). It’s written in Python, so you can install it with pip.

Here is a short youtube video on how to use it.

Categories: bash, linux, python Tags: , ,

extract an animated gif from a video

You have a video and you want to create an animated gif from a part of it.

You can use MoviePy for that. Here you can find a blog post from the author of MoviePy, where the process is explained through several examples. Here I copy three simple examples:

Example 1:

from moviepy.editor import *

clip = (VideoFileClip("frozen_trailer.mp4")  # input video
        .subclip((1,22.65),(1,23.2))         # part to extract, where 1’22.65 means 1 minute 22.65 seconds
        .resize(0.3))                        # resize to 30% of the original
clip.write_gif("use_your_head.gif")          # output animated gif

Example 2 (cropping):

kris_sven = (VideoFileClip("frozen_trailer.mp4")
             .crop(x1=145,x2=400))  # cropping: remove left-right borders

Example 3 (play forward and backward):

def time_symetrize(clip):
    return concatenate([clip, clip.fx( vfx.time_mirror )])

clip = (VideoFileClip("frozen_trailer.mp4", audio=False)
        .crop(x1=189, x2=433)
        .fx( time_symetrize ))  # the effect is added here

For more advanced usage, see the original blog post.

Categories: python Tags: , , ,

copy large files between computers at home over the network

January 2, 2015 Leave a comment

I have a desktop machine at home with a Windows 2007 virtual machine. I mainly have it because of Powerpoint. Recently I prefer to work on my laptop in the living room. Today I needed Powerpoint, so I decided to copy the whole Windows virtual machine and put it on my laptop. The only problem is that it was 67 GB and I didn’t have that much space on my external HDDs :(

Don’t panic. On my desktop machine I entered the folder that I wanted to copy and started a web server:

python -m SimpleHTTPServer

With “ifconfig” I checked the local IP address of the machine, it was

On my laptop I opened a browser and navigated to ““. All the files I needed were there. Since I’m lazy and I didn’t want to click on each link one by one, I issued the following command (tip from here):

wget -r --no-parent

The download speed was about 10 MB/sec, so it took almost 2 hours.

Categories: network, python Tags: , ,

media info

December 28, 2014 Leave a comment

You have a media file (audio, video, image) and you want to get some detailed information about it: duration, bit rate, resolution, etc. How to extract these pieces of information?

Use the MediaInfo project. You can install it via your package manager and you will get a command called “mediainfo”.


$ mediainfo movie.avi


Complete name                            : movie.avi
Format                                   : AVI
Format/Info                              : Audio Video Interleave
Format profile                           : OpenDML
Format settings                          : rec
File size                                : 1.27 GiB
Duration                                 : 2h 29mn
Overall bit rate                         : 1 218 Kbps
Writing application                      : AVI-Mux GUI, Feb 16 201019:42:50

ID                                       : 0
Format                                   : MPEG-4 Visual
Format profile                           : Advanced Simple@L5
Format settings, BVOP                    : 2
Format settings, QPel                    : No
Format settings, GMC                     : No warppoints
Format settings, Matrix                  : Default (H.263)
Muxing mode                              : Packed bitstream
Codec ID                                 : XVID
Codec ID/Hint                            : XviD
Duration                                 : 2h 29mn
Bit rate                                 : 1 086 Kbps
Width                                    : 720 pixels
Height                                   : 304 pixels
Display aspect ratio                     : 2.35:1
Frame rate                               : 23.976 fps
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Progressive
Compression mode                         : Lossy
Bits/(Pixel*Frame)                       : 0.207
Stream size                              : 1.13 GiB (89%)
Writing library                          : XviD 64

ID                                       : 1
Format                                   : MPEG Audio
Format version                           : Version 1
Format profile                           : Layer 3
Mode                                     : Joint stereo
Mode extension                           : MS Stereo
Codec ID                                 : 55
Codec ID/Hint                            : MP3
Duration                                 : 2h 29mn
Bit rate mode                            : Constant
Bit rate                                 : 128 Kbps
Channel(s)                               : 2 channels
Sampling rate                            : 48.0 KHz
Compression mode                         : Lossy
Stream size                              : 136 MiB (11%)
Alignment                                : Aligned on interleaves
Interleave, duration                     : 747 ms (17.92 video frames)
Interleave, preload duration             : 216 ms
Title                                    : mp3
Writing library                          : LAME3.99r
Encoding settings                        : -m j -V 4 -q 2 -lowpass 17 -b 128

There is a simple Python wrapper for it called pymediainfo. Its github page is here.

Categories: bash, python Tags: , , ,

autocompile LaTeX project when a file changes

November 19, 2014 Leave a comment

When I work with LaTeX, I always create a script called “” that compiles the project and produces a PDF. For viewing the PDF file I use okular since it refreshes automatically if the PDF changes. However, if I change the LaTeX source, I need to call the “” script manually. Could it be automated? That is, when I save the LaTeX source, the project should compile automatically, so I should only switch between my text editor and the PDF viewer.

I found a complete solution for the problem: It’s a demo script that is part of the pyinotify project.


./ . .tex,.bib ./

I put in the root folder of the LaTeX project, next to the script. The command above means the following: “monitor the current directory recursively. When a .tex or .bib file changes, call the script.”


Categories: python Tags: , , , ,

Get every new post delivered to your Inbox.

Join 87 other followers