Showing posts with label xbmc. Show all posts
Showing posts with label xbmc. Show all posts

Kodi / XBMC / uTorrent / EventGhost / TheRenamer: Automatically renaming downloads for Kodi consumption

Kodi expects your files to be organised in a certain way if you want it to be displayed correctly. This isn't a big ask, but most people are incapable or lazy, so it'd be nice if it could be done automatically.

At the moment this handles movies and TV shows just fine, but anime renaming is a whole different can of worms needs a little more work.

This method relies on a particular setup, but your setup is similar then it'll work for you. If your setup is similar, then you can easily adapt it.

update 10/01/2016: Made the process work better with anime.

Basic process

  • When files are added to uTorrent, categorise them with a label (movie, TV show, anime, etc)
  • uTorrent completes a download and moves it your "completed" folder but also appends the label. (eg. C:\Downloads\Movies\)
  • EventGhost monitors the labelled folders for media files and copies them off to a temporary folder (so you can continue seeding)
  • When the file has finished copying to the temporary folder, EventGhost will start TheRenamer to rename and move the files to it's final resting place
  • Next time Kodi starts, it'll scan and detect the new files

For the time being, anime is copied to a temporary folder but no renaming is done.

Downloads

Setting up your computer

You'll need 3 sets of folders, one for completed downloads and one for temporary downloads.

For example:

  • C:\Downloads\Movies
  • C:\Downloads\TV Shows
  • C:\Downloads\Anime
  • C:\XBMC-prepare\Movies
  • C:\XBMC-prepare\TV Shows
  • C:\XBMC-prepare\Anime
  • C:\XBMC\Movies
  • C:\XBMC\TV Shows
  • C:\XBMC\Anime

Ensure these are ready before continuing.

Setting up uTorrent

  • Options > Preferences
  • Under "Directories", ensure that you set the "Move completed downloads to:" to a specific folder
image4
  • On older uTorrent clients, you'll have to check "Append the torrent's label to the directory name" as well
  • (optional) Under Advanced > UI Extras, fill in the persistent labels "Anime|Movies|TV Shows" so you don't run into inconsistent label names

uTorrent and Anime

The difference with anime is that it's a pain in the butt to get working because of the naming convention compared to TV Shows.

  • Set up the filename scanner as shown http://kodi.wiki/view/Anime#Scanning_files_without_renaming_them here by pasting the snippet into advancedsettings.xml.
  • In uTorrent, name your labels as "Anime\One-Punch Man" and such so that the name matches the name you want to match in the scraper (anidb or thetvdb)
  • That should be enough to get you by. Specials and movies will probably require a change of scraper or involve manual renaming.

If your anime (one off movie) doesn't belong in a folder, then you can simply label it as "Anime" and the script will still work.

Setting up EventGhost

image14

To the right is an image of the setup you should replicate in EventGhost.

Preparation

  • Click "Add plugin" in the toolbar
  • Select Other > Directory Watcher
  • Select the folder "C:\Downloads\TV Shows" and tick "Watch subdirectories too"
  • Do this again for Movies and Anime
  • Now under Autostart, you should have "Plugin: Directory Watcher" "Autostart" #2 and #3 (note this for naming for events)
  • Select "Configuration Tree" at the top
  • Click the "Add macro..." button in the toolbar
  • Select "Event Ghost > Python Script"
  • Paste in the following content:

This part took the longest because of the finicky nature of events and the EventGhost UI. A few people have contributed to the original script by Pako, but many of the solutions had flaws which made it unworkable for larger files (longer copy times). After months of trial, I've figured out the ideal script to handle most use cases without problems.

Note: Make sure the variables at the top of the script are correct for YOUR setup

    • ALLOWED_TYPES
    • DESTINATION_FOLDER
    • THE_RENAMER
  • When done, rename the new macro to "Copy Video Files"

For each media type (Movies, TV Shows, Anime)

  • Select "Configuration Tree" at the top
  • Click the "Add macro..." button in the toolbar
  • When asked to choose an event to add, select "EventGhost > Python Command" (not Python Script!)
  • For the statement, enter in: mediaType = "Movies" (or "TV Shows", "Anime" etc)
  • Select the macro and rename it to "Copy Movies" (because the default is just silly)
  • Now right click your macro and select "Add event"
  • Type in "DirectoryWatcher.Created" and click ok (Note: For Movies or Anime, use DirectoryWatcher2 or DirectoryWatcher3 accordingly depending on the order you created the plugins)
  • Now right click your macro and select "Add action"
  • Change "If" to "Always"
  • Select "EventGhost > Jump" and select "Copy Video Files"
  • Repeat these steps for TV Shows and Anime if needed

Phew, that's it for EventGhost!

Setting up TheRenamer

Last piece of the puzzle is quite a useful tool. However, the UI isn't the most intuitive so I'll have to guide you through that part. I forgot which mode TheRenamer starts in, but you can switch between "TV Shows" and "Movies" modes by clicking on the middle of the screen as highlighted.

Settings for the current mode is always in the top-right corner.

image37

TV Shows

For TV shows, set it up as shown. This configuration makes it very easy for XBMC to parse your content when organised as "C:\XBMC\TV Shows\Show Name\Season 01\Show Name S01E02.avi".

image31

The important parts are:

  • Renamed format: s1e01 ticked
  • Fetch folder
  • TV shows archive (destination folder)
  • Moving File Structure: TV Show Folder ticked

Movies

For movies, it's much simpler. All you really need is "Movie Name (Year)" and it'd be enough to scrape correctly.

image36

The important parts are:

  • Fetch folder
  • Movies archive (destination folder)
  • Auto move
  • The brackets around the year format

Kodi / XBMC scanning

Whenever Kodi starts up it should scan for new media files. I forgot if this was enabled by default or not, but it's definitely something I would consider setting up after all this.

TV shows and movies will work out of box with The Renamer doing its job correctly.

However, anime will need a little tweaking to read the format correctly.

  • Open up "%APPDATA%\Kodi\userdata\" in Windows Explorer and find advancedsettings.xml
  • If it doesn't exist, download this file and save it there. Then you're done.
  • If it DOES exist, copy in the contents from http://kodi.wiki/view/Anime#Scanning_files_without_renaming_them into it into the right location under the <advancedsettings> tag
  • Save and restart Kodi
  • Anime files should now detect without need for renaming

20DQV7U4
Automation, it's a beautiful thing... when it works.

Sources

XBMC / Kodi: List files not found in library

One of the biggest hurdles for people setting up their first XBMC/Kodi machines is getting content to scan correctly.

Although the scanner supports a number of different naming conventions, there's still no built-in way of checking which files have been ignored by the library scanner.

That's why "null_pointer" created "Missing Movie Scanner". It checks your library and finds any movie files which have been ignored by the library, so you know which ones to rename properly.

image

Installation

  • Load up XBMC
  • Settings
  • Add-ons
  • Get Add-ons
  • XBMC.org Add-ons
  • Video Add-ons
  • Scroll down to "Missing Movie Scanner"
  • Select install
  • Go back to the home menu
  • Access Add-ons from your home menu (you may need to enable this, depending on your skin)
  • Select "Video Add-ons"
  • Missing Movie Scanner
  • Now you can select between movies or TV shows
  • The next screen will list the files which aren't included in your library.

anigif_enhanced-buzz-14424-1386607752-4
No, sadly this won't fix any high-5 misses

Source

XBMC / Kodi: (Amber Skin) Adding a custom menu item to the main menu

Changing skins isn't easy, but I was getting a bit annoyed at Aeon Nox and the excessive CPU usage when idling in menus. Eventually I went with Amber, a super light weight skin with some pretty good customisation.

For this example, I'll show you how to add Steam games and a custom playlist to your main menu. I used the Steam Launcher addon by Teeedubb, so you'll need that first (or whatever addon you're using).

To begin make sure you have Amber skin installed, along with any addons you wish to add to the main menu.

  • Settings
  • Home Menu
  • Enable "Add-ons"

image

  • Go back to the main menu
  • Select "Add-ons"

image

  • Select Programs
  • Select Steam
  • Press "C" on the keyboard to bring up the context menu
  • Select "Add to favourites"

image

  • Likewise with the custom playlist, I'm going to add "Anime" to the main menu.
  • Go to TV Shows > Playlists (submenu) > Highlight your playlist of choice and press "C"
  • Select "Add to favourites"

image

  • Now go back to Settings
  • Home menu
  • And pick an empty slot where you want to put your new custom menu

image

  • Select it
  • Pick Steam
  • Call it "Games"
  • Your menu item should now appear as "Games", but activate the "Steam" addon!
  • Do the same with your custom playlist

image

  • Before moving on, be sure to hide the Add-ons menu if you don't need it anymore.
  • Go to Settings > Backgrounds to customise the background for your new Games menu item
  • And there you have it! You've now got custom menus working on your XBMC menu.

image

Source

XBMC: Scraping anime show information correctly

If there's one thing I found troublesome about XBMC, it's the poor support for anime shows out of box. I get that anime are done a little differently and that there's a separate scraper for anime information, but even that is a tad out of date.

The majority of the shows I had weren't scraped. Either due to different naming conventions or they just weren't matched at all.

Filenames

First of all, unlike TV shows, anime is treated like one big season. Your episodes should follow the naming convention of "Show Name - ep001.mkv". The important bit is "ep123" which lets XBMC know the episodic order.

Specifying source for metadata

In comes "AniDB.net Scraper Mods for Anime TV shows and Movies" by scudlee, which is a well maintained scraper primarily for anime. There are also a bunch of improvements to help with matching the titles to the right show.

The naming of this mod could have been a bit better, but it gets the job done well.

If your show still doesn't appear, you can tell it to scrape from a specific URL on aniDB.net by creating a file called "tvshow.nfo" in the show folder and pasting a link to the information.

For example Gintama (season 1), Gintama` (season 2) and Gintama Enchousen (season 3) are an absolute bitch to get right. Have no fear, just put the episodes into the right folders and place "tvshow.nfo" in each one.

For each file, paste in the direct link to each show accordingly and it'll scan right into XBMC fine. You may have to remove the show first in order for it to re-scan.

So in "Gintama\tvshow.nfo" (Season 1):

http://anidb.net/perl-bin/animedb.pl?show=anime&aid=3468

For "Gintama`\tvshow.nfo" (Season 2):

http://anidb.net/perl-bin/animedb.pl?show=anime&aid=8126

And lastly, "Gintama` Enchousen\tvshow.nfo" (Season 3) I have:

http://anidb.net/perl-bin/animedb.pl?show=anime&aid=9427

If you want to customise the Season 3 name a little, you can do this.

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<tvshow>
<title>Gintama` Rush</title>
</tvshow>
http://anidb.net/perl-bin/animedb.pl?show=anime&aid=9427

This way you can customise the name but specify the URL to fetch information from.

This is the only way to truly enjoy Gintama and the pure Jet Armstrong Cannon insanity that comes with it!

127309_v0_600x JustawayneoCRY3Ql 158066_v0_600x  tumblr_m52m2lX0171rv62t0o1_500 

Source

XBMC: How to group movies together using movie sets

Sometimes you get a movie series that aren't named in order (such as X1, X2, X3) but instead have all these whacky titles such as The Fast and the Furious, 2 Fast 2 Furious, Fast Five, Furious 6, etc.

To sort the movies in order, we'll need to cast a little NFO magic.

Beside each movie file, create an NFO file with the same name.

For example, the files:

2 Fast 2 Furious.avi
2 Fast 2 Furious.nfo
Fast Five.avi
Fast Five.nfo
Furious 6.avi
Furious 6.nfo
The Fast and the Furious.avi
The Fast and the Furious.nfo

As you can see, the second movie is first and the first movie is last.

In each NFO file, paste in:

<movie>
<title>The Fast and the Furious</title>
<sorttitle>Fast and Furious 1</sorttitle>
<set>Fast and Furious</set>
</movie>
  • The "title" is the name used to display the movie.
  • The "sorttitle" is used for sorting of movies.
  • Lastly, the "set" is the group which the movie belongs to. If you wanted to group all the Lord of the Ring movies then that's what you'll use as the set name.

If you need to specify the URL to scrape, then just add it at the end.

<movie> <title>2 Fast 2 Furious</title>
<sorttitle>Fast and Furious 2</sorttitle>
<set>Fast and Furious</set>
</movie>
http://www.themoviedb.org/movie/584-2-fast-2-furious

If the movies are already in your library, remove them by simply right clicking and selecting remove.

To bring them back into the list, go to Movies > Update to refresh your library. The movies should now appear in their new order.

image 
Any other questions? Refer them to Mona Diesel.

Sources

XBMC: Fix for 100% CPU usage when idle in menus

This is something that's had me baffled for some time. It just didn't make sense that CPU usage was barely 9% during video playback, but when it's paused or a menu is shown the damn thing would cook the computer!

It isn't very noticeable when switching between episodes/movies/shows but if I fall asleep before a movie finishes, I'd definitely be woken up by the busy CPU fan when my HTPC tries to stop itself from roasting in the TV unit.

Eqmql
HTPC, meet heat and XBMC.

A little research quickly shows that XBMC still carries a lot of legacy code from it's XBOX days, and redrawing the interface at every given chance is just one of those things.

This means XBMC is written with "game loop" logic in mind, so they had to add some options in order to optimise the redrawing process.

Thankfully there is a fairly easy way to fix this (possible since Eden or Frodo I beleive).

  • Make sure XBMC is NOT running.
  • Open up Windows Explorer and go to "%APPDATA%\XBMC\userdata\" (or ~/.xbmc/userdata/ on Linux)
  • If "advancedsettings.xml" doesn't already exist, create a file called and open it with Notepad.
  • Under the <gui> tag, copy in <algorithmdirtyregions> and <nofliptimeout> as shown below.
<advancedsettings>
<gui>
<algorithmdirtyregions>1</algorithmdirtyregions>
<nofliptimeout>0</nofliptimeout>
</gui>
</advancedsettings>
  • Save and exit.

I've tried the default "1000" value for <nofliptimeout> as shown in the XBMC docs but it didn't seem to have any effect. Only when I set it to "0" would it reduce CPU usage.

And of course, your mileage may vary depending on your graphics card and/or drivers installed. For my Intel E6700 (Core 2 Duo) and AMD A8-5600k it worked like a charm.

Sources

XBMC: How to use EventServer

In my quest to get the Wii remote working on XBMC, I've tried every possible API I was able to find and tried them all out.

Initially I thought I could get away with using window messages, sending WM_KEYDOWN, WM_CHAR and WM_KEYUP and VK_ENTER which worked until you started watching videos. For some reason, on-screen display (OSD) would stack up all input in a queue and replay them once you leave the OSD.

So I looked into more "official" control APIs. The HTTP-API was first on the list, but also deprecated no point building something upon that.

I also tried the HTTP-API replacement called JSONRPC. Although I got it working, that API felt like it was more complicated than it should have been. By the way, don't include the trailing backslash unless you like 404's.

The input methods would work fine for navigating menus, but when it came to controlling the video playback I had to use different commands. Seriously!?

2JX8XRl
This is what I felt like doing after wasting my time with that...

Here's some simple JSONRPC code that worked, just for the sake of it.

JavaScriptSerializer jss = new JavaScriptSerializer();
Object obj = new { jsonrpc = "2.0", method = "Input.Left" };
String data = jss.Serialize(obj);
WebClient client = new WebClient();

string text = client.DownloadString("http://localhost:8080/jsonrpc?request=" + Uri.EscapeDataString(data));

Now remember, this is just to send a simple request. You're not processing any data from it yet!

So came my last hope, EventServer. Well to say least, it worked but was also poorly documented. There was so much guess-work when it came to the input arguments, but when you've finally figured it out all the little puzzle pieces, it comes together very nicely!

Enabling EventServer on XBMC

First you've gotta have this enabled. Otherwise there'll be no event server to connect to.

  • Go to System > Services > Remote control
  • Enable "Allow programs on this system to control XBMC" (lol yeah, it's badly named)

screenshot000

XBMC EventServer libraries and sample code

Now for the fun part, choosing your poison. These EventServer client libraries were written between 2-5 years ago (at time of writing this blog post)

These libraries really save you a lot of time, so get the library for your language of choice. There are also example clients available which are worth taking a look at.

Coding

For the purpose of this tutorial I'll chose C#, a language I absolutely hate with a passion. Why the hell would I do that!? Because Wiimotelib is written in C#...

Anyways... copy "EventClient.cs" from the C# library into your project. Import the namespace.

using XBMC;

Now to set up the client. This is assuming you're running this code on the same machine that XBMC is running with the default event server port of 9777.

EventClient eventClient;

eventClient = new EventClient();
eventClient.Connect("localhost", 9777);
eventClient.SendHelo("Wii remote");

SendHelo() (another badly named function) will display a notification on your screen saying a new device has connected. Let's test out the connection shall we?

eventClient.SendNotification(
"Yo VIP",
"Vanilla ice ice baby"
);

This should display a nice little notification on your screen. If it doesn't, you're missing a vital step somewhere.

screenshot002 

Action commands

We'll start off with something simple. To control parts of XBMC functionality, you can just send specialised action commands.

eventClient.SendAction("mute");
eventClient.SendAction("nextsubtitle");

For a full list of supported actions, look at ButtonTranslator.cpp and search for "ActionMapping actions[]".

To implement some basic navigation, I tried out "left" and "right" but they didn't seem to work so I had to resort to button commands.

Button commands

This is where the magic happens. The following code will send a "enter" command to XBMC.

eventClient.SendButton(
"enter",
"KB",
XBMC.ButtonFlagsType.BTN_DOWN | ButtonFlagsType.BTN_NO_REPEAT
);

Simple enough, sends an "Enter" button command ("enter") to XBMC in the form of a keyboard ("KB") device map. This ensures that we're using the keyboard.xml keyboard mapping.

If you're wondering what keymaps are, check em out because you've already got a whole heap of mappings with your XBMC install (see "1. Location of keymaps")

Now you might also be wondering where I found these magic string values like "enter", or the deviceMap "KB". Even more confusing was the sample client code which uses deviceMap "XG".

Well I had to dig through a fair bit of XBMC source for that and it took up much of my time! For sanity sake, you can find some useful values for device maps in EventClient.cs to use in SendButton().

  • "KB" - Standard keyboard map
  • "XG" - Xbox Gamepad
  • "R1" - Xbox Remote
  • "R2" - Xbox Universal Remote
  • "LI:devicename" - valid LIRC device map where 'devicename' is the actual name of the LIRC device
  • "JS<num>:joyname" - valid Joystick device map where 'joyname' is the name specified in the keymap. JS only supports button code and not button name currently (ie. "JS0:WiiRemote")

Given the choices I went with keyboard, which makes life much easier. OK, so now what button do you want to send?

Check out ButtonTranslator.cpp in the XBMC source. It's the "best/neatest" way to see what buttons are supported by the given mapping.

Depending on the device map you're using, search for either:

  • CButtonTranslator::TranslateKeyboardString
  • CButtonTranslator::TranslateGamepadString
  • CButtonTranslator::TranslateRemoteString

For Joystick (JS) button presses, you're better off just gleaming the values from the keymap XML files. The <global> config should give you a fair idea of what the button IDs are.

Cleaning up

Now now, don't forget to clean up after yourself once you're done having fun. Remember to disconnect your client properly.

if (eventClient != null) {
eventClient.SendBye();
eventClient.Disconnect();
}

There are so many dead ends on a wiki page, and it seems that I've already run into most of them for you. Hopefully this tutorial provides more than enough information so it makes life easier for you.

rake-dance 

Sources

XBMC: Getting 404 File not found on your JSONRPC requests?

I'd hate to admit, but this one took me a few hours to figure out...

See this request?

"http://localhost:8080/jsonrpc/?request=<uriencodedrequest>"

Well, that's wrong. It's supposed to be:

http://localhost:8080/jsonrpc?request=<uriencodedrequest>

Can you spot the difference?

Yep, trailing slash! Damn it!

cuyqe 
Oh well, back to it!

XBMC: How to pick a random background for your custom menu item (within a specific playlist)

Now that's a lengthy title! Now I'm pretty sure this is a common problem, but I haven't been able to find a tutorial for it anywhere (unless I was searching for the wrong keywords?)

What I wanted was simple, in theory! I created a smart playlist for all my anime, called "Anime Playlist". I also had a custom menu item in the home screen which took you straight there, however the background was boring and unrelated.

screenshot000 screenshot001

A cool, randomly selected background from an anime within the playlist. Hmm, how to go about doing that?

So, off to the XMBC forums I went and a nice Canadian by the name Vaikin gave me some directions to where I wanted to go.

dog-scientist-atheist-49845773629

Downloads

At time of writing, I'm running the latest release of XBMC (12/Frodo).

Firstly, you'll need the script.randomandlastitems addon. See if you've already got it (some skins bundle it) by checking the folder %APPDATA%\XBMC\addons\script.randomandlastitems.

Make sure you grab the right one for your XBMC build. I used script.randomandlastitems-2.0.3.zip. Download the zip and install it via:

  • System
  • Add-ons
  • Install from zip file
  • Find and install

Setup

Once installed, you can do the rest in XBMC. The instructions I write are for the skin Aeon Nox, so the layout or menus may be a little different for you.

  • Go to the System menu and press DOWN to "Edit main menu"

screenshot002

  • Now press UP to configure the "script.randomandlastitems" addon
screenshot003
  • Under "Smart playlist manager", select "Slot 1" and press ENTER

screenshot004

  • Select "Random Episodes"
  • Choose whatever you want for "Include already watched items?"
  • Select the playlist you want to restrict the backgrounds to (eg. Anime Playlist)

screenshot006

  • Repeat the same steps in Slot 2 if you have any other custom menus you'd like nice backgrounds for
  • Once you're done, back out to the "Edit main menu" screen
  • Press ENTER on your menu item (ie. Anime) to configure it
    • Type: Video Playlist > Anime Playlist
    • Choose Background: Anime Playlist (Episode Random)
    • (optional) Set InfoLine: Anime Playlist (Gives you the watched/unwatched count)

screenshot005
It should now look a little like this

Rinse and repeat for any other custom menus.

And there you have it! Here are some screenshots of the script working. It takes a few seconds before the background changes.

screenshot007 screenshot008 screenshot009

Sources

XBMC: Automatically play the next episode/video

I couldn't believe something this simple took so long to implement.

For some time I thought my XBMC configuration was broken, but it was actually "working as intended". The wife approval factor rating really drops when it comes to little things like this.

gintama

Fortunately, a clever chap called ScudLee made a patch for it and it's been integrated into XBMC v12 (Frodo).

At time of writing, v12 is current on RC3, so grab it and check it out!

It's in:

  • Settings
  • Videos
  • Playback
  • Play next video automatically (tick it)

Definitely taking the opportunity to upgrade to Frodo when it's finally finished.

Sources

 
Copyright © Twig's Tech Tips
Theme by BloggerThemes & TopWPThemes Sponsored by iBlogtoBlog