public async Task <List <Media> > GetMediaList(long?collectionId, long?seriesId, string sort, int?offset, int?limit) { try { var session = _applicationState.GetSession(); if (session.GetId() == null) { var sessionId = await CrunchyrollSessionHandler.GetSessionId(); session.SetId(sessionId); } var req = new ListMediaRequest(collectionId, seriesId, sort, offset, limit); var response = await Run(req); var data = response.ResponseElement.Element("data"); var items = data.Elements("item"); return(items.Select(Media.FromXml).ToList()); } catch { } return(new List <Media>()); }
public async void StartSession() { try { var session = _applicationState.GetSession(); if (session.GetId() == null) { var sessionId = await CrunchyrollSessionHandler.GetSessionId(); session.SetId(sessionId); } var req = new StartSessionRequest(_clientInformation, session.GetAuth(), null); var response = await RunSessionless(req, _clientInformation); var data = response.ResponseElement.Element("data"); session.SetId(data.Element("session_id").Value); } catch (Exception exc) { } }
public async Task <VideoStreamData> GetMediaStream(int mediaId) { var streamData = new VideoStreamData(); try { var session = _applicationState.GetSession(); if (session.GetId() == null) { var sessionId = await CrunchyrollSessionHandler.GetSessionId(); session.SetId(sessionId); } var req = new InfoRequest(mediaId); var response = await Run(req); var data = response.ResponseElement.Element("data"); var infoData = data.Element("stream_data"); streamData = VideoStreamData.FromXml(infoData); } catch { } return(streamData); }
public async Task <List <Series> > GetSeriesList(string mediatype, string filter, int offset, int limit) { try { var session = _applicationState.GetSession(); if (session.GetId() == null) { var sessionId = await CrunchyrollSessionHandler.GetSessionId(); session.SetId(sessionId); } var req = new ListSeriesRequest(mediatype, filter, offset, limit); var response = await Run(req); var data = response.ResponseElement.Element("data"); var items = data.Elements("item"); return(items.Select(Series.FromXml).ToList()); } catch { } return(new List <Series>()); }
public async Task <bool> Login(string username, string password) { try { var session = _applicationState.GetSession(); if (session.GetId() == null) { var sessionId = await CrunchyrollSessionHandler.GetSessionId(); session.SetId(sessionId); } var loginReq = new LoginRequest(username, password); var response = await Run(loginReq); var data = response.ResponseElement; var xElement = data.Element("data"); if (xElement != null) { var userElm = xElement.Element("user"); if (userElm != null) { var user = new User(userElm.Element("username").Value, userElm.Element("email").Value, userElm.Element("premium").Value); session.SetUser(user); } _applicationState.SetLoggedInUser(session.GetUser()); var authElm = xElement.Element("auth"); if (authElm != null) { session.SetAuth(authElm.Value); _applicationState.SetAuth(authElm.Value); } } return(true); } catch { return(false); } }