gdcvault: implement login
* since there is a limited number of usable concurrent sessions we force a logout on exit. Signed-off-by: François Revol <revol@free.fr>
This commit is contained in:
parent
f6b2911511
commit
8a07b7a9ce
3 changed files with 80 additions and 6 deletions
|
|
@ -22,8 +22,9 @@
|
|||
from __future__ import with_statement
|
||||
|
||||
from weboob.capabilities.video import ICapVideo, BaseVideo
|
||||
from weboob.tools.backend import BaseBackend
|
||||
from weboob.tools.backend import BaseBackend, BackendConfig
|
||||
from weboob.capabilities.collection import ICapCollection, CollectionNotFound
|
||||
from weboob.tools.value import Value, ValueBackendPassword
|
||||
|
||||
from .browser import GDCVaultBrowser
|
||||
from .video import GDCVaultVideo
|
||||
|
|
@ -40,6 +41,24 @@ class GDCVaultBackend(BaseBackend, ICapVideo, ICapCollection):
|
|||
DESCRIPTION = 'Game Developers Conferences Vault video streaming website'
|
||||
LICENSE = 'AGPLv3+'
|
||||
BROWSER = GDCVaultBrowser
|
||||
CONFIG = BackendConfig(Value('username', label='Username', default=''),
|
||||
ValueBackendPassword('password', label='Password', default=''))
|
||||
|
||||
def create_default_browser(self):
|
||||
username = self.config['username'].get()
|
||||
if len(username) > 0:
|
||||
password = self.config['password'].get()
|
||||
else:
|
||||
password = None
|
||||
return self.create_browser(username, password)
|
||||
|
||||
def deinit(self):
|
||||
# don't need to logout if the browser hasn't been used.
|
||||
if not self._browser:
|
||||
return
|
||||
|
||||
with self.browser:
|
||||
self.browser.close_session()
|
||||
|
||||
def get_video(self, _id):
|
||||
with self.browser:
|
||||
|
|
|
|||
|
|
@ -18,11 +18,13 @@
|
|||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from weboob.tools.browser import BaseBrowser
|
||||
import urllib
|
||||
|
||||
from weboob.tools.browser import BaseBrowser, BrowserIncorrectPassword, BrowserUnavailable
|
||||
from weboob.tools.browser.decorators import id2url
|
||||
|
||||
#from .pages.index import IndexPage
|
||||
from .pages import VideoPage
|
||||
from .pages import VideoPage, IndexPage
|
||||
from .video import GDCVaultVideo
|
||||
|
||||
|
||||
|
|
@ -31,13 +33,56 @@ __all__ = ['GDCVaultBrowser']
|
|||
|
||||
class GDCVaultBrowser(BaseBrowser):
|
||||
DOMAIN = 'gdcvault.com'
|
||||
ENCODING = None
|
||||
ENCODING = 'utf-8'
|
||||
PAGES = {r'http://[w\.]*gdcvault.com/play/(?P<id>[\d]+)/?.*': VideoPage,
|
||||
r'http://[w\.]*gdcvault.com/': IndexPage,
|
||||
}
|
||||
|
||||
def is_logged(self):
|
||||
if self.password is None:
|
||||
return True
|
||||
|
||||
if not self.page:
|
||||
return False
|
||||
|
||||
obj = self.parser.select(self.page.document.getroot(), 'h3[id=welcome_user_name]', 1)
|
||||
if obj is None:
|
||||
return False
|
||||
|
||||
return obj.attrib.get('class','') != "hidden"
|
||||
|
||||
def login(self):
|
||||
if self.password is None:
|
||||
return
|
||||
|
||||
params = {'remember_me': 0,
|
||||
'email': self.username,
|
||||
'password': self.password,
|
||||
}
|
||||
|
||||
data = self.readurl('http://gdcvault.com/api/login.php',
|
||||
urllib.urlencode(params))
|
||||
# data is returned as JSON, not sure yet if it's useful
|
||||
|
||||
print data
|
||||
if data is None:
|
||||
raise BrowserBanned('Too many open sessions?')
|
||||
|
||||
self.location('/', no_login=True)
|
||||
|
||||
if not self.is_logged():
|
||||
raise BrowserIncorrectPassword()
|
||||
|
||||
def close_session(self):
|
||||
print "logging out..."
|
||||
self.openurl('/logout', '')
|
||||
|
||||
@id2url(GDCVaultVideo.id2url)
|
||||
def get_video(self, url, video=None):
|
||||
self.location(url)
|
||||
# redirects to /login means the video is not public
|
||||
if not isinstance(self.page, VideoPage):
|
||||
raise BrowserUnavailable('Requires account')
|
||||
return self.page.get_video(video)
|
||||
|
||||
# def search_videos(self, pattern, sortby):
|
||||
|
|
|
|||
|
|
@ -35,9 +35,19 @@ from .video import GDCVaultVideo
|
|||
#import lxml.etree
|
||||
|
||||
|
||||
__all__ = ['VideoPage']
|
||||
__all__ = ['IndexPage', 'VideoPage']
|
||||
|
||||
|
||||
class IndexPage(BasePage):
|
||||
def iter_videos(self):
|
||||
for a in self.parser.select(self.document.getroot(), 'section.conference ul.media_items li.featured a.session_item'):
|
||||
print a
|
||||
#m = re.match('id-(\d+)', a.attrib.get('class', ''))
|
||||
#if not m:
|
||||
# continue
|
||||
# FIXME
|
||||
yield None
|
||||
|
||||
class VideoPage(BasePage):
|
||||
def get_video(self, video=None):
|
||||
if video is None:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue