mirror of
https://github.com/moparisthebest/SickRage
synced 2024-12-04 15:12:23 -05:00
Fixed system path to prepend instead of append for custom libs
This commit is contained in:
parent
7c6b1b32de
commit
44ae0c2933
@ -45,7 +45,7 @@ except:
|
||||
|
||||
import os
|
||||
|
||||
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), 'lib')))
|
||||
sys.path.insert(1, os.path.abspath(os.path.join(os.path.dirname(__file__), 'lib')))
|
||||
|
||||
# We only need this for compiling an EXE and I will just always do that on 2.6+
|
||||
if sys.hexversion >= 0x020600F0:
|
||||
|
@ -1,4 +0,0 @@
|
||||
include UNLICENSE
|
||||
include readme.md
|
||||
include tests/*.py
|
||||
include Rakefile
|
@ -1,103 +0,0 @@
|
||||
require 'fileutils'
|
||||
|
||||
task :default => [:clean]
|
||||
|
||||
task :clean do
|
||||
[".", "tests"].each do |cd|
|
||||
puts "Cleaning directory #{cd}"
|
||||
Dir.new(cd).each do |t|
|
||||
if t =~ /.*\.pyc$/
|
||||
puts "Removing #{File.join(cd, t)}"
|
||||
File.delete(File.join(cd, t))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
desc "Upversion files"
|
||||
task :upversion do
|
||||
puts "Upversioning"
|
||||
|
||||
Dir.glob("*.py").each do |filename|
|
||||
f = File.new(filename, File::RDWR)
|
||||
contents = f.read()
|
||||
|
||||
contents.gsub!(/__version__ = ".+?"/){|m|
|
||||
cur_version = m.scan(/\d+\.\d+/)[0].to_f
|
||||
new_version = cur_version + 0.1
|
||||
|
||||
puts "Current version: #{cur_version}"
|
||||
puts "New version: #{new_version}"
|
||||
|
||||
new_line = "__version__ = \"#{new_version}\""
|
||||
|
||||
puts "Old line: #{m}"
|
||||
puts "New line: #{new_line}"
|
||||
|
||||
m = new_line
|
||||
}
|
||||
|
||||
puts contents[0]
|
||||
|
||||
f.truncate(0) # empty the existing file
|
||||
f.seek(0)
|
||||
f.write(contents.to_s) # write modified file
|
||||
f.close()
|
||||
end
|
||||
end
|
||||
|
||||
desc "Upload current version to PyPi"
|
||||
task :topypi => :test do
|
||||
cur_file = File.open("tvdb_api.py").read()
|
||||
tvdb_api_version = cur_file.scan(/__version__ = "(.*)"/)
|
||||
tvdb_api_version = tvdb_api_version[0][0].to_f
|
||||
|
||||
puts "Build sdist and send tvdb_api v#{tvdb_api_version} to PyPi?"
|
||||
if $stdin.gets.chomp == "y"
|
||||
puts "Sending source-dist (sdist) to PyPi"
|
||||
|
||||
if system("python setup.py sdist register upload")
|
||||
puts "tvdb_api uploaded!"
|
||||
end
|
||||
|
||||
else
|
||||
puts "Cancelled"
|
||||
end
|
||||
end
|
||||
|
||||
desc "Profile by running unittests"
|
||||
task :profile do
|
||||
cd "tests"
|
||||
puts "Profiling.."
|
||||
`python -m cProfile -o prof_runtest.prof runtests.py`
|
||||
puts "Converting prof to dot"
|
||||
`python gprof2dot.py -o prof_runtest.dot -f pstats prof_runtest.prof`
|
||||
puts "Generating graph"
|
||||
`~/Applications/dev/graphviz.app/Contents/macOS/dot -Tpng -o profile.png prof_runtest.dot -Gbgcolor=black`
|
||||
puts "Cleanup"
|
||||
rm "prof_runtest.dot"
|
||||
rm "prof_runtest.prof"
|
||||
end
|
||||
|
||||
task :test do
|
||||
puts "Nosetest'ing"
|
||||
if not system("nosetests -v --with-doctest")
|
||||
raise "Test failed!"
|
||||
end
|
||||
|
||||
puts "Doctesting *.py (excluding setup.py)"
|
||||
Dir.glob("*.py").select{|e| ! e.match(/setup.py/)}.each do |filename|
|
||||
if filename =~ /^setup\.py/
|
||||
skip
|
||||
end
|
||||
puts "Doctesting #{filename}"
|
||||
if not system("python", "-m", "doctest", filename)
|
||||
raise "Failed doctest"
|
||||
end
|
||||
end
|
||||
|
||||
puts "Doctesting readme.md"
|
||||
if not system("python", "-m", "doctest", "readme.md")
|
||||
raise "Doctest"
|
||||
end
|
||||
end
|
@ -1,26 +0,0 @@
|
||||
Copyright 2011-2012 Ben Dickson (dbr)
|
||||
|
||||
This is free and unencumbered software released into the public domain.
|
||||
|
||||
Anyone is free to copy, modify, publish, use, compile, sell, or
|
||||
distribute this software, either in source code form or as a compiled
|
||||
binary, for any purpose, commercial or non-commercial, and by any
|
||||
means.
|
||||
|
||||
In jurisdictions that recognize copyright laws, the author or authors
|
||||
of this software dedicate any and all copyright interest in the
|
||||
software to the public domain. We make this dedication for the benefit
|
||||
of the public at large and to the detriment of our heirs and
|
||||
successors. We intend this dedication to be an overt act of
|
||||
relinquishment in perpetuity of all present and future rights to this
|
||||
software under copyright law.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
For more information, please refer to <http://unlicense.org/>
|
@ -1,109 +0,0 @@
|
||||
# `tvdb_api`
|
||||
|
||||
`tvdb_api` is an easy to use interface to [thetvdb.com][tvdb]
|
||||
|
||||
`tvnamer` has moved to a separate repository: [github.com/dbr/tvnamer][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`)
|
||||
|
||||
[![Build Status](https://secure.travis-ci.org/dbr/tvdb_api.png?branch=master)](http://travis-ci.org/dbr/tvdb_api)
|
||||
|
||||
## To install
|
||||
|
||||
You can easily install `tvdb_api` via `easy_install`
|
||||
|
||||
easy_install tvdb_api
|
||||
|
||||
You may need to use sudo, depending on your setup:
|
||||
|
||||
sudo easy_install tvdb_api
|
||||
|
||||
The [`tvnamer`][tvnamer] command-line tool can also be installed via `easy_install`, this installs `tvdb_api` as a dependancy:
|
||||
|
||||
easy_install tvnamer
|
||||
|
||||
|
||||
## Basic usage
|
||||
|
||||
import tvdb_api
|
||||
t = indexerApi()
|
||||
episode = t['My Name Is Earl'][1][3] # get season 1, episode 3 of show
|
||||
print episode['episodename'] # Print episode name
|
||||
|
||||
## 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][tvdb] (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][tvdb] is accessible via the `Show` class. A Show is retrieved by doing..
|
||||
|
||||
>>> import tvdb_api
|
||||
>>> t = indexerApi()
|
||||
>>> 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', 'imdb_id', 'genre', 'banner', 'seriesid', 'language', 'zap2it_id', 'addedby', 'tms_wanted', '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|Christa Miller|Aloma Wright|Robert Maschio|Sam Lloyd|Neil Flynn|Ken Jenkins|Judy Reyes|John C. McGinley|Travis Schuldt|Johnny Kastl|Heather Graham|Michael Mosley|Kerry Bish\xe9|Dave Franco|Eliza Coupe|'
|
||||
|
||||
[tvdb]: http://thetvdb.com
|
||||
[tvnamer]: http://github.com/dbr/tvnamer
|
@ -1,35 +0,0 @@
|
||||
from setuptools import setup
|
||||
setup(
|
||||
name = 'tvdb_api',
|
||||
version='1.9',
|
||||
|
||||
author='dbr/Ben',
|
||||
description='Interface to thetvdb.com',
|
||||
url='http://github.com/dbr/tvdb_api/tree/master',
|
||||
license='unlicense',
|
||||
|
||||
long_description="""\
|
||||
An easy to use API interface to TheTVDB.com
|
||||
Basic usage is:
|
||||
|
||||
>>> import tvdb_api
|
||||
>>> t = tvdb_api.Tvdb()
|
||||
>>> ep = t['My Name Is Earl'][1][22]
|
||||
>>> ep
|
||||
<Episode 01x22 - Stole a Badge>
|
||||
>>> ep['episodename']
|
||||
u'Stole a Badge'
|
||||
""",
|
||||
|
||||
py_modules = ['tvdb_api', 'tvdb_ui', 'tvdb_exceptions', 'tvdb_cache'],
|
||||
|
||||
classifiers=[
|
||||
"Intended Audience :: Developers",
|
||||
"Natural Language :: English",
|
||||
"Operating System :: OS Independent",
|
||||
"Programming Language :: Python",
|
||||
"Topic :: Multimedia",
|
||||
"Topic :: Utilities",
|
||||
"Topic :: Software Development :: Libraries :: Python Modules",
|
||||
]
|
||||
)
|
File diff suppressed because it is too large
Load Diff
@ -1,28 +0,0 @@
|
||||
#!/usr/bin/env python2
|
||||
#encoding:utf-8
|
||||
#author:dbr/Ben
|
||||
#project:tvdb_api
|
||||
#repository:http://github.com/dbr/tvdb_api
|
||||
#license:unlicense (http://unlicense.org/)
|
||||
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
import test_tvdb_api
|
||||
|
||||
def main():
|
||||
suite = unittest.TestSuite([
|
||||
unittest.TestLoader().loadTestsFromModule(test_tvdb_api)
|
||||
])
|
||||
|
||||
runner = unittest.TextTestRunner(verbosity=2)
|
||||
result = runner.run(suite)
|
||||
if result.wasSuccessful():
|
||||
return 0
|
||||
else:
|
||||
return 1
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(
|
||||
int(main())
|
||||
)
|
@ -1,577 +0,0 @@
|
||||
#!/usr/bin/env python2
|
||||
#encoding:utf-8
|
||||
#author:dbr/Ben
|
||||
#project:tvdb_api
|
||||
#repository:http://github.com/dbr/tvdb_api
|
||||
#license:unlicense (http://unlicense.org/)
|
||||
|
||||
"""Unittests for tvdb_api
|
||||
"""
|
||||
|
||||
import os,os.path
|
||||
import sys
|
||||
print sys.path
|
||||
import datetime
|
||||
import unittest
|
||||
|
||||
# Force parent directory onto path
|
||||
#sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
sys.path.append(os.path.abspath('../../tests'))
|
||||
|
||||
|
||||
import sickbeard
|
||||
|
||||
|
||||
from tvdb_api import Tvdb
|
||||
import tvdb_ui
|
||||
from tvdb_api import (tvdb_shownotfound, tvdb_seasonnotfound,
|
||||
tvdb_episodenotfound, tvdb_attributenotfound)
|
||||
from lib import xmltodict
|
||||
import lib
|
||||
|
||||
class test_tvdb_basic(unittest.TestCase):
|
||||
# Used to store the cached instance of Tvdb()
|
||||
t = None
|
||||
|
||||
def setUp(self):
|
||||
if self.t is None:
|
||||
self.__class__.t = tvdb_api.Tvdb(cache = True, banners = False)
|
||||
|
||||
def test_different_case(self):
|
||||
"""Checks the auto-correction of show names is working.
|
||||
It should correct the weirdly capitalised 'sCruBs' to 'Scrubs'
|
||||
"""
|
||||
self.assertEquals(self.t['scrubs'][1][4]['episodename'], 'My Old Lady')
|
||||
self.assertEquals(self.t['sCruBs']['seriesname'], 'Scrubs')
|
||||
|
||||
def test_spaces(self):
|
||||
"""Checks shownames with spaces
|
||||
"""
|
||||
self.assertEquals(self.t['My Name Is Earl']['seriesname'], 'My Name Is Earl')
|
||||
self.assertEquals(self.t['My Name Is Earl'][1][4]['episodename'], 'Faked His Own Death')
|
||||
|
||||
def test_numeric(self):
|
||||
"""Checks numeric show names
|
||||
"""
|
||||
self.assertEquals(self.t['24'][2][20]['episodename'], 'Day 2: 3:00 A.M.-4:00 A.M.')
|
||||
self.assertEquals(self.t['24']['seriesname'], '24')
|
||||
|
||||
def test_show_iter(self):
|
||||
"""Iterating over a show returns each seasons
|
||||
"""
|
||||
self.assertEquals(
|
||||
len(
|
||||
[season for season in self.t['Life on Mars']]
|
||||
),
|
||||
2
|
||||
)
|
||||
|
||||
def test_season_iter(self):
|
||||
"""Iterating over a show returns episodes
|
||||
"""
|
||||
self.assertEquals(
|
||||
len(
|
||||
[episode for episode in self.t['Life on Mars'][1]]
|
||||
),
|
||||
8
|
||||
)
|
||||
|
||||
def test_get_episode_overview(self):
|
||||
"""Checks episode overview is retrieved correctly.
|
||||
"""
|
||||
self.assertEquals(
|
||||
self.t['Battlestar Galactica (2003)'][1][6]['overview'].startswith(
|
||||
'When a new copy of Doral, a Cylon who had been previously'),
|
||||
True
|
||||
)
|
||||
|
||||
def test_get_parent(self):
|
||||
"""Check accessing series from episode instance
|
||||
"""
|
||||
show = self.t['Battlestar Galactica (2003)']
|
||||
season = show[1]
|
||||
episode = show[1][1]
|
||||
|
||||
self.assertEquals(
|
||||
season.show,
|
||||
show
|
||||
)
|
||||
|
||||
self.assertEquals(
|
||||
episode.season,
|
||||
season
|
||||
)
|
||||
|
||||
self.assertEquals(
|
||||
episode.season.show,
|
||||
show
|
||||
)
|
||||
|
||||
def test_no_season(self):
|
||||
show = self.t['Katekyo Hitman Reborn']
|
||||
print tvdb_api
|
||||
print show[1][1]
|
||||
|
||||
|
||||
class test_tvdb_errors(unittest.TestCase):
|
||||
# Used to store the cached instance of Tvdb()
|
||||
t = None
|
||||
|
||||
def setUp(self):
|
||||
if self.t is None:
|
||||
self.__class__.t = tvdb_api.Tvdb(cache = True, banners = False)
|
||||
|
||||
def test_seasonnotfound(self):
|
||||
"""Checks exception is thrown when season doesn't exist.
|
||||
"""
|
||||
self.assertRaises(tvdb_seasonnotfound, lambda:self.t['CNNNN'][10][1])
|
||||
|
||||
def test_shownotfound(self):
|
||||
"""Checks exception is thrown when episode doesn't exist.
|
||||
"""
|
||||
self.assertRaises(tvdb_shownotfound, lambda:self.t['the fake show thingy'])
|
||||
|
||||
def test_episodenotfound(self):
|
||||
"""Checks exception is raised for non-existent episode
|
||||
"""
|
||||
self.assertRaises(tvdb_episodenotfound, lambda:self.t['Scrubs'][1][30])
|
||||
|
||||
def test_attributenamenotfound(self):
|
||||
"""Checks exception is thrown for if an attribute isn't found.
|
||||
"""
|
||||
self.assertRaises(tvdb_attributenotfound, lambda:self.t['CNNNN'][1][6]['afakeattributething'])
|
||||
self.assertRaises(tvdb_attributenotfound, lambda:self.t['CNNNN']['afakeattributething'])
|
||||
|
||||
class test_tvdb_search(unittest.TestCase):
|
||||
# Used to store the cached instance of Tvdb()
|
||||
t = None
|
||||
|
||||
def setUp(self):
|
||||
if self.t is None:
|
||||
self.__class__.t = tvdb_api.Tvdb(cache = True, banners = False)
|
||||
|
||||
def test_search_len(self):
|
||||
"""There should be only one result matching
|
||||
"""
|
||||
self.assertEquals(len(self.t['My Name Is Earl'].search('Faked His Own Death')), 1)
|
||||
|
||||
def test_search_checkname(self):
|
||||
"""Checks you can get the episode name of a search result
|
||||
"""
|
||||
self.assertEquals(self.t['Scrubs'].search('my first')[0]['episodename'], 'My First Day')
|
||||
self.assertEquals(self.t['My Name Is Earl'].search('Faked His Own Death')[0]['episodename'], 'Faked His Own Death')
|
||||
|
||||
def test_search_multiresults(self):
|
||||
"""Checks search can return multiple results
|
||||
"""
|
||||
self.assertEquals(len(self.t['Scrubs'].search('my first')) >= 3, True)
|
||||
|
||||
def test_search_no_params_error(self):
|
||||
"""Checks not supplying search info raises TypeError"""
|
||||
self.assertRaises(
|
||||
TypeError,
|
||||
lambda: self.t['Scrubs'].search()
|
||||
)
|
||||
|
||||
def test_search_season(self):
|
||||
"""Checks the searching of a single season"""
|
||||
self.assertEquals(
|
||||
len(self.t['Scrubs'][1].search("First")),
|
||||
3
|
||||
)
|
||||
|
||||
def test_search_show(self):
|
||||
"""Checks the searching of an entire show"""
|
||||
self.assertEquals(
|
||||
len(self.t['CNNNN'].search('CNNNN', key='episodename')),
|
||||
3
|
||||
)
|
||||
|
||||
def test_aired_on(self):
|
||||
"""Tests airedOn show method"""
|
||||
sr = self.t['Scrubs'].airedOn(datetime.date(2001, 10, 2))
|
||||
self.assertEquals(len(sr), 1)
|
||||
self.assertEquals(sr[0]['episodename'], u'My First Day')
|
||||
|
||||
class test_tvdb_data(unittest.TestCase):
|
||||
# Used to store the cached instance of Tvdb()
|
||||
t = None
|
||||
|
||||
def setUp(self):
|
||||
if self.t is None:
|
||||
self.__class__.t = tvdb_api.Tvdb(cache = True, banners = False)
|
||||
|
||||
def test_episode_data(self):
|
||||
"""Check the firstaired value is retrieved
|
||||
"""
|
||||
self.assertEquals(
|
||||
self.t['lost']['firstaired'],
|
||||
'2004-09-22'
|
||||
)
|
||||
|
||||
class test_tvdb_misc(unittest.TestCase):
|
||||
# Used to store the cached instance of Tvdb()
|
||||
t = None
|
||||
|
||||
def setUp(self):
|
||||
if self.t is None:
|
||||
self.__class__.t = tvdb_api.Tvdb(cache = True, banners = False)
|
||||
|
||||
def test_repr_show(self):
|
||||
"""Check repr() of Season
|
||||
"""
|
||||
self.assertEquals(
|
||||
repr(self.t['CNNNN']),
|
||||
"<Show Chaser Non-Stop News Network (CNNNN) (containing 3 seasons)>"
|
||||
)
|
||||
def test_repr_season(self):
|
||||
"""Check repr() of Season
|
||||
"""
|
||||
self.assertEquals(
|
||||
repr(self.t['CNNNN'][1]),
|
||||
"<Season instance (containing 9 episodes)>"
|
||||
)
|
||||
def test_repr_episode(self):
|
||||
"""Check repr() of Episode
|
||||
"""
|
||||
self.assertEquals(
|
||||
repr(self.t['CNNNN'][1][1]),
|
||||
"<Episode 01x01 - Terror Alert>"
|
||||
)
|
||||
def test_have_all_languages(self):
|
||||
"""Check valid_languages is up-to-date (compared to languages.xml)
|
||||
"""
|
||||
et = self.t._getetsrc(
|
||||
"http://thetvdb.com/api/%s/languages.xml" % (
|
||||
self.t.config['apikey']
|
||||
)
|
||||
)
|
||||
languages = [x.find("abbreviation").text for x in et.findall("Language")]
|
||||
|
||||
self.assertEquals(
|
||||
sorted(languages),
|
||||
sorted(self.t.config['valid_languages'])
|
||||
)
|
||||
|
||||
class test_tvdb_languages(unittest.TestCase):
|
||||
def test_episode_name_french(self):
|
||||
"""Check episode data is in French (language="fr")
|
||||
"""
|
||||
t = tvdb_api.Tvdb(cache = True, language = "fr")
|
||||
self.assertEquals(
|
||||
t['scrubs'][1][1]['episodename'],
|
||||
"Mon premier jour"
|
||||
)
|
||||
self.assertTrue(
|
||||
t['scrubs']['overview'].startswith(
|
||||
u"J.D. est un jeune m\xe9decin qui d\xe9bute"
|
||||
)
|
||||
)
|
||||
|
||||
def test_episode_name_spanish(self):
|
||||
"""Check episode data is in Spanish (language="es")
|
||||
"""
|
||||
t = tvdb_api.Tvdb(cache = True, language = "es")
|
||||
self.assertEquals(
|
||||
t['scrubs'][1][1]['episodename'],
|
||||
"Mi Primer Dia"
|
||||
)
|
||||
self.assertTrue(
|
||||
t['scrubs']['overview'].startswith(
|
||||
u'Scrubs es una divertida comedia'
|
||||
)
|
||||
)
|
||||
|
||||
def test_multilanguage_selection(self):
|
||||
"""Check selected language is used
|
||||
"""
|
||||
class SelectEnglishUI(tvdb_ui.BaseUI):
|
||||
def selectSeries(self, allSeries):
|
||||
return [x for x in allSeries if x['language'] == "en"][0]
|
||||
|
||||
class SelectItalianUI(tvdb_ui.BaseUI):
|
||||
def selectSeries(self, allSeries):
|
||||
return [x for x in allSeries if x['language'] == "it"][0]
|
||||
|
||||
t_en = tvdb_api.Tvdb(
|
||||
cache=True,
|
||||
custom_ui = SelectEnglishUI,
|
||||
language = "en")
|
||||
t_it = tvdb_api.Tvdb(
|
||||
cache=True,
|
||||
custom_ui = SelectItalianUI,
|
||||
language = "it")
|
||||
|
||||
self.assertEquals(
|
||||
t_en['dexter'][1][2]['episodename'], "Crocodile"
|
||||
)
|
||||
self.assertEquals(
|
||||
t_it['dexter'][1][2]['episodename'], "Lacrime di coccodrillo"
|
||||
)
|
||||
|
||||
|
||||
class test_tvdb_unicode(unittest.TestCase):
|
||||
def test_search_in_chinese(self):
|
||||
"""Check searching for show with language=zh returns Chinese seriesname
|
||||
"""
|
||||
t = tvdb_api.Tvdb(cache = True, language = "zh")
|
||||
show = t[u'T\xecnh Ng\u01b0\u1eddi Hi\u1ec7n \u0110\u1ea1i']
|
||||
self.assertEquals(
|
||||
type(show),
|
||||
tvdb_api.Show
|
||||
)
|
||||
|
||||
self.assertEquals(
|
||||
show['seriesname'],
|
||||
u'T\xecnh Ng\u01b0\u1eddi Hi\u1ec7n \u0110\u1ea1i'
|
||||
)
|
||||
|
||||
def test_search_in_all_languages(self):
|
||||
"""Check search_all_languages returns Chinese show, with language=en
|
||||
"""
|
||||
t = tvdb_api.Tvdb(cache = True, search_all_languages = True, language="en")
|
||||
show = t[u'T\xecnh Ng\u01b0\u1eddi Hi\u1ec7n \u0110\u1ea1i']
|
||||
self.assertEquals(
|
||||
type(show),
|
||||
tvdb_api.Show
|
||||
)
|
||||
|
||||
self.assertEquals(
|
||||
show['seriesname'],
|
||||
u'Virtues Of Harmony II'
|
||||
)
|
||||
|
||||
class test_tvdb_banners(unittest.TestCase):
|
||||
# Used to store the cached instance of Tvdb()
|
||||
t = None
|
||||
|
||||
def setUp(self):
|
||||
if self.t is None:
|
||||
self.__class__.t = tvdb_api.Tvdb(cache = True, banners = True)
|
||||
|
||||
def test_have_banners(self):
|
||||
"""Check banners at least one banner is found
|
||||
"""
|
||||
self.assertEquals(
|
||||
len(self.t['scrubs']['_banners']) > 0,
|
||||
True
|
||||
)
|
||||
|
||||
def test_banner_url(self):
|
||||
"""Checks banner URLs start with http://
|
||||
"""
|
||||
for banner_type, banner_data in self.t['scrubs']['_banners'].items():
|
||||
for res, res_data in banner_data.items():
|
||||
for bid, banner_info in res_data.items():
|
||||
self.assertEquals(
|
||||
banner_info['_bannerpath'].startswith("http://"),
|
||||
True
|
||||
)
|
||||
|
||||
def test_episode_image(self):
|
||||
"""Checks episode 'filename' image is fully qualified URL
|
||||
"""
|
||||
self.assertEquals(
|
||||
self.t['scrubs'][1][1]['filename'].startswith("http://"),
|
||||
True
|
||||
)
|
||||
|
||||
def test_show_artwork(self):
|
||||
"""Checks various image URLs within season data are fully qualified
|
||||
"""
|
||||
for key in ['banner', 'fanart', 'poster']:
|
||||
self.assertEquals(
|
||||
self.t['scrubs'][key].startswith("http://"),
|
||||
True
|
||||
)
|
||||
|
||||
class test_tvdb_actors(unittest.TestCase):
|
||||
t = None
|
||||
def setUp(self):
|
||||
if self.t is None:
|
||||
self.__class__.t = tvdb_api.Tvdb(cache = True, actors = True)
|
||||
|
||||
def test_actors_is_correct_datatype(self):
|
||||
"""Check show/_actors key exists and is correct type"""
|
||||
self.assertTrue(
|
||||
isinstance(
|
||||
self.t['scrubs']['_actors'],
|
||||
tvdb_api.Actors
|
||||
)
|
||||
)
|
||||
|
||||
def test_actors_has_actor(self):
|
||||
"""Check show has at least one Actor
|
||||
"""
|
||||
self.assertTrue(
|
||||
isinstance(
|
||||
self.t['scrubs']['_actors'][0],
|
||||
tvdb_api.Actor
|
||||
)
|
||||
)
|
||||
|
||||
def test_actor_has_name(self):
|
||||
"""Check first actor has a name"""
|
||||
self.assertEquals(
|
||||
self.t['scrubs']['_actors'][0]['name'],
|
||||
"Zach Braff"
|
||||
)
|
||||
|
||||
def test_actor_image_corrected(self):
|
||||
"""Check image URL is fully qualified
|
||||
"""
|
||||
for actor in self.t['scrubs']['_actors']:
|
||||
if actor['image'] is not None:
|
||||
# Actor's image can be None, it displays as the placeholder
|
||||
# image on thetvdb.com
|
||||
self.assertTrue(
|
||||
actor['image'].startswith("http://")
|
||||
)
|
||||
|
||||
class test_tvdb_doctest(unittest.TestCase):
|
||||
# Used to store the cached instance of Tvdb()
|
||||
t = None
|
||||
|
||||
def setUp(self):
|
||||
if self.t is None:
|
||||
self.__class__.t = tvdb_api.Tvdb(cache = True, banners = False)
|
||||
|
||||
def test_doctest(self):
|
||||
"""Check docstring examples works"""
|
||||
import doctest
|
||||
doctest.testmod(tvdb_api)
|
||||
|
||||
|
||||
class test_tvdb_custom_caching(unittest.TestCase):
|
||||
def test_true_false_string(self):
|
||||
"""Tests setting cache to True/False/string
|
||||
|
||||
Basic tests, only checking for errors
|
||||
"""
|
||||
|
||||
tvdb_api.Tvdb(cache = True)
|
||||
tvdb_api.Tvdb(cache = False)
|
||||
tvdb_api.Tvdb(cache = "/tmp")
|
||||
|
||||
def test_invalid_cache_option(self):
|
||||
"""Tests setting cache to invalid value
|
||||
"""
|
||||
|
||||
try:
|
||||
tvdb_api.Tvdb(cache = 2.3)
|
||||
except ValueError:
|
||||
pass
|
||||
else:
|
||||
self.fail("Expected ValueError from setting cache to float")
|
||||
|
||||
def test_custom_urlopener(self):
|
||||
class UsedCustomOpener(Exception):
|
||||
pass
|
||||
|
||||
import urllib2
|
||||
class TestOpener(urllib2.BaseHandler):
|
||||
def default_open(self, request):
|
||||
print request.get_method()
|
||||
raise UsedCustomOpener("Something")
|
||||
|
||||
custom_opener = urllib2.build_opener(TestOpener())
|
||||
t = tvdb_api.Tvdb(cache = custom_opener)
|
||||
try:
|
||||
t['scrubs']
|
||||
except UsedCustomOpener:
|
||||
pass
|
||||
else:
|
||||
self.fail("Did not use custom opener")
|
||||
|
||||
class test_tvdb_by_id(unittest.TestCase):
|
||||
t = None
|
||||
def setUp(self):
|
||||
if self.t is None:
|
||||
self.__class__.t = tvdb_api.Tvdb(cache = True, actors = True)
|
||||
|
||||
def test_actors_is_correct_datatype(self):
|
||||
"""Check show/_actors key exists and is correct type"""
|
||||
self.assertEquals(
|
||||
self.t[76156]['seriesname'],
|
||||
'Scrubs'
|
||||
)
|
||||
|
||||
|
||||
class test_tvdb_zip(unittest.TestCase):
|
||||
# Used to store the cached instance of Tvdb()
|
||||
t = None
|
||||
|
||||
def setUp(self):
|
||||
if self.t is None:
|
||||
self.__class__.t = tvdb_api.Tvdb(cache = True, useZip = True)
|
||||
|
||||
def test_get_series_from_zip(self):
|
||||
"""
|
||||
"""
|
||||
self.assertEquals(self.t['scrubs'][1][4]['episodename'], 'My Old Lady')
|
||||
self.assertEquals(self.t['sCruBs']['seriesname'], 'Scrubs')
|
||||
|
||||
def test_spaces_from_zip(self):
|
||||
"""Checks shownames with spaces
|
||||
"""
|
||||
self.assertEquals(self.t['My Name Is Earl']['seriesname'], 'My Name Is Earl')
|
||||
self.assertEquals(self.t['My Name Is Earl'][1][4]['episodename'], 'Faked His Own Death')
|
||||
|
||||
|
||||
class test_tvdb_show_ordering(unittest.TestCase):
|
||||
# Used to store the cached instance of Tvdb()
|
||||
t_dvd = None
|
||||
t_air = None
|
||||
|
||||
def setUp(self):
|
||||
if self.t_dvd is None:
|
||||
self.t_dvd = tvdb_api.Tvdb(cache = True, useZip = True, dvdorder=True)
|
||||
|
||||
if self.t_air is None:
|
||||
self.t_air = tvdb_api.Tvdb(cache = True, useZip = True)
|
||||
|
||||
def test_ordering(self):
|
||||
"""Test Tvdb.search method
|
||||
"""
|
||||
self.assertEquals(u'The Train Job', self.t_air['Firefly'][1][1]['episodename'])
|
||||
self.assertEquals(u'Serenity', self.t_dvd['Firefly'][1][1]['episodename'])
|
||||
|
||||
self.assertEquals(u'The Cat & the Claw (Part 1)', self.t_air['Batman The Animated Series'][1][1]['episodename'])
|
||||
self.assertEquals(u'On Leather Wings', self.t_dvd['Batman The Animated Series'][1][1]['episodename'])
|
||||
|
||||
class test_tvdb_show_search(unittest.TestCase):
|
||||
# Used to store the cached instance of Tvdb()
|
||||
t = None
|
||||
|
||||
def setUp(self):
|
||||
if self.t is None:
|
||||
self.__class__.t = tvdb_api.Tvdb(cache = True, useZip = True)
|
||||
|
||||
def test_search(self):
|
||||
"""Test Tvdb.search method
|
||||
"""
|
||||
results = self.t.search("my name is earl")
|
||||
all_ids = [x['seriesid'] for x in results]
|
||||
self.assertTrue('75397' in all_ids)
|
||||
|
||||
|
||||
class test_tvdb_alt_names(unittest.TestCase):
|
||||
t = None
|
||||
def setUp(self):
|
||||
if self.t is None:
|
||||
self.__class__.t = tvdb_api.Tvdb(cache = True, actors = True)
|
||||
|
||||
def test_1(self):
|
||||
"""Tests basic access of series name alias
|
||||
"""
|
||||
results = self.t.search("Don't Trust the B---- in Apartment 23")
|
||||
series = results[0]
|
||||
self.assertTrue(
|
||||
'Apartment 23' in series['aliasnames']
|
||||
)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
runner = unittest.TextTestRunner(verbosity = 2)
|
||||
unittest.main(testRunner = runner)
|
@ -1,9 +0,0 @@
|
||||
Original Author:
|
||||
------------
|
||||
* Christian Kreutzer
|
||||
|
||||
Contributors
|
||||
------------
|
||||
* topdeck (http://bitbucket.org/topdeck)
|
||||
* samueltardieu (http://bitbucket.org/samueltardieu)
|
||||
* chevox (https://bitbucket.org/chexov)
|
@ -1,26 +0,0 @@
|
||||
Copyright (c) 2009, Christian Kreutzer
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the author of this software nor the name of
|
||||
contributors to this software may be used to endorse or promote products
|
||||
derived from this software without specific prior written consent.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
@ -1,29 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import os
|
||||
|
||||
from distutils.core import setup
|
||||
from tvrage import __version__, __author__, __license__
|
||||
|
||||
setup(name='python-tvrage',
|
||||
description='python client for the tvrage.com XML API',
|
||||
long_description = file(
|
||||
os.path.join(os.path.dirname(__file__),'README.rst')).read(),
|
||||
license=__license__,
|
||||
version=__version__,
|
||||
author=__author__,
|
||||
author_email='herr.kreutzer@gmail.com',
|
||||
# url='http://bitbucket.org/ckreutzer/python-tvrage/',
|
||||
url='https://github.com/ckreutzer/python-tvrage',
|
||||
packages=['tvrage'],
|
||||
install_requires = ["BeautifulSoup"],
|
||||
classifiers = [
|
||||
'Development Status :: 4 - Beta',
|
||||
'Intended Audience :: Developers',
|
||||
'License :: OSI Approved :: BSD License',
|
||||
'Topic :: Software Development :: Libraries :: Python Modules',
|
||||
'Programming Language :: Python',
|
||||
'Operating System :: OS Independent'
|
||||
]
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user