<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Jared Meek on Medium]]></title>
        <description><![CDATA[Stories by Jared Meek on Medium]]></description>
        <link>https://medium.com/@jmeek13?source=rss-abccc5831a2e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*MDfU4hmZFXHJaejypoOGww.jpeg</url>
            <title>Stories by Jared Meek on Medium</title>
            <link>https://medium.com/@jmeek13?source=rss-abccc5831a2e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 18:51:03 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jmeek13/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[The Coder of Necessity]]></title>
            <link>https://medium.com/@jmeek13/the-coder-of-necessity-810bee26fc4e?source=rss-abccc5831a2e------2</link>
            <guid isPermaLink="false">https://medium.com/p/810bee26fc4e</guid>
            <category><![CDATA[imdb]]></category>
            <category><![CDATA[kodi]]></category>
            <category><![CDATA[file-management]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[plex]]></category>
            <dc:creator><![CDATA[Jared Meek]]></dc:creator>
            <pubDate>Mon, 02 Oct 2017 16:53:18 GMT</pubDate>
            <atom:updated>2017-10-02T16:53:18.381Z</atom:updated>
            <content:encoded><![CDATA[<h3>The Coder of Necessity — and Using IMDbPY to get Movie Metadata</h3><p>This week begins my 3rd week at the javascript web-development bootcamp known as <a href="http://hackreactor.com/">HackReactor</a>, and so it seems only fitting that I kick off my technical blogging with a post about a python media tool.</p><p>In the personal bio I composed shortly before the first week started, I described myself as a long-time <em>coder-of-necessity</em>. I’ve used that term many times in the past 6 months when people ask why I’m making this career change, and while it seems to convey the appropriate feeling, I’ve never really sat down to define it. This entry may provide a quick glimpse into what I mean.</p><h4>Let’s set the stage…</h4><p>The problem today is driven by three main factors:</p><ul><li>Large film collection (1k+ titles) that is constantly growing</li><li>Media files need to be well organized so they can be referenced and tagged correctly by any of several media players (Plex, Kodi, etc.)</li><li>Little patience for doing repetitive things… (<em>excluding video games</em>)</li></ul><p>There are many steps in the path from new BluRay to properly stored MKV, and despite my best efforts, some of them simply can’t be automated accurately. Getting movies off of the disk and onto a hard drive with the correct chapters, subtitles, and audio is one of these tasks. There are any number of tools that can handle this task and some even give intelligent automation a go… but none are quite yet accurate enough that I can trust them given the long processing time lost in a failed attempt.</p><p>But let’s move on from what’s currently impossible and dive into what we can automate, <strong>finding metadata</strong>. Again, there are many tools out there that attempt to do this for you at various levels of detail. But my preference has always been to find the least you can do to get the results you need — and for this particular case that happens to be <strong>a single .nfo file with the film’s IMDB url.</strong></p><p><strong>What does this accomplish?</strong> It prompts both Plex and Kodi’s own metadata scanners with exactly where to go to look for more information.</p><p><strong>Why is more unnecessary?</strong> The more complicated your metadata gets, the more maintenance it requires… and possibly the more likely it becomes that an update to Plex or Kodi or some other system will render them unable to make sense of it. You spend more time early on putting a stick in the ground that may simply get you stuck in the mud.</p><p><strong>But wait… don’t Kodi and Plex have their own scanners and can do this for me? </strong>Yes, but they’re not perfect, and in my opinion having imperfect library data kind of defeats the point of having a nice library / media player like Plex or Kodi. And since we have to manually intervene to get the data into our preferred format anyways, we might as well take a second to spike that data with one line that will lead to perfect library results.</p><p><strong>Alright, on board? Good. Let’s get started.</strong></p><h3>First, the file setup</h3><p>Let’s assume we start with a scratch folder where incoming movies are deposited. In the below example I’ve just imported Definitely Maybe and Serendipity (<em>because we all love rom-coms</em>).</p><pre>M:\Movie_Scratch\Definitely Maybe\Definitely Maybe (2008).mkv<br>             ...\Serendipity\Serendipity (2001).mkv</pre><p>The folder structure (<em>Movie Name \ Movie Name (year).mkv</em>) is one I’ve found to be quite useful and easy to navigate but is by no means required for this to work. The minimum we need is to drop an ‘nfo’ file with an identical name next to each .mkv file. So it will eventually look like:</p><pre>M:\Movie_Scratch\Definitely Maybe\Definitely Maybe (2008).mkv<br>                              ...\Definitely Maybe (2008).nfo      <br>                  ...\Serendipity\Serendipity (2001).mkv<br>                  ...\Serendipity\Serendipity (2001).nfo</pre><p>And inside of each of those nfo files we just need a single line with their IMDB url. I used to do this step manually. It doesn’t take too long, but it can get tedious as life gets busy and your pipeline grows larger and larger between chances to process things. So let’s grab <a href="http://imdbpy.sourceforge.net/">IMDbPY</a> (a great little library that I’m sure is capable of much more than I’m using it for in this little script) and get into the code.</p><h3>Getting started with <strong>IMDbPY</strong></h3><p>Getting IMDbPY installed is easy thanks to pip. We just kick off with this from the console:</p><pre>pip install IMDbPY</pre><p>Now we’re ready to import it into our script and get started with:</p><pre>import imdb<br>ia = imdb.IMDb() # this initiates the IMDb tool</pre><pre># other packages we&#39;ll need<br>import os<br>import glob<br>import webbrowser</pre><p>Next we’ll collect the list of files we want to process, we’ll use glob for this, and here’s where you may need to adjust for your local file system.</p><pre>movies_scratch = glob.glob(&#39;*/*.mkv&#39;)</pre><p>Now we’ve got an array of all the movies we need to process. This is mostly an exercise in string manipulation and some file i/o, so I won’t go into too much detail.</p><pre>for movie_path in movies_scratch:<br>    new_outpath = movie_path[0:-4]+&#39;.nfo&#39;<br>    # if the file exists and is not empty, leave it alone<br>    if (os.path.isfile(new_outpath) and os.path.getsize(new_outpath) &gt; 0):<br>        break<br>    else:<br>        output = open(new_outpath,&#39;w&#39;)<br>        output.truncate()<br>        moviename = os.path.basename(new_outpath)[0:-4]<br>        year = int(moviename[-5:-1])<br>        moviename_noyear = moviename[0:-7]<br>        results = ia.search_movie(moviename_noyear)</pre><p>Ignoring the first block, which is simply protection against overwriting any file that’s already there. We can see that we’re assembling, based on our naming conventions, the movie name without the year, and the year itself. We finish out the block by kicking off an IMDb search.</p><p>Note: the reason we separate these is that searching IMDb with a movie+year search query can be less than successful. But it does leave us with a problem… the same movie name more often than not will have multiple hits without specifying the year!</p><p>Turns out we can turn this to our advantage, because we do know the year, and IMDB gives us back the year of each result, we just don’t know how IMDb always expects it to be attached to a search record. So we’ll take the larger result set provided by the year-less query, and compare each to the year we know.</p><pre>#########            <br>            for res in results:<br>                if (res[&#39;year&#39;] == year):<br>                    result_link = &quot;<a href="http://www.imdb.com/title/tt">http://www.imdb.com/title/tt</a>&quot; + res.movieID + &quot;/&quot;<br>                    webbrowser.open(result_link,new=2)<br>                    break</pre><pre>output.write(result_link)<br>output.close()</pre><p>Just in case there are conflicting results we use the handy webbrowser module to open up the resulting link so that we can quickly verify. Assuming we know the movies we’ve recently acquired, this should be a nearly instantaneous. And the good news is, an easy correction here, where the errors are obvious and the files are right in front of us, leads to a perfect match-rate inside Plex or Kodi, where it can be much more difficult to address.</p><p>In the end, we’ve turned what used to be several rounds of new file creation, copy and pasting, online IMDB searching, and more copy and pasting into a single double click.</p><p>I’ve uploaded the raw code as a gist <a href="https://gist.github.com/AtreidesEnd/8439427b52d7581d764121b8ca58f7a0">here</a>. Feel free to poke around and tweak as you see fit — any ideas are welcome!</p><h3>Brief aside…</h3><p>I mentioned earlier that this might show some insight into why I consider myself a <em>coder-of-necessity. </em>I began teaching myself Python 5 years ago to help clean up a bunch of media collections that my family had merged together. I later used it to write this and a handful of other scripts to automate more of my media workflow. More recently I got into BeautifulSoup to write some web-scraping utilities for work. And that’s just my journey with Python…</p><p>But each time I got into something new with a language, I had some quick project or motive. I learned what I needed, applied it, and got out. I loved learning and writing the scripts but for some reason I never pushed further.</p><p>Until now. About 6 months ago I made the decision to move from a career in various forms of tech consulting into development. I’m starting that move with HackReactor, but I know that’s only the beginning.</p><p>So far I’ve just been a <em>coder-of-necessity. </em>I’m excited to figure out what it means to be a coder.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=810bee26fc4e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>