Beispiel #1
0
        public async Task AddMediaToSession(MySocket socket, MediaV1 media)
        {
            var sessionId      = socket.SessionId;
            var updatedSession = await _db.AddMediaToSessionAsync(media.ToModel(), sessionId);

            await _sender.clientUpdateQueue(updatedSession.ToContract().Queue, _myContext.GetSocketsInSession(sessionId));
        }
Beispiel #2
0
        public async Task <List <MediaV1> > searchPodcasts(string query, int page)
        {
            if (_ready)
            {
                HttpResponseMessage response;
                string  responseBody;
                dynamic json;
                try
                {
                    var encodedQuery = System.Net.WebUtility.UrlEncode(query);
                    var request      = new HttpRequestMessage()
                    {
                        RequestUri = new Uri(BASE_AUDIO_PATH + API_PATH + EPISODE_QUERY_PATH + encodedQuery + "?size=5&from=" + (5 * page).ToString()),
                        Method     = HttpMethod.Get
                    };
                    request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", _audioToken);

                    response = await _client.SendAsync(request);

                    responseBody = await response.Content.ReadAsStringAsync();

                    json = Newtonsoft.Json.JsonConvert.DeserializeObject(responseBody);

                    var mediaResults = new List <MediaV1>();
                    var results      = json.results;
                    foreach (var result in results)
                    {
                        var media = new MediaV1();
                        media.Title       = result.title;
                        media.MP3Source   = result.audio_files[0].mp3;
                        media.ThumbURL    = result.show_image_urls.thumb;
                        media.Description = result.description;
                        media.Show        = result.show_title;
                        mediaResults.Add(media);
                    }

                    return(mediaResults);
                }
                catch (Exception e)
                {
                    // TODO: error search response on client
                    return(new List <MediaV1>());
                }
            }
            else
            {
                throw new RadioException("Tried searching when http client wasn't ready");
            }
        }