def testDownloadAndCacheUrl(self): danishaddons.init([tempfile.gettempdir()]) first = danishaddons.web.downloadAndCacheUrl(URL, os.path.join(danishaddons.ADDON_DATA_PATH, 'unittestcache.tmp'), 1) time.sleep(1) second = danishaddons.web.downloadAndCacheUrl(URL, os.path.join(danishaddons.ADDON_DATA_PATH, 'unittestcache.tmp'), 1) self.assertEquals(first, second, msg = 'Content is different, perhaps it is not cached?')
def test00Init(self): expectedAddonId = 'script.module.danishaddons' self.assertEqual(None, danishaddons.ADDON_ID, msg = 'Expected ADDON_ID to be None before call to init()') danishaddons.init(['.', '12345', '?key1=value1&key2=value2']) self.assertEqual(expectedAddonId, danishaddons.ADDON_ID, msg = 'Got unexpected ADDON_ID') self.assertTrue(isinstance(danishaddons.ADDON, xbmcaddon.Addon), msg = 'Expected instance of xbmcaddon.Addon class') self.assertEqual('/tmp/%s' % expectedAddonId, danishaddons.ADDON_DATA_PATH) self.assertEqual('.', danishaddons.ADDON_PATH) self.assertEqual(12345, danishaddons.ADDON_HANDLE) self.assertEqual({'key1' : 'value1', 'key2' : 'value2'}, danishaddons.ADDON_PARAMS)
danishaddons.web.downloadUrl('http://common-dyn.tv2.dk/crossdomain.xml') # retrieve real playlist playlist = danishaddons.web.downloadUrl('http://common-dyn.tv2.dk/flashplayer/geocheck.php?id=' + m.group(2) + '&file=' + m.group(1)) item = xbmcgui.ListItem(path = playlist) xbmcplugin.setResolvedUrl(danishaddons.ADDON_HANDLE, True, item) def loadJson(): json_path = os.path.join(danishaddons.ADDON_DATA_PATH, 'video.js') json = danishaddons.web.downloadAndCacheUrl(BASE_URL, json_path, 60) # get json part of js file m = re.search('data = (\{.*)\}', json, re.DOTALL) # fixup json parsing with simplejson, ie. replace ' with " json = re.sub(r'\'([\w-]+)\':', r'"\1":', m.group(1)) return simplejson.loads(json) if __name__ == '__main__': danishaddons.init(sys.argv) if danishaddons.ADDON_PARAMS.has_key('key'): showCategory(danishaddons.ADDON_PARAMS['key']) elif danishaddons.ADDON_PARAMS.has_key('id'): playVideo(danishaddons.ADDON_PARAMS['id']) else: showOverview()
def setUp(self): danishaddons.init([".", "12345", ""]) xbmcplugin.items = list()