Showing posts with label zenity. Show all posts
Showing posts with label zenity. Show all posts

Sunday, November 24, 2013

Makeshift DIY Youtube and Flash Video Player w/o Flash

This is a dirty hack for a video stream player. It's using youtube-dl, a script which can download videos from Youtube, as well as many other sites, including those graphic ones. We will have youtube-dl download a temporary file which is played with a 5 second delay in mplayer. The script is completely immature and probably won't properly kill processes and such, so you've been warned!

1. Deps

1.1. Install youtube-dl

 # wget https://yt-dl.org/downloads/2013.11.24.1/youtube-dl -O /usr/local/bin/youtube-dl  

 # chmod a+x /usr/local/bin/youtube-dl  


1.2. Install mplayer and Zenity

 # apt-get install mplayer zenity


2. The script

 #!/bin/bash  
 URL=`zenity --title "Dirty Youtube Player" --text "Please paste URL here: " --entry`  
 if [ -f ~/.utubetmp ]  
   then  
    rm ~/.utubetmp  
   else  
    mkfifo .utubetmp  
    youtube-dl $URL -o .utubetmp &  
    sleep 5 && mplayer .utubetmp && rm .utubetmp  
 fi  


I called the temp file .utubetmp and made it reside in your current user's home folder. It's also a hidden file.

You run the programme (I called it utube and put it in my ~/.bin), paste a video URL in this dialogue:



 
and eventually, you'll get a video after 5 seconds or a bit more...





There you go! You've got yourself a lovely Flash video player which actually should be using less resources than actual Flash and doesn't even require you to have Flash installed.

Bugs: Skipping ahead is possible only until the point youtube-dl has already downloaded, skipping back breaks MPlayer and it exits, pausing and resuming works though.



Wednesday, August 14, 2013

Screenshots in Window Managers with Zenity, Scrot and Gpicview


TECHNICAL UPDATE: Code snippets will be dark green from now on. I am still working on making proper code boxes with select all function and all the jazz.


There are a lot of dedicated screenshooters out there, some more advanced than others. I need something simple and want to facilitate it with the tools I already have on my machine or that need just a few more lean programmes.

scrot (HQ, deb)
zenity (HQ, deb)
gpicview (HQ, deb)

scrot is just a small screenshot wrapper around imlib2 and quite lean.

Why gpicview? It's my go to image viewer and it can save files. So, if you substitute this with something else, choose one that lets you easily save the picture, since the script will only save into /tmp and then delete the file immediately!

Basically, there are 2 ways of using this script. It will wait for a certain interval (I've set it to 3s) after which it will either make a screenshot of the whole screen, or, in the second mode where you call the script with the -w flag, you either click on a window you want, or draw a rubber band around the screen portion you want.
In both cases, a zenity window will pop up to warn or instruct you.
After that, gpicview will display the image. That's where you can actually save the picture by using the right click dialogue, as the temporary picture in /tmp will be deleted once you close gpicview!

The script proper:


 .  

   
 #!/bin/bash  
   
 NEW_FILE=screenshot__`date +%d-%b-%Y_%T`.png  
   
 case $1 in  
   
  -w)  
    zenity --title "Selective screenshot" --info --text "Please select a portion of the screen by holding down the left mouse button and drawing a rectangle, or just click on the window you would like a screenshot of." && scrot -s -d 3 /tmp/$NEW_FILE && gpicview /tmp/$NEW_FILE && rm /tmp/$NEW_FILE  
  ;;  
   
   *)  
    zenity --timeout 2 --title "Fullscreen screenshot" --info --text "Making a screenshot of your entire screen..."  
    scrot -d 3 /tmp/$NEW_FILE && gpicview /tmp/$NEW_FILE && rm /tmp/$NEW_FILE  
  ;;  
   
 esac  
   
 exit 0  
   



WARNING: Both bold parts in the script are 1 line and are only broken up here because of the blog!


I save the script as scrnw and call the command

scrnw

with the Print Screen button in case I need a full screen shot, or as

scrnw -w

with Alt-Print Screen in case I need just a portion of the screen or a window.
Here's a screenshot of the dialogue in this case:




That's it.