-
Notifications
You must be signed in to change notification settings - Fork 25
/
sovok_api.py
91 lines (75 loc) · 2.85 KB
/
sovok_api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# Dreambox Enigma2 KartinaTV/RodnoeTV player! (by technic)
#
# Copyright (c) 2010 Alex Maystrenko <alexeytech@gmail.com>
# web: http://techhost.dlinkddns.com/
#
# This is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2, or (at your option) any later
# version.
from abstract_api import MODE_STREAM, AbstractAPI, AbstractStream
import cookielib, urllib, urllib2 #TODO: optimize imports
from xml.etree.cElementTree import fromstring
from datetime import datetime
from . import tdSec, secTd, setSyncTime, syncTime, Bouquet, EpgEntry, Channel, unescapeEntities, Timezone, APIException, SettEntry
from kartina_api import Ktv as Kartina
#TODO: GLOBAL: add private! Get values by properties.
class Ktv(Kartina):
iProvider = "sovoktv"
iName = "SovokTV"
iTitle = "SovokTV"
NEXT_API = None
MODE = MODE_STREAM
NUMBER_PASS = False
site = "http://api.sovok.tv"
apipath = "/v2.0"
HAS_PIN = True
locked_cids = [163, 171, 172, 119]
def authorize(self):
self.trace("Authorization started")
self.trace("username = %s" % self.username)
self.cookiejar.clear()
params = urllib.urlencode({"login" : self.username,
"pass" : self.password,
"settings" : "all"})
reply = self.opener.open(self.site+self.apipath+'/xml/login?', params).read()
#checking cookies
cookies = list(self.cookiejar)
cookiesdict = {}
hasSSID = False
deleted = False
reply = fromstring(reply)
if reply.find("error"):
raise APIException(reply.find('error').findtext('message'))
for cookie in cookies:
cookiesdict[cookie.name] = cookie.value
if (cookie.name.find('SSID') != -1):
hasSSID = True
if (cookie.value.find('deleted') != -1):
deleted = True
if (not hasSSID):
raise APIException(self.username+": Authorization of user failed!")
if (deleted):
raise APIException(self.username+": Wrong authorization request")
try:
self.packet_expire = datetime.fromtimestamp(int(reply.find('account').findtext('packet_expire')))
except:
self.trace("Could not read packet_expire from reply: %s" % reply)
self.trace("Authorization returned: %s" % urllib.urlencode(cookiesdict))
self.trace("Packet expire: %s" % self.packet_expire)
self.SID = True
def setTimeShift(self, timeShift):
pass
def getSettings(self):
try:
reply = self.opener.open(self.site+self.apipath+'/xml/settings').read()
self.trace("settings: " + reply)
reply = fromstring(reply)
streamer = reply.find("settings").findtext("streamer")
return {"streamer": SettEntry("streamer", streamer, ["1", "2", "3"])}
except:
raise APIException("Error getting settings from the server")
def pushSettings(self, sett):
for x in sett:
if x[0] == "streamer":
self.opener.open(self.site+self.apipath+"/xml/settings_set?streamer="+x[1]).read()