Sunday 6 April 2014

Plex Dual Monitor on Ubuntu

I had a lot of problems with the Plex client on Ubuntu and my dual monitor setup.

If you run plex in fullscreen mode it detects the screens incorrectly (because of TwinView and xrandr).

The best way I could get to fix this is by running Plex in windowed mode but making it full screen (so it looks like it is in fullscreen mode). This has the added benefit of still allowing you the use of your mouse and keyboard on your other screen.

Unfortunately plex detects the resolution of your screen automatically for windowed mode, and did this incorrectly for me (it set the resolution to 720p, that of my small monitor instead of 1080p), so my plex did not fill the entire screen and had big black borders on two sides.

I fixed this with a bit of a hack, by lying to plex about the xrandr output.

Feel free to give any ideas for better fixes in the comments.

So here is how I got my Plex to work correctly on my two monitors.

Part 1 - Full screen windowed mode:


1. Set Plex to windowed mode:


Preferences > System > Advanced > Display Mode > Windowed


2. Install wmctrl:


sudo apt-get install wmctrl
(or use software center if you like)

3. copy the shell script for plex to your own bin folder and make some changes:


mkdir ~/bin
cp /usr/bin/plexhometheater.sh ~/bin/plexhometheater.sh

change the content in your own bin folder to:

#!/bin/sh
export XBMC_HOME=/opt/plexhometheater/share/XBMC
/opt/plexhometheater/bin/plexhometheater &
sleep 1
wmctrl -x -r plexhometheater.plexhometheater -e 0,0,-1,-1,-1
wmctrl -x -r plexhometheater.plexhometheater -b add,fullscreen

Make sure this is executed when you launch plex instead of the original.
The first 2 line are the same as the original file,
The 3rd line has an added '&' which allow the other lines to be executed
The 4th line sleeps one second while plex launches
The 5th line puts plex on the correct screen (the second 0 is the x-coordinate of the plex window), so change that to something like 3000 if you want plex on your second monitor, ex.

wmctrl -x -r plexhometheater.plexhometheater -e 0,3000,-1,-1,-1

The 6th line makes the window full screen.
Hopefully this is all you need. If your Plex has the wrong resolution then follow part two

Part 2 - Change windowed mode resolution:


Plex sets the resolution using its own xrandr binary, so to force the resolution I lied to it.

1. Turn off your second screen, keeping only the one you want plex to run on:


In Ubuntu and not Plex go to Settings > System Settings... > Displays and turn off the display you to not want plex on, leaving only the want you want plex to be displayed on.

This lets you get the correct xrandr output for the next step.

2. Run Plex's xrandr and save the output:


cd /opt/plexhometheater/bin
sudo ./xbmc-xrandr > xrandr.txt

3. Turn on your second screen again:


Settings > System Settings... > Displays and turn on your second display

4. Move xrandr:


sudo mv xbmc-xrandr xbmc-xrandr_bac

5. Create your own xrandr that calls xrandr when it wants to, otherwise returns your txt file:


Use your favourite editor (in my case vim) to create your own xrandr file
sudo vim xbmc-xrandr
And paste the following

#!/bin/bash

if [ "$#" == 0 ]; then
    cat /opt/plexhometheater/bin/xrandr.txt
else
    /opt/plexhometheater/bin/xbmc-xrandr_bac "$@"
fi
save the file and make it executable
sudo chmod +x xbmc-xrandr

Plex will now call your xrandr instead of the normal one, and you will tell it you only have the high resolution screen connected.

You might want to make a copy of these files somewhere, I do not know if Plex will overwrite the xbmc-xrandr file if it updates.

And that's it, a bit of a hack but it works.


Wednesday 12 February 2014

Amazon E-Book Specials Checker

I recently cleaned up my Amazon E-Book Specials Checker and put it up on github.

If you are like me and like to know when e-books from your favourite authors are on special, check it out.

You can set the price to look for, add specific authors to a list to watch for, or just specific books.

The program can log-in to your amazon account if you choose to let it (this ensures that you get the correct pricing for the book, as the price differs per region).

How this program came to be:

A while ago I decided to write a script for checking e-book specials, so I tried to use the amazon API.
I got this working, but they did not have pricing for e-books (only physical books).

Plan B was to scrape the website. I wrote some code in python, scraping the website with urllib2 and using Beautiful Soup to parse the html. This did not always give the correct prices though, because my server running the script was not in the same country as I and amazon has different prices in different countries.

The next problem was to figure out how to log-in to my amazon account, this makes sure I always have the correct prices.

So with that done, here it is. Feedback is appreciated.

link to program