Git Product home page Git Product logo

tvdb_api's Introduction

tvdb_api

PyPI Build Status codecov

tvdb_api is an easy to use interface to thetvdb.com

It supports Python 2.7, and 3.5 onwards

tvnamer has moved to a separate repository: github.com/dbr/tvnamer - it is a utility which uses tvdb_api to rename files from some.show.s01e03.blah.abc.avi to Some Show - [01x03] - The Episode Name.avi (which works by getting the episode name from tvdb_api)

To install

You can easily install tvdb_api via pip

pip install --upgrade tvdb_api

You may need to use sudo, depending on your setup:

sudo pip install --upgrade tvdb_api

Basic usage

First initialise an instance of the Tvdb class with your API key:

import tvdb_api
t = tvdb_api.Tvdb() 

Note you must specify the apikey argument here, for example:

t = Tvdb(apikey="ENTER YOUR API KEY HERE") # doctest:+SKIP

See https://thetvdb.com/api-information to register a key.

Then to use the API:

episode = t['My Name Is Earl'][1][3] # get season 1, episode 3 of show
print episode['episodename'] # Print episode name

Registering an API key

You must have an API key from http://thetvdb.com in order to use this module.

Registering for a key is easy to do and can be done within a few minutes - see the following page for details:

https://thetvdb.com/api-information

Note: In tvdb_api v2 a default key was included for convenience. However over time this key became very heavily used and this causes problems for TheTVDB.com admins. This old shared key will be deprecated and removed at some point soon.

Advanced usage

Most of the documentation is in docstrings. The examples are tested (using doctest) so will always be up to date and working.

The docstring for Tvdb.__init__ lists all initialisation arguments, including support for non-English searches, custom "Select Series" interfaces and enabling the retrieval of banners and extended actor information. You can also override the default API key using apikey, recommended if you're using tvdb_api in a larger script or application

Exceptions

There are several exceptions you may catch, these can be imported from tvdb_api:

  • tvdb_error - this is raised when there is an error communicating with thetvdb.com (a network error most commonly)
  • tvdb_userabort - raised when a user aborts the Select Series dialog (by ctrl+c, or entering q)
  • tvdb_shownotfound - raised when t['show name'] cannot find anything
  • tvdb_seasonnotfound - raised when the requested series (t['show name][99]) does not exist
  • tvdb_episodenotfound - raised when the requested episode (t['show name][1][99]) does not exist.
  • tvdb_attributenotfound - raised when the requested attribute is not found (t['show name']['an attribute'], t['show name'][1]['an attribute'], or t['show name'][1][1]['an attribute'])

Series data

All data exposed by thetvdb.com is accessible via the Show class. A Show is retrieved by doing..

>>> import tvdb_api
>>> t = tvdb_api.Tvdb()
>>> show = t['scrubs']
>>> type(show)
<class 'tvdb_api.Show'>

For example, to find out what network Scrubs is aired:

>>> t['scrubs']['network']
u'ABC'

The data is stored in an attribute named data, within the Show instance:

>>> t['scrubs'].data.keys()
['networkid', 'rating', 'airs_dayofweek', 'contentrating', 'seriesname', 'id', 'airs_time', 'network', 'fanart', 'lastupdated', 'actors', 'ratingcount', 'status', 'added', 'poster', 'tms_wanted_old', 'imdb_id', 'genre', 'banner', 'seriesid', 'language', 'zap2it_id', 'addedby', 'firstaired', 'runtime', 'overview']

Although each element is also accessible via t['scrubs'] for ease-of-use:

>>> t['scrubs']['rating']
u'9.0'

This is the recommended way of retrieving "one-off" data (for example, if you are only interested in "seriesname"). If you wish to iterate over all data, or check if a particular show has a specific piece of data, use the data attribute,

>>> 'rating' in t['scrubs'].data
True

Banners and actors

Since banners and actors are separate XML files, retrieving them by default is undesirable. If you wish to retrieve banners (and other fanart), use the banners Tvdb initialisation argument:

>>> from tvdb_api import Tvdb
>>> t = Tvdb(banners = True)

Then access the data using a Show's _banner key:

>>> t['scrubs']['_banners'].keys()
['fanart', 'poster', 'series', 'season']

The banner data structure will be improved in future versions.

Extended actor data is accessible similarly:

>>> t = Tvdb(actors = True)
>>> actors = t['scrubs']['_actors']
>>> actors[0]
<Actor "Zach Braff">
>>> actors[0].keys()
['sortorder', 'image', 'role', 'id', 'name']
>>> actors[0]['role']
u'Dr. John Michael "J.D." Dorian'

Remember a simple list of actors is accessible via the default Show data:

>>> t['scrubs']['actors']
u'|Zach Braff|Donald Faison|Sarah Chalke|Judy Reyes|John C. McGinley|Neil Flynn|Ken Jenkins|Christa Miller|Aloma Wright|Robert Maschio|Sam Lloyd|Travis Schuldt|Johnny Kastl|Heather Graham|Michael Mosley|Kerry Bish\xe9|Dave Franco|Eliza Coupe|'

tvdb_api's People

Contributors

dbr avatar djsutherland avatar dpimenov avatar echelonfour avatar etabard avatar gene1wood avatar jankatins avatar lad1337 avatar mge avatar midgetspy avatar minrk avatar mr-orange avatar mspieth avatar sbrudenell avatar smeggingsmegger avatar someone561 avatar timgates42 avatar tremby avatar vapier avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tvdb_api's Issues

Tvdb.__getitem__ fails for integer show id

I think there's a bug in the Tvdb.getitem method. It works for a show name but fails when passed a show id. Here's the change I made against tip:

--- tvdb_api.py.1       2010-04-04 12:16:21.757125000 -0700
+++ tvdb_api.py 2010-04-03 19:51:48.687500000 -0700
@@ -741,6 +741,7 @@
         """
         if isinstance(key, (int, long)):
             # Item is integer, treat as show id
+            key = str(key)
             if key not in self.shows:
                 self._getShowData(key, self.config['language'])
             return self.shows[key]

TV shows with 'and' in their name.

tvnamer (and probably tvdb_api behind it) aren't picking up "Law and Order" because in the tvdb it's "Law & Order", so it fails.

Maybe a simple list of word substitutions if something fails.
& = and, etc

Request to add code to Show class

I would like to suggest adding the following code to the Show class, it'll allow one to determine if a key value does exist or not plus set a default value of there choosing depending on the conditional set via getattr.

Class Show

    def __getattr__(self, key):
        if key in self:
            # Key is an episode, return it
            return self[key]

        if key in self.data:
            # Non-numeric request is for show-data
            return self.data[key]

        raise AttributeError

Class Season

    def __getattr__(self, episode_number):
        if episode_number in self:
            return self[episode_number]
        raise AttributeError

Class Episode

    def __getattr__(self, key):
        if key in self:
            return self[key]
        raise AttributeError

Top rated season level graphics

I there a way to access the top rated poster and banner URL’s at the season level? I top rated graphics at the series level is an excellent option I would like to extend to the season level.

Top rated season level graphics

There doesn’t seem to be..

None of the pages on http://thetvdb.com/wiki/index.php/Programmers_API seem to mention it.. but I seem to recall the banners.xml being ordered by rating, so when I redo the banner interface I shall store the banners in a list, rather than an unordered dict..

original LH ticket

querying 100s of shows results in random tracebacks

        for (tvdb_id, show_name, status) in shows:
            try:
                show = t[show_name]
            except tvdb_exceptions.tvdb_error, msg:
                return msg

after like 50 queries it does:

  File "C:\Program Files (x86)\Sick-Beard--dev\cherrypy\_cprequest.py", line 660, in respond
    response.body = self.handler()
  File "C:\Program Files (x86)\Sick-Beard--dev\cherrypy\lib\encoding.py", line 193, in __call__
    self.body = self.oldhandler(*args, **kwargs)
  File "C:\Program Files (x86)\Sick-Beard--dev\cherrypy\_cpdispatch.py", line 25, in __call__
    return self.callable(*self.args, **self.kwargs)
  File "C:\Program Files (x86)\Sick-Beard--dev\sickbeard\webserve.py", line 1499, in sbEnded
    show = t[show_name]
  File "C:\Program Files (x86)\Sick-Beard--dev\lib\tvdb_api\tvdb_api.py", line 862, in __getitem__
    sid = self._nameToSid(key)
  File "C:\Program Files (x86)\Sick-Beard--dev\lib\tvdb_api\tvdb_api.py", line 846, in _nameToSid
    self._getShowData(selected_series['id'], selected_series['language'])
  File "C:\Program Files (x86)\Sick-Beard--dev\lib\tvdb_api\tvdb_api.py", line 795, in _getShowData
    self._setShowData(sid, tag, value)
  File "C:\Program Files (x86)\Sick-Beard--dev\lib\tvdb_api\tvdb_api.py", line 612, in _setShowData
    self.shows[sid] = Show()
  File "C:\Program Files (x86)\Sick-Beard--dev\lib\tvdb_api\tvdb_api.py", line 71, in __setitem__
    del self[o]
KeyError: 77801

Uncaught Excption when using getpass.getuser() in function _getTempDir

I'm on window Python 2.6 when retrieving TVDB Languages the system return an exception on get_pass.getuser() (Function _getTempDir)
As described in python get_pass module function get_user() is working only when a username is set and this is not true for my windows system.
Is It possible caught this exception and and return tempdir as version 1.7.2?

Unicode issue

I have a little snippet of code here but the thing is I don't know how to fix the output my script is giving me.

#!/usr/bin/env python
# encoding:utf-8

import tvdb_api

t = tvdb_api.Tvdb(interactive = 'True', language = 'fr')
season24 = t['Les grands reportages'][24].search("")

print season24

Output:

user@homeseedbox:~/script$ python tvdb_episode_renamer.py TVDB Search Results: 1 -> Grands reportages [fr] # http://thetvdb.com/?tab=series&id=297490&lid=17 (default) 2 -> Les grands reportages [fr] # http://thetvdb.com/?tab=series&id=226591&lid=17 3 -> Les grands reportages - Exploration [fr] # http://thetvdb.com/?tab=series&id=291259&lid=17 4 -> Les grands reportages - Personnalités [fr] # http://thetvdb.com/?tab=series&id=290829&lid=17 5 -> Les grands reportages - Les films IMAX [fr] # http://thetvdb.com/?tab=series&id=295231&lid=17 6 -> 20 ans de grands reportages [fr] # http://thetvdb.com/?tab=series&id=295277&lid=17 Enter choice (first number, return for default, 'all', ? for help): 2 [<Episode 24x01 - u'Game Fever'>, <Episode 24x02 - u"La course vers l'intelligence artificielle">, <Episode 24x03 - u'La Cor\xe9e de mon p\xe8re'>, <Episode 24x04 - u'Unit\xe9 9 - documentaire 2 : Les IPL'>, <Episode 24x05 - u'Immortalit\xe9, derni\xe8re fronti\xe8re'>, <Episode 24x06 - u"L'inde aujourd'hui">, <Episode 24x07 - u'Bye'>, <Episode 24x08 - u"L'abus des jeux vid\xe9os nuit \xe0 la sant\xe9">, <Episode 24x09 - u'De Sotchi \xe0 Pyeonchang'>, <Episode 24x10 - u'Sonia Benezra : Le meilleur est \xe0 venir'>, <Episode 24x11 - u"L'imam et son discours">, <Episode 24x12 - u'Qu\xe9bec, un an apr\xe8s'>, <Episode 24x13 - u'Trump: la culture du racisme en politique am\xe9ricaine'>, <Episode 24x14 - u'\xc0 contre-mar\xe9e'>, <Episode 24x15 - u"Charles et Mariane, jusqu'au dernier tour de piste">]

Any result with the chars (é and è) displays it's unicode value instead. I tried some ways to encode and decode the output string but Python is not my strong suit.

Season banners should be accessible via t[&rsquo;show&rsquo;][1]

The current method of retrieving banners is a bit of a mess:

t[&rsquo;show&rsquo;][&rsquo;_banners&rsquo;][&rsquo;fanart&rsquo;][banners_id][&rsquo;_bannerpath&rsquo;]

..or something along those lines. Users should be able to do something like..

>>> t[&rsquo;show&rsquo;][&rsquo;_banners&rsquo;][&rsquo;posters&rsquo;]
[<Banner id:123>, <Banner id:124]
>>> t[&rsquo;show&rsquo;][&rsquo;_banners&rsquo;][&rsquo;posters&rsquo;][0][&rsquo;url&rsquo;]
http://....

original LH ticket

create .nfo file for episodes

Not sure if you will find this relevant to your project or not, but I thought I would suggest...

It might be interesting to have a library function that produces an episode .nfo file from an episode object.

Maybe this kind of mapping already exists somewhere that I am just not aware of.

Combine Multi-Season Episodes Into Single Season

Can i retrieve episode name using episode only without season? So for example:

season 1 has 50 episodes
season 2 has 50 episodes

Is it possible to just use episode 60 to get season 2 episode 10 name?

flag to _not_ add episode title to filename?

Great script, but I'd like to request one minor addition..
Could you possibly add a flag to restrict adding the episode title to the filename when renaming please?
so, as per the example in the readme:
"scrubs.s01e01.avi" would become "Scrubs - [01x01].avi"

I've got a couple of series with really long titles, and it's making the filenames a little unwieldy!

Implement Show slice

The Show class should support get_item() slice, which comes in handy when we want to get only a few seasons e.g., show[2:4] (or all seasons without specials - show[1:]).

That'd be nice to see this feature in future (:sunglasses:).

banners - filter/sort

would you be opposed to handling some logic inside the tvdb_api to handle the filter/sorting of banner data (basically change the default returned value).

sorting the banner data requested.. return the most popular / newest / oldest. filter data by size / language / if it includes seriesname

failed tests

need to see if this has been resolved in latest git, currently using 1.9

======================================================================
ERROR: test_search_checkname (test_tvdb_api.test_tvdb_search)
Checks you can get the episode name of a search result
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Program Files (x86)\Sick-Beard--dev\lib\tvdb_api\tests\test_tvdb_api.py", line 153, in test_search_checkname
    self.assertEquals(self.t['My Name Is Earl'].search('Faked His Own Death')[0]['episodename'], 'Faked His Own Death')
IndexError: list index out of range

======================================================================
FAIL: test_spaces (test_tvdb_api.test_tvdb_basic)
Checks shownames with spaces
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Program Files (x86)\Sick-Beard--dev\lib\tvdb_api\tests\test_tvdb_api.py", line 43, in test_spaces
    self.assertEquals(self.t['My Name Is Earl'][1][4]['episodename'], 'Faked His Own Death')
AssertionError: u'Faked My Own Death' != 'Faked His Own Death'

======================================================================
FAIL: test_search_len (test_tvdb_api.test_tvdb_search)
There should be only one result matching
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Program Files (x86)\Sick-Beard--dev\lib\tvdb_api\tests\test_tvdb_api.py", line 147, in test_search_len
    self.assertEquals(len(self.t['My Name Is Earl'].search('Faked His Own Death')), 1)
AssertionError: 0 != 1

======================================================================
FAIL: test_spaces_from_zip (test_tvdb_api.test_tvdb_zip)
Checks shownames with spaces
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Program Files (x86)\Sick-Beard--dev\lib\tvdb_api\tests\test_tvdb_api.py", line 509, in test_spaces_from_zip
    self.assertEquals(self.t['My Name Is Earl'][1][4]['episodename'], 'Faked His Own Death')
AssertionError: u'Faked My Own Death' != 'Faked His Own Death'

----------------------------------------------------------------------
Ran 47 tests in 13.883s

FAILED (failures=3, errors=1)

UnicodeEncodeError - When trying to print series

While testing some code I noticed a funky result for a show name, seeing if it was a bug within tvdb or the api I see that it looks like just a badly created show name... but still I dont think a unicode error should be returned if just printing the seriesname worked fine?

default locale/encoding:

>>> import sys, locale
>>> locale.getdefaultlocale()
('en_US', 'cp1252')
>>> sys.getdefaultencoding()
'ascii'

http://thetvdb.com/?tab=series&id=264024

>>> print t[264024]['seriesname']
More at IMDbPro » InuYasha: The Final Act
>>> print t[264024]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode character u'\xbb' in position 22: ordinal not in range(128)

http://thetvdb.com/?tab=series&id=264025

>>> print t[264025]['seriesname']
InuYasha: The Final Act
>>> print t[264025]
<Show InuYasha: The Final Act (containing 0 seasons)>

forced encoding to utf-8, notice difference in responses..

>>> sys.setdefaultencoding('UTF-8')
>>> print t[264024]['seriesname']
More at IMDbPro _ InuYasha: The Final Act
>>> print t[264024]
<Show More at IMDbPro A» InuYasha: The Final Act (containing 0 seasons)>

trakt tv

ever thought about doing a trakt.tv api ?

Occasional KeyError

I'm using tvdb_api 2.0. I do a lot of by-name accesses, e.g. tvdb["Show Name"]. I occasionally get the following exception:

DEBUG tvdb_api tvdb_api.py:1162: Getting show Adventure Time)
DEBUG tvdb_api tvdb_api.py:942: Searching for show Adventure%20Time)
... loads some data ...
DEBUG tvdb_api tvdb_api.py:952: Found series Adventure Time)
DEBUG tvdb_api tvdb_api.py:970: Auto-selecting first search result using BaseUI)
DEBUG tvdb_api tvdb_api.py:1165: Got Adventure Time, id 152831)
... later ...
DEBUG tvdb_api tvdb_api.py:1159: Correcting Adventure Time to 152831
DEBUG tvdb_api tvdb_api.py:1183: Got series id 152831
DEBUG tvdb_api tvdb_api.py:1159: Correcting Brooklyn Nine-Nine to 269586
DEBUG tvdb_api tvdb_api.py:1183: Got series id 269586
... later ...
DEBUG tvdb_api tvdb_api.py:1159: Correcting Adventure Time to 152831
DEBUG tvdb_api tvdb_api.py:1183: Got series id 152831
Traceback (most recent call last):)
... files files files ...
  File "/home/me/venv/lib/python2.7/site-packages/tvdb_api.py", line 1184, in __getitem__)
    return self.shows[sid])
KeyError: 152831

It looks like the "smart" garbage collection in ShowContainer isn't all that smart.

Some special carracter not recognize.

It's me again :D
I use Ubuntu Intrepid with UTF-8. Script recognize show name corretly from thetvdb but while renaming skipping that char.

see below:


####################
# Starting tvnamer
# Processing 5 files
# ..got tvdb mirrors
# Starting to process files
####################
# Processing Carnivale (season: 1, episode 11)
TVDB Search Results:
1 -> Carnivàle # http://thetvdb.com/?tab=series&id=70860
Automatically selecting only result
####################
Old name: Carnivale 1x11 - The Day of the Dead.avi
New name: Carnivle - [01x11] - Day of the Dead.avi
Rename?
([y]/n/a/q) y
..renamed
# Processing Carnivale (season: 1, episode 1)
####################
Old name: Carnivale 1x1 - Milfay.avi
New name: Carnivle - [01x01] - Milfay.avi
Rename?
([y]/n/a/q) y
..renamed
# Processing Carnivale (season: 1, episode 4)
####################
Old name: Carnivale 1x4 - Black Blizzard.avi
New name: Carnivle - [01x04] - Black Blizzard.avi
Rename?
([y]/n/a/q) y
..renamed
# Processing Carnivale (season: 1, episode 5)
####################
Old name: Carnivale 1x5 - Babylon.avi
New name: Carnivle - [01x05] - Babylon.avi
Rename?
([y]/n/a/q) y
..renamed
# Processing Carnivale (season: 1, episode 6)
####################
Old name: Carnivale 1x6 - Pick a Number.avi
New name: Carnivle - [01x06] - Pick a Number.avi
Rename?
([y]/n/a/q) y
..renamed

UnicodeEncodeError

When I execute the following script:

import tvdb_api
tv = tvdb_api.Tvdb()
s = tv['Sons of Anarchy']
print s[2][13]

This is what I get:
Traceback (most recent call last):
File "", line 1, in
UnicodeEncodeError: 'ascii' codec can't encode character u'\xf3' in position 26: ordinal not in range(128)

tvnamer parsing of multi-languages filenames does not work

When tvnamer is used on unicode filenames the regex strings need to be modified. These new regex strings will still work for regular ascii filenames. tvnamer has other errors when processing unicode filenames that I do not have patches for. I use these regex strings in my own scripts to parse unicode filenames for season and episode numbers. They were originally based on tvnamer file processing.

New regex strings:

config[&rsquo;name_parse&rsquo;] = [
    # foo_[s01]_[e01]
    re.compile(&rsquo;&rsquo;&rsquo;^(.+?)[ \._\-]\[[Ss]([0-9]+?)\]_\[[Ee]([0-9]+?)\]?[^\\/]*$&rsquo;&rsquo;&rsquo;% (config[&rsquo;valid_filename_chars_regex&rsquo;])),
    # foo.1x09*
    re.compile(&rsquo;&rsquo;&rsquo;^(.+?)[ \._\-]\[?([0-9]+)x([0-9]+)[^\\/]*$&rsquo;&rsquo;&rsquo; % (config[&rsquo;valid_filename_chars_regex&rsquo;])),
    # foo.s01.e01, foo.s01_e01
    re.compile(&rsquo;&rsquo;&rsquo;^(.+?)[ \._\-][Ss]([0-9]+)[\.\- ]?[Ee]([0-9]+)[^\\/]*$&rsquo;&rsquo;&rsquo; % (config[&rsquo;valid_filename_chars_regex&rsquo;])),
    # foo.103*
    re.compile(&rsquo;&rsquo;&rsquo;^(.+)[ \._\-]([0-9]{1})([0-9]{2})[\._ -][^\\/]*$&rsquo;&rsquo;&rsquo; % (config[&rsquo;valid_filename_chars_regex&rsquo;])),
    # foo.0103*
    re.compile(&rsquo;&rsquo;&rsquo;^(.+)[ \._\-]([0-9]{2})([0-9]{2,3})[\._ -][^\\/]*$&rsquo;&rsquo;&rsquo; % (config[&rsquo;valid_filename_chars_regex&rsquo;])),
]

original LH ticket

episode['filename'] gives str rather than unicode

I expect unicode always from the API but found that the filename key in the episode object gives me a str instead.

import tvdb_api
t = tvdb_api.Tvdb()
s = t['californication']
e = s[1][2]
e['filename']
'http://www.thetvdb.com/banners/episodes/80349/332181.jpg'
e['episodename']
u'Hell-A Woman'

I haven't looked at how simple it is to fix yet, I will probably fix it in my fork but I figured I'd log this anyway.

IPV6 - Hangs

Originally ipv6 was compiled in the kernel and enabled. The runtest.py hung indefinitely on the first request. I believe urllib2 is picking ipv6 instead of ipv4 which tvdb apparently has an issue with. Is there a workaround to force urllib2 to use ipv4? When I flip ipv6 off system wide through sysctl it "Ran 47 tests in 15.326s". Running python 2.7.5 and tvdb_api 1.9. Even curl hangs indefinitely with ipv6.

sanitation?

notice that there is a \t and leading spaces for one of the aliases:

            {
                "aliasnames": [
                    "\t  Shipwrecked: Battle of the Islands", 
                    "Shipwrecked: The Island"
                ], 
                "firstaired": "2007-01-20", 
                "language": "en", 
                "lid": 7, 
                "seriesname": "Shipwrecked", 
                "network": "Channel 4", 
                "overview": "This is a British reality contest show with a twist. Instead of trying to eliminate others, the contestants try to get people to choose to hang out with them on \"their island.\" Ten people are split between two islands. One group is called Tigers, the others Sharks. Each week, a new contestant arrives and spends 3 days with the Tigers, and then 3 days with the Sharks. On the seventh day, the groups all get together and have a \"beach party\" during which the new arrival must decide who they want to stay with for the remainder of the show. Whichever island has more people at the end of 5 months wins \u00a370,000.", 
                "seriesid": "80347", 
                "id": 80347
            }, 

xml doesnt obtain aliases..
http://thetvdb.com/api/9DAF49C96CBF8DAC/series/80347/all/en.xml

--added post to tvdb forums about this, maybe they can do their part to prevent this from happening in the future: http://forums.thetvdb.com/viewtopic.php?f=17&t=15279

leading space in one of the aliases,

            {
                "aliasnames": [
                    "Fight Ippatsu! Juuden-chan!!", 
                    "Fight Ippatsu! J\u016bden-chan!!", 
                    " Fight, One Shot! Charger Girls!!"
                ], 
                "firstaired": "2009-06-25", 
                "language": "en", 
                "lid": 7, 
                "seriesname": "Charger Girl Ju-den Chan", 
                "overview": "From a planet called \"Life Core\", which exists parallel to the normal human world, females known as \"J\u016bden-chan\" (charger girls) are patrolling the human world in search for individuals who feel depressed and unlucky. These people are ranked from A to F, F being normal and A being near suicidal. When the J\u016bden-chan find targets ranked C or higher, they charge these people up with the help of electricity in order to improve their mental states. Whilst normally unseen by human eyes, one of these J\u016bden-chan, Plug Cryostat, accidentally meets a young man who is able to see her, because she was targeting his father (his sister in the anime). This series revolves around the various antics between the main characters and the quest for this J\u016bden-chan to improve herself.", 
                "seriesid": "103291", 
                "id": 103291
            }, 

this one has random \n in the overview,

            {
                "language": "en", 
                "lid": 7, 
                "seriesname": "Conspiracies", 
                "overview": "Sky One aims to sort reality from rumour with four more intriguing cases in the new series of Conspiracies. Danny Wallace is back seeking answers to some disturbing questions. Did the CIA play geopolitics with lives at Lockerbie? Is the government conducting a top-secret alien programme? Did the Nazis invade England\u2019s green and pleasant land? And was the FBI responsible for mass murder at Waco? \nTravelling the globe on a definitive search for the truth, Danny talks to those who claim to be in the know. Each one hour episode dissects a different conspiracy: The Alien Evidence, MI5 Nazi Invasion, Carnage at Waco, Lockerbie and the CIA. \n\nConspiracies challenges the culture of control and secrecy of our governments as Danny Wallace goes in search of the answers to these alarming questions. Cover up or cock-up? This illuminating series aims to find out. \n \n \n", 
                "seriesid": "81568", 
                "id": 81568
            }, 

xml that shows the \n are still there:
http://thetvdb.com/api/9DAF49C96CBF8DAC/series/81568/all/en.xml

internally I've done something like:

cshow["overview"] = cshow["overview"].encode("UTF-8", "ignore").replace('  ', ' ').strip(' \t\n\r').replace('\n', '')

which cleans up things a bit.. ive seen show overview in the past contain html tags as well - but thats a whole other battle :(

I know there are plenty that probably dont want anything to be modified from what is on the tvdb.. for others I'm sure it would be nice to see .strip(' \t\n\r') done on each element (at least the aliases/overview which seem to be the main source of problems) - the problem with strip is that it only does leading/trailing while the \n in the middle of the string wouldnt be touched :(

Option to remember naming choices from previous runs

I like to run the script recursively over my library. I re-run it every so often to pick up any new files and any new tvdb info. I run it with "-rv" flags. It would be helpful if it would remember certain choices I've made between runs e.g.:

Old name: Name.EpisodeName.01x01.avi
New name: Name [01x01].avi
Rename?
([y]/n/a/q)

On this choice I'll hit "n" since I don't want to lose the episode name. I would like this choice remembered on a subsequent run so that I will not be prompted again.

Options to 1) clear 2) ignore previous choices would be good.

Add git tag for 2.0 release

Currently the tag is missing. Please add a 2.0 git tag referencing the commit that was used to upload/release to PyPI

Create Directory Structure.

Hi again,

First of all sorry about request here. I saw your note about Lighthouse. I'm too lazy for create account :)

Could you add directory structure feature? Something like SABnzbd tvsort function?
http://trac2.assembla.com/SABnzbd/browser/trunk/main/sabnzbd/tvsort.py

Searching file on tvdb then create and move to directory.

$ tvnamer scrubs.s01e01.avi
####################
# Starting tvnamer
# Processing 1 files
# ..got tvdb mirrors
# Starting to process files
####################
# Processing scrubs (season: 1, episode 1)
TVDB Search Results:
1 -> Scrubs # http://thetvdb.com/?tab=series&id=76156
Automatically selecting only result
####################
Old name: scrubs.s01e01.avi
New name: Scrubs - [01x01] - My First Day.avi
New directory: Scrubs/Season 1/
Rename and move?
([y]/n/a/q)

Episode ID search

Hi !
Thanks for you API, it fantastic :)
I would know if it's possible to search an episode with his own TV ID ?

Thks !
Slaan.

There was an error with the XML retrieved from thetvdb.com

>>> import tvdb_api
>>> t = tvdb_api.Tvdb()
>>> show = t['Sugar and Spice']
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "tvdb_api.py", line 877, in __getitem__
    sid = self._nameToSid(key)
  File "tvdb_api.py", line 857, in _nameToSid
    selected_series = self._getSeries( name )
  File "tvdb_api.py", line 643, in _getSeries
    allSeries = self.search(series)
  File "tvdb_api.py", line 624, in search
    seriesEt = self._getetsrc(self.config['url_getSeries'] % (series))
  File "tvdb_api.py", line 575, in _getetsrc
    raise tvdb_error(errormsg)
tvdb_exceptions.tvdb_error: There was an error with the XML retrieved from thetvdb.com:
not well-formed (invalid token): line 7, column 68

Looking at XML for show:
http://thetvdb.com/api/9DAF49C96CBF8DAC/series/78252/all/en.xml

We can see its because html is in the overview:

<Overview>Welcome to the Sugar and Spice guide at TV Tome. <p align=left> Loretta Fontaine and Vickilyn Fontaine Clayton, two black sisters living in a small Oklahoma town who attempt to raise their rambunctious teenage niece, Toby Reed (played by La Verne Anderson) after her parents are killed in a car accident. Vicklyn runs a curio shop called Small World Miniatures, and Loretta is a hostess at Cafe Jacques. All three live at 731 Oakwood Avenue in Ponca City. <p align=left>First Telecast:March 30,1990 <p align=left>Last Telecast:May 25, 1990 <p align=left>Episodes: 7 color episodes. <p align=center> CBS Broadcast History <p align =center>March-May 1990----Fridays----9:30
<p align=center>May 1990----Fridays----8:30
<p align=center>Theme song: <p align=center> Performed by Loretta Devine and Vickilyn Reynolds</Overview>

Another one,

>>> show = t['Someone Like Me']
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "tvdb_api.py", line 877, in __getitem__
    sid = self._nameToSid(key)
  File "tvdb_api.py", line 857, in _nameToSid
    selected_series = self._getSeries( name )
  File "tvdb_api.py", line 643, in _getSeries
    allSeries = self.search(series)
  File "tvdb_api.py", line 624, in search
    seriesEt = self._getetsrc(self.config['url_getSeries'] % (series))
  File "tvdb_api.py", line 575, in _getetsrc
    raise tvdb_error(errormsg)
tvdb_exceptions.tvdb_error: There was an error with the XML retrieved from thetvdb.com:
mismatched tag: line 8, column 93

Looking at XML:
http://thetvdb.com/api/9DAF49C96CBF8DAC/series/78253/all/en.xml

We can see its because html is in the overview:

<Overview>Welcome to the <B>Someone Like Me guide at TV Tome.
There is no editor for this show. If you would like to be the editor look here for details.</Overview>

Fixing these manually.. rumor is that new tvdb site is coming soon (heard that before.. ) since this has been an ongoing issue forever on this site.. any advice on how to just prune html out of that damn overview field? Or if we wanted to just nuke that field?

Extracting episode info using episode name

Hi!
First of all I want to thank you for writing this excellent API. :)
I was wondering if it is possible to extract information from an episode by using the name of the episode instead of the season number and episode number.

So for example. I can do the following to extract information from an episode by referring to the season number and episode number:

>>> t['Lost'][4][11]
<Episode 04x11 - Cabin Fever>

But would it be possible to something like the following instead?

>>> t['Lost']['Cabin Fever']
<Episode 04x11 - Cabin Fever>

Thanks.

Anomalous behavior for recent shows in TVDB.api

I'm experiencing a problem retrieving recent TV show overviews from TVDB

Specifically, I call the episode overview from the TVDB database, thus:

#!/usr/bin/python   
# getoverview.py
import sys, tvdb_api   
t = tvdb_api.Tvdb()   
episode = t [str(sys.argv[1])] [float(sys.argv[2])] [float(sys.argv[3])]   
ov = episode['overview']   
print ov.encode('UTF-8')

For shows before May 1, typing getoverview.py Homeland 7 11, for example, returns "Saul's mission is a go. The clock ticks on the Keane administration.", as expected.

For shows that aired their first episodes after May 1, however, typing getoverview.py Sweetbitter 1 1 or getoverview.py "Cobra Kai" 1 6 returns errors:

Traceback (most recent call last):  
  File "/usr/local/bin/getoverview.py", line 9, in <module>
    print ov.encode('UTF-8')
AttributeError: 'NoneType' object has no attribute 'encode'

I have verified that the episode overview is present on the web page for both these examples.

I am using tvnamer 2.4, updated flexget to the current version, and both of these appear to link to tvdb.api(), so whatever error I am making is a subtle one (at least to me). Help would be appreciated.

Selecting series ID 290490 (BBC News Witness) fails

I discovered this while iterating over a search result.

import tvdb_api
tvdb = tvdb_api.Tvdb()

Now, selecting this specific series by id or name fails:

s_by_id = tvdb[290490]
s_by_name = tvdb['BBC News Witness']

Passing in variables for Season / Episode Numbers

when I try to send in variables for the Season# and Episode# I get an error

when I run:
(sys.argv[1]="veep" , sys.argv[2]=1 , sys.argv[3]=1)

t = tvdb_api.Tvdb(cache = True)
tvEpisode = t[ sys.argv[1] ][ sys.argv[2] ][ sys.argv[3] ]

and I get this error:

File "/usr/local/lib/python2.7/dist-packages/tvdb_api-1.9-py2.7.egg/tvdb_api.py", line 106, in getitem
raise tvdb_seasonnotfound("Could not find season %s" % (repr(key)))
tvdb_exceptions.tvdb_seasonnotfound: Could not find season '1'

It does this for any show I try to send variables to, Is there a way I can fix this?

Need some modification for Anime series.

Hi i really like your script. Could you pls update tvnamer.py for Anime series? Most of anime series haven't season number.

Some examples for Anime filenames:

[Eclipse] Fullmetal Alchemist Brotherhood - 02 (1280x720 h264) [8452C4BF].mkv
[Shinsen-Subs] Armored Trooper Votoms - Pailsen Files - 01 [9E3F1D1C].avi
[Shinsen-Subs] Beet - 19 [24DAB497].avi
[AG-SHS]_Victory_Gundam_-_03_DVD_[FC6E3A6F].avi
[YuS-SHS]_Gintama_-_88_(H264)_[52CA4F8B].mp4

(?:[.+?])

Funsub name and codes not neded ofcourse :)

Thx.

Ignore non-media files

The tvnamer script could ignore non-media files such as ones with .txt or .nfo extensions.

proxy support?

i noticed that a few years ago a sickbeard user added proxy support to tvdb_api... since then its been nuked during upgrades to newer tvdb_api (dont think others realized it was modified). anyways curious if the type of change is valid to be done in the core of tvdb_api or what.

the original old commit is here:
midgetspy/Sick-Beard@d46740e

after the fact there were some small tweaks which resulted in:
https://github.com/midgetspy/Sick-Beard/blob/f4920025aafe0f617426623755004b1fc0e1be3e/lib/tvdb_api/tvdb_api.py

as you can see its quite old (1.5) but figured I'd share what i found. i know nothing of proxy.. so i cant even begin to say if this is good code/warranted or what.

Banner rating always 0

This is on the latest PyPI version (2.0)

For example for the top rated poster of "Doctor Who (2005)":

In [71]: tvdb['doctor who (2005)']['_banners']['poster']['raw'][47]
Out[71]: 
{'id': 1105324,
 'keyType': 'poster',
 'subKey': '',
 'fileName': 'posters/78804-52.jpg',
 'resolution': '680x1000',
 'ratingsInfo': {'average': 0, 'count': 0},
 'thumbnail': ''}

Better handling of years

I often have movies interspersed in my files. I get offered choices like:
Old name: Film Name.2009.avi
New name: Film Name [20x09].avi
Rename?
([y]/n/a/q)

This does not make so much sense. I guess some series run into seasons 19 and 20 but perhaps a heuristic could be figured out.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.