Ejemplo n.º 1
0
        public ClientCapabilities GetCapabilities(string id)
        {
            using (WriteLock.Read())
            {
                using (var connection = CreateConnection(true))
                {
                    var statementTexts = new List <string>();
                    statementTexts.Add("Select Capabilities from Devices where Id=@Id");

                    return(connection.RunInTransaction(db =>
                    {
                        var statements = PrepareAllSafe(db, statementTexts).ToList();

                        using (var statement = statements[0])
                        {
                            statement.TryBind("@Id", id);

                            foreach (var row in statement.ExecuteQuery())
                            {
                                if (row[0].SQLiteType != SQLiteType.Null)
                                {
                                    return _json.DeserializeFromString <ClientCapabilities>(row.GetString(0));
                                }
                            }
                        }

                        return null;
                    }, ReadTransactionMode));
                }
            }
        }
Ejemplo n.º 2
0
        private async Task UpdateUserPolicy(User user, UserPolicy userPolicy, bool fireEvent)
        {
            // The xml serializer will output differently if the type is not exact
            if (userPolicy.GetType() != typeof(UserPolicy))
            {
                var json = _jsonSerializer.SerializeToString(userPolicy);
                userPolicy = _jsonSerializer.DeserializeFromString <UserPolicy>(json);
            }

            var path = GetPolifyFilePath(user);

            Directory.CreateDirectory(Path.GetDirectoryName(path));

            lock (_policySyncLock)
            {
                _xmlSerializer.SerializeToFile(userPolicy, path);
                user.Policy = userPolicy;
            }

            user.Configuration.IsAdministrator        = user.Policy.IsAdministrator;
            user.Configuration.EnableLiveTvManagement = user.Policy.EnableLiveTvManagement;
            user.Configuration.EnableLiveTvAccess     = user.Policy.EnableLiveTvAccess;
            user.Configuration.EnableMediaPlayback    = user.Policy.EnableMediaPlayback;
            user.Configuration.EnableContentDeletion  = user.Policy.EnableContentDeletion;

            await UpdateConfiguration(user, user.Configuration, true).ConfigureAwait(false);
        }
Ejemplo n.º 3
0
        private void UpdateUserPolicy(User user, UserPolicy userPolicy, bool fireEvent)
        {
            // The xml serializer will output differently if the type is not exact
            if (userPolicy.GetType() != typeof(UserPolicy))
            {
                var json = _jsonSerializer.SerializeToString(userPolicy);
                userPolicy = _jsonSerializer.DeserializeFromString <UserPolicy>(json);
            }

            var path = GetPolicyFilePath(user);

            Directory.CreateDirectory(Path.GetDirectoryName(path));

            lock (_policySyncLock)
            {
                _xmlSerializer.SerializeToFile(userPolicy, path);
                user.Policy = userPolicy;
            }

            if (fireEvent)
            {
                UserPolicyUpdated?.Invoke(this, new GenericEventArgs <User> {
                    Argument = user
                });
            }
        }
Ejemplo n.º 4
0
        private static async Task <VeraNetworkDeviceModel> LocateVeraDeviceAsync()
        {
            var jSon = string.Empty;

            try
            {
                jSon =
                    await PluginHttpClient.GetStream(BaseLocatorUrl);
            }
            catch { }
            return(JSonSerializer.DeserializeFromString <VeraNetworkDeviceModel>(jSon));
        }
Ejemplo n.º 5
0
        private void ReportPlaybackStart(WebSocketMessageInfo message)
        {
            _logger.Debug("Received ReportPlaybackStart message");

            var session = GetSessionFromMessage(message);

            if (session != null && session.UserId.HasValue)
            {
                var info = _json.DeserializeFromString <PlaybackStartInfo>(message.Data);

                info.SessionId = session.Id;

                _sessionManager.OnPlaybackStart(info);
            }
        }
Ejemplo n.º 6
0
        private SmartMatchResult GetResultSmartMatch(IResultSet reader)
        {
            var index = 0;

            var result = new SmartMatchResult
            {
                Id = reader.GetGuid(0)
            };

            index++;
            result.ItemName = reader.GetString(index);

            index++;
            result.DisplayName = reader.GetString(index);

            index++;
            result.OrganizerType = (FileOrganizerType)Enum.Parse(typeof(FileOrganizerType), reader.GetString(index), true);

            index++;
            if (!reader.IsDBNull(index))
            {
                result.MatchStrings = _json.DeserializeFromString <List <string> >(reader.GetString(index));
            }

            return(result);
        }
Ejemplo n.º 7
0
        public async Task <ActionResult> SaveTracks(InputTracksSessionForm tracksSessionForm)
        {
            var tracksModel  = jsonSerializer.DeserializeFromString <TracksWizardModel>(tracksSessionForm.TracksJson);
            var sourceTracks = tracksModel.ToTracksWizardModel();
            var text         = jsonTrackGetter.SerializeTracks(sourceTracks);

            var sessionId = Guid.NewGuid();
            await tempSessionService.SaveTempSessionAsync(sessionId, SafeUserId, text).ConfigureAwait(true);

            if (authorizationSettings.UserAuthorized(UserId))
            {
                return(RedirectToAction("GetYaPlaylists", new { sessionId = sessionId }));
            }

            return(RedirectToAction("YandexAuthorize", new { sessionId = sessionId }));
        }
Ejemplo n.º 8
0
        public static async Task <string> UploadImage(Stream ImageData, IJsonSerializer jsonSerializer, HttpClient httpClient)
        {
            StreamContent            imageStream        = new StreamContent(ImageData);
            ByteArrayContent         imageStreamContent = new ByteArrayContent(await imageStream.ReadAsByteArrayAsync());
            MultipartFormDataContent formData           = new MultipartFormDataContent();

            imageStreamContent.Headers.ContentType = MediaTypeHeaderValue.Parse("multipart/form-data");

            formData.Add(imageStreamContent, "file", "poster.png");

            try {
                HttpResponseMessage res = await httpClient.PostAsync(uploadEndpoint, formData);

                string responseContent = await res.Content.ReadAsStringAsync();

                ImageServiceResponse memesterResponse = jsonSerializer.DeserializeFromString <ImageServiceResponse>(responseContent);

                if (res.StatusCode == HttpStatusCode.Created)
                {
                    return(memesterResponse.filePath);
                }
                else
                {
                    throw new Exception($"Status: {res.StatusCode} Server Response: {responseContent}");
                }
            } catch (HttpRequestException e) {
                throw new Exception(e.Message);
            }
        }
        internal async Task <Response.Subject> GetDoubanSubject(string sid,
                                                                CancellationToken cancellationToken)
        {
            _logger.LogInformation("Douban: Trying to get douban subject by " +
                                   "sid: {0}", sid);
            cancellationToken.ThrowIfCancellationRequested();

            if (string.IsNullOrWhiteSpace(sid))
            {
                throw new ArgumentException("sid is empty when getting subject");
            }

            String apikey = _config.ApiKey;
            var    url    = String.Format("http://api.douban.com/v2/movie/subject" +
                                          "/{0}?apikey={1}", sid, apikey);


            String content = await _doubanAccessor.GetResponse(url, cancellationToken);

            var data = _jsonSerializer.DeserializeFromString <Response.Subject>(content);

            _logger.LogInformation("Get douban subject {0} successfully: {1}",
                                   sid, data.Title);
            return(data);
        }
        private SyncUpdateInfo PopulateLibraryInfo(string userId, string lastRequestedDt,
                                                   IReadOnlyCollection <MediaType> filters)
        {
            var startTime = DateTime.UtcNow;

            _logger.LogDebug("Starting PopulateLibraryInfo...");

            var info = new SyncUpdateInfo();

            var userDt = DateTime.Parse(lastRequestedDt, CultureInfo.CurrentCulture, DateTimeStyles.AssumeUniversal);
            var dtl    = (long)userDt.ToUniversalTime().Subtract(new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds;
            var user   = _userManager.GetUserById(Guid.Parse(userId));

            var itemsAdded      = Plugin.Instance.DbRepo.GetItems(dtl, ItemStatus.Added, filters);
            var itemsRemoved    = Plugin.Instance.DbRepo.GetItems(dtl, ItemStatus.Removed, filters);
            var itemsUpdated    = Plugin.Instance.DbRepo.GetItems(dtl, ItemStatus.Updated, filters);
            var userDataChanged = Plugin.Instance.DbRepo.GetUserInfos(dtl, userId, filters);

            info.ItemsAdded      = GetAddedOrUpdatedItems(user, itemsAdded);
            info.ItemsRemoved    = itemsRemoved.Select(id => id.ToString("N")).ToList();
            info.ItemsUpdated    = GetAddedOrUpdatedItems(user, itemsUpdated);
            info.UserDataChanged = userDataChanged.Select(i => _jsonSerializer.DeserializeFromString <UserItemDataDto>(i.JsonData)).ToList();

            _logger.LogInformation("Added: {AddedCount}, Removed: {RemovedCount}, Updated: {UpdatedCount}, Changed User Data: {ChangedUserDataCount}",
                                   info.ItemsAdded.Count, info.ItemsRemoved.Count, info.ItemsUpdated.Count, info.UserDataChanged.Count);
            TimeSpan diffDate = DateTime.UtcNow - startTime;

            _logger.LogInformation("Request Finished Taking {TimeTaken}", diffDate.ToString("c"));

            return(info);
        }
Ejemplo n.º 11
0
        public async Task <IEnumerable <ChannelItemInfo> > GetAllItems(bool direct, CancellationToken cancellationToken)
        {
            if (!RegistrationInfo.Instance.IsRegistered)
            {
                return(GetNonSupporterItems().Items);
            }

            if (direct)
            {
                return(await GetDirectListings(cancellationToken).ConfigureAwait(false));
            }

            var json = await EntryPoint.Instance.GetAndCacheResponse("https://raw.githubusercontent.com/MediaBrowser/MediaBrowser.Channels/master/MediaBrowser.Plugins.Trailers/Listings/listingswithmetadata.txt?v=" + DataVersion,
                                                                     TimeSpan.FromDays(3), cancellationToken);

            var items = _json.DeserializeFromString <List <ChannelItemInfo> >(json);

            if (!Plugin.Instance.Configuration.EnableMovieArchive)
            {
                items = items.Where(i => i.TrailerTypes.Count != 1 || i.TrailerTypes[0] != TrailerType.Archive)
                        .ToList();
            }

            if (Plugin.Instance.Configuration.ExcludeUnIdentifiedContent)
            {
                items = items.Where(i => !string.IsNullOrWhiteSpace(i.GetProviderId(MetadataProviders.Imdb)) || !string.IsNullOrWhiteSpace(i.GetProviderId(MetadataProviders.Tmdb)))
                        .ToList();
            }

            return(items);
        }
Ejemplo n.º 12
0
        private void LoadCachedData()
        {
            var path = CacheFilePath;

            _logger.Info("Loading data from {0}", path);

            try
            {
                lock (_dataFileLock)
                {
                    var encrypted = _fileSystem.ReadAllText(path, Encoding.UTF8);

                    var json = _encryption.DecryptString(encrypted);

                    _data = _json.DeserializeFromString <ConnectData>(json);
                }
            }
            catch (IOException)
            {
                // File isn't there. no biggie
            }
            catch (Exception ex)
            {
                _logger.ErrorException("Error loading data", ex);
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Gets the countries.
        /// </summary>
        /// <returns>IEnumerable{CountryInfo}.</returns>
        public CountryInfo[] GetCountries()
        {
            // ToDo: DeserializeFromStream seems broken in this case
            string jsonCountries = "[{\"Name\":\"AF\",\"DisplayName\":\"Afghanistan\",\"TwoLetterISORegionName\":\"AF\",\"ThreeLetterISORegionName\":\"AFG\"},{\"Name\":\"AL\",\"DisplayName\":\"Albania\",\"TwoLetterISORegionName\":\"AL\",\"ThreeLetterISORegionName\":\"ALB\"},{\"Name\":\"DZ\",\"DisplayName\":\"Algeria\",\"TwoLetterISORegionName\":\"DZ\",\"ThreeLetterISORegionName\":\"DZA\"},{\"Name\":\"AR\",\"DisplayName\":\"Argentina\",\"TwoLetterISORegionName\":\"AR\",\"ThreeLetterISORegionName\":\"ARG\"},{\"Name\":\"AM\",\"DisplayName\":\"Armenia\",\"TwoLetterISORegionName\":\"AM\",\"ThreeLetterISORegionName\":\"ARM\"},{\"Name\":\"AU\",\"DisplayName\":\"Australia\",\"TwoLetterISORegionName\":\"AU\",\"ThreeLetterISORegionName\":\"AUS\"},{\"Name\":\"AT\",\"DisplayName\":\"Austria\",\"TwoLetterISORegionName\":\"AT\",\"ThreeLetterISORegionName\":\"AUT\"},{\"Name\":\"AZ\",\"DisplayName\":\"Azerbaijan\",\"TwoLetterISORegionName\":\"AZ\",\"ThreeLetterISORegionName\":\"AZE\"},{\"Name\":\"BH\",\"DisplayName\":\"Bahrain\",\"TwoLetterISORegionName\":\"BH\",\"ThreeLetterISORegionName\":\"BHR\"},{\"Name\":\"BD\",\"DisplayName\":\"Bangladesh\",\"TwoLetterISORegionName\":\"BD\",\"ThreeLetterISORegionName\":\"BGD\"},{\"Name\":\"BY\",\"DisplayName\":\"Belarus\",\"TwoLetterISORegionName\":\"BY\",\"ThreeLetterISORegionName\":\"BLR\"},{\"Name\":\"BE\",\"DisplayName\":\"Belgium\",\"TwoLetterISORegionName\":\"BE\",\"ThreeLetterISORegionName\":\"BEL\"},{\"Name\":\"BZ\",\"DisplayName\":\"Belize\",\"TwoLetterISORegionName\":\"BZ\",\"ThreeLetterISORegionName\":\"BLZ\"},{\"Name\":\"VE\",\"DisplayName\":\"Bolivarian Republic of Venezuela\",\"TwoLetterISORegionName\":\"VE\",\"ThreeLetterISORegionName\":\"VEN\"},{\"Name\":\"BO\",\"DisplayName\":\"Bolivia\",\"TwoLetterISORegionName\":\"BO\",\"ThreeLetterISORegionName\":\"BOL\"},{\"Name\":\"BA\",\"DisplayName\":\"Bosnia and Herzegovina\",\"TwoLetterISORegionName\":\"BA\",\"ThreeLetterISORegionName\":\"BIH\"},{\"Name\":\"BW\",\"DisplayName\":\"Botswana\",\"TwoLetterISORegionName\":\"BW\",\"ThreeLetterISORegionName\":\"BWA\"},{\"Name\":\"BR\",\"DisplayName\":\"Brazil\",\"TwoLetterISORegionName\":\"BR\",\"ThreeLetterISORegionName\":\"BRA\"},{\"Name\":\"BN\",\"DisplayName\":\"Brunei Darussalam\",\"TwoLetterISORegionName\":\"BN\",\"ThreeLetterISORegionName\":\"BRN\"},{\"Name\":\"BG\",\"DisplayName\":\"Bulgaria\",\"TwoLetterISORegionName\":\"BG\",\"ThreeLetterISORegionName\":\"BGR\"},{\"Name\":\"KH\",\"DisplayName\":\"Cambodia\",\"TwoLetterISORegionName\":\"KH\",\"ThreeLetterISORegionName\":\"KHM\"},{\"Name\":\"CM\",\"DisplayName\":\"Cameroon\",\"TwoLetterISORegionName\":\"CM\",\"ThreeLetterISORegionName\":\"CMR\"},{\"Name\":\"CA\",\"DisplayName\":\"Canada\",\"TwoLetterISORegionName\":\"CA\",\"ThreeLetterISORegionName\":\"CAN\"},{\"Name\":\"029\",\"DisplayName\":\"Caribbean\",\"TwoLetterISORegionName\":\"029\",\"ThreeLetterISORegionName\":\"029\"},{\"Name\":\"CL\",\"DisplayName\":\"Chile\",\"TwoLetterISORegionName\":\"CL\",\"ThreeLetterISORegionName\":\"CHL\"},{\"Name\":\"CO\",\"DisplayName\":\"Colombia\",\"TwoLetterISORegionName\":\"CO\",\"ThreeLetterISORegionName\":\"COL\"},{\"Name\":\"CD\",\"DisplayName\":\"Congo [DRC]\",\"TwoLetterISORegionName\":\"CD\",\"ThreeLetterISORegionName\":\"COD\"},{\"Name\":\"CR\",\"DisplayName\":\"Costa Rica\",\"TwoLetterISORegionName\":\"CR\",\"ThreeLetterISORegionName\":\"CRI\"},{\"Name\":\"HR\",\"DisplayName\":\"Croatia\",\"TwoLetterISORegionName\":\"HR\",\"ThreeLetterISORegionName\":\"HRV\"},{\"Name\":\"CZ\",\"DisplayName\":\"Czech Republic\",\"TwoLetterISORegionName\":\"CZ\",\"ThreeLetterISORegionName\":\"CZE\"},{\"Name\":\"DK\",\"DisplayName\":\"Denmark\",\"TwoLetterISORegionName\":\"DK\",\"ThreeLetterISORegionName\":\"DNK\"},{\"Name\":\"DO\",\"DisplayName\":\"Dominican Republic\",\"TwoLetterISORegionName\":\"DO\",\"ThreeLetterISORegionName\":\"DOM\"},{\"Name\":\"EC\",\"DisplayName\":\"Ecuador\",\"TwoLetterISORegionName\":\"EC\",\"ThreeLetterISORegionName\":\"ECU\"},{\"Name\":\"EG\",\"DisplayName\":\"Egypt\",\"TwoLetterISORegionName\":\"EG\",\"ThreeLetterISORegionName\":\"EGY\"},{\"Name\":\"SV\",\"DisplayName\":\"El Salvador\",\"TwoLetterISORegionName\":\"SV\",\"ThreeLetterISORegionName\":\"SLV\"},{\"Name\":\"ER\",\"DisplayName\":\"Eritrea\",\"TwoLetterISORegionName\":\"ER\",\"ThreeLetterISORegionName\":\"ERI\"},{\"Name\":\"EE\",\"DisplayName\":\"Estonia\",\"TwoLetterISORegionName\":\"EE\",\"ThreeLetterISORegionName\":\"EST\"},{\"Name\":\"ET\",\"DisplayName\":\"Ethiopia\",\"TwoLetterISORegionName\":\"ET\",\"ThreeLetterISORegionName\":\"ETH\"},{\"Name\":\"FO\",\"DisplayName\":\"Faroe Islands\",\"TwoLetterISORegionName\":\"FO\",\"ThreeLetterISORegionName\":\"FRO\"},{\"Name\":\"FI\",\"DisplayName\":\"Finland\",\"TwoLetterISORegionName\":\"FI\",\"ThreeLetterISORegionName\":\"FIN\"},{\"Name\":\"FR\",\"DisplayName\":\"France\",\"TwoLetterISORegionName\":\"FR\",\"ThreeLetterISORegionName\":\"FRA\"},{\"Name\":\"GE\",\"DisplayName\":\"Georgia\",\"TwoLetterISORegionName\":\"GE\",\"ThreeLetterISORegionName\":\"GEO\"},{\"Name\":\"DE\",\"DisplayName\":\"Germany\",\"TwoLetterISORegionName\":\"DE\",\"ThreeLetterISORegionName\":\"DEU\"},{\"Name\":\"GR\",\"DisplayName\":\"Greece\",\"TwoLetterISORegionName\":\"GR\",\"ThreeLetterISORegionName\":\"GRC\"},{\"Name\":\"GL\",\"DisplayName\":\"Greenland\",\"TwoLetterISORegionName\":\"GL\",\"ThreeLetterISORegionName\":\"GRL\"},{\"Name\":\"GT\",\"DisplayName\":\"Guatemala\",\"TwoLetterISORegionName\":\"GT\",\"ThreeLetterISORegionName\":\"GTM\"},{\"Name\":\"HT\",\"DisplayName\":\"Haiti\",\"TwoLetterISORegionName\":\"HT\",\"ThreeLetterISORegionName\":\"HTI\"},{\"Name\":\"HN\",\"DisplayName\":\"Honduras\",\"TwoLetterISORegionName\":\"HN\",\"ThreeLetterISORegionName\":\"HND\"},{\"Name\":\"HK\",\"DisplayName\":\"Hong Kong S.A.R.\",\"TwoLetterISORegionName\":\"HK\",\"ThreeLetterISORegionName\":\"HKG\"},{\"Name\":\"HU\",\"DisplayName\":\"Hungary\",\"TwoLetterISORegionName\":\"HU\",\"ThreeLetterISORegionName\":\"HUN\"},{\"Name\":\"IS\",\"DisplayName\":\"Iceland\",\"TwoLetterISORegionName\":\"IS\",\"ThreeLetterISORegionName\":\"ISL\"},{\"Name\":\"IN\",\"DisplayName\":\"India\",\"TwoLetterISORegionName\":\"IN\",\"ThreeLetterISORegionName\":\"IND\"},{\"Name\":\"ID\",\"DisplayName\":\"Indonesia\",\"TwoLetterISORegionName\":\"ID\",\"ThreeLetterISORegionName\":\"IDN\"},{\"Name\":\"IR\",\"DisplayName\":\"Iran\",\"TwoLetterISORegionName\":\"IR\",\"ThreeLetterISORegionName\":\"IRN\"},{\"Name\":\"IQ\",\"DisplayName\":\"Iraq\",\"TwoLetterISORegionName\":\"IQ\",\"ThreeLetterISORegionName\":\"IRQ\"},{\"Name\":\"IE\",\"DisplayName\":\"Ireland\",\"TwoLetterISORegionName\":\"IE\",\"ThreeLetterISORegionName\":\"IRL\"},{\"Name\":\"PK\",\"DisplayName\":\"Islamic Republic of Pakistan\",\"TwoLetterISORegionName\":\"PK\",\"ThreeLetterISORegionName\":\"PAK\"},{\"Name\":\"IL\",\"DisplayName\":\"Israel\",\"TwoLetterISORegionName\":\"IL\",\"ThreeLetterISORegionName\":\"ISR\"},{\"Name\":\"IT\",\"DisplayName\":\"Italy\",\"TwoLetterISORegionName\":\"IT\",\"ThreeLetterISORegionName\":\"ITA\"},{\"Name\":\"CI\",\"DisplayName\":\"Ivory Coast\",\"TwoLetterISORegionName\":\"CI\",\"ThreeLetterISORegionName\":\"CIV\"},{\"Name\":\"JM\",\"DisplayName\":\"Jamaica\",\"TwoLetterISORegionName\":\"JM\",\"ThreeLetterISORegionName\":\"JAM\"},{\"Name\":\"JP\",\"DisplayName\":\"Japan\",\"TwoLetterISORegionName\":\"JP\",\"ThreeLetterISORegionName\":\"JPN\"},{\"Name\":\"JO\",\"DisplayName\":\"Jordan\",\"TwoLetterISORegionName\":\"JO\",\"ThreeLetterISORegionName\":\"JOR\"},{\"Name\":\"KZ\",\"DisplayName\":\"Kazakhstan\",\"TwoLetterISORegionName\":\"KZ\",\"ThreeLetterISORegionName\":\"KAZ\"},{\"Name\":\"KE\",\"DisplayName\":\"Kenya\",\"TwoLetterISORegionName\":\"KE\",\"ThreeLetterISORegionName\":\"KEN\"},{\"Name\":\"KR\",\"DisplayName\":\"Korea\",\"TwoLetterISORegionName\":\"KR\",\"ThreeLetterISORegionName\":\"KOR\"},{\"Name\":\"KW\",\"DisplayName\":\"Kuwait\",\"TwoLetterISORegionName\":\"KW\",\"ThreeLetterISORegionName\":\"KWT\"},{\"Name\":\"KG\",\"DisplayName\":\"Kyrgyzstan\",\"TwoLetterISORegionName\":\"KG\",\"ThreeLetterISORegionName\":\"KGZ\"},{\"Name\":\"LA\",\"DisplayName\":\"Lao P.D.R.\",\"TwoLetterISORegionName\":\"LA\",\"ThreeLetterISORegionName\":\"LAO\"},{\"Name\":\"419\",\"DisplayName\":\"Latin America\",\"TwoLetterISORegionName\":\"419\",\"ThreeLetterISORegionName\":\"419\"},{\"Name\":\"LV\",\"DisplayName\":\"Latvia\",\"TwoLetterISORegionName\":\"LV\",\"ThreeLetterISORegionName\":\"LVA\"},{\"Name\":\"LB\",\"DisplayName\":\"Lebanon\",\"TwoLetterISORegionName\":\"LB\",\"ThreeLetterISORegionName\":\"LBN\"},{\"Name\":\"LY\",\"DisplayName\":\"Libya\",\"TwoLetterISORegionName\":\"LY\",\"ThreeLetterISORegionName\":\"LBY\"},{\"Name\":\"LI\",\"DisplayName\":\"Liechtenstein\",\"TwoLetterISORegionName\":\"LI\",\"ThreeLetterISORegionName\":\"LIE\"},{\"Name\":\"LT\",\"DisplayName\":\"Lithuania\",\"TwoLetterISORegionName\":\"LT\",\"ThreeLetterISORegionName\":\"LTU\"},{\"Name\":\"LU\",\"DisplayName\":\"Luxembourg\",\"TwoLetterISORegionName\":\"LU\",\"ThreeLetterISORegionName\":\"LUX\"},{\"Name\":\"MO\",\"DisplayName\":\"Macao S.A.R.\",\"TwoLetterISORegionName\":\"MO\",\"ThreeLetterISORegionName\":\"MAC\"},{\"Name\":\"MK\",\"DisplayName\":\"Macedonia (FYROM)\",\"TwoLetterISORegionName\":\"MK\",\"ThreeLetterISORegionName\":\"MKD\"},{\"Name\":\"MY\",\"DisplayName\":\"Malaysia\",\"TwoLetterISORegionName\":\"MY\",\"ThreeLetterISORegionName\":\"MYS\"},{\"Name\":\"MV\",\"DisplayName\":\"Maldives\",\"TwoLetterISORegionName\":\"MV\",\"ThreeLetterISORegionName\":\"MDV\"},{\"Name\":\"ML\",\"DisplayName\":\"Mali\",\"TwoLetterISORegionName\":\"ML\",\"ThreeLetterISORegionName\":\"MLI\"},{\"Name\":\"MT\",\"DisplayName\":\"Malta\",\"TwoLetterISORegionName\":\"MT\",\"ThreeLetterISORegionName\":\"MLT\"},{\"Name\":\"MX\",\"DisplayName\":\"Mexico\",\"TwoLetterISORegionName\":\"MX\",\"ThreeLetterISORegionName\":\"MEX\"},{\"Name\":\"MN\",\"DisplayName\":\"Mongolia\",\"TwoLetterISORegionName\":\"MN\",\"ThreeLetterISORegionName\":\"MNG\"},{\"Name\":\"ME\",\"DisplayName\":\"Montenegro\",\"TwoLetterISORegionName\":\"ME\",\"ThreeLetterISORegionName\":\"MNE\"},{\"Name\":\"MA\",\"DisplayName\":\"Morocco\",\"TwoLetterISORegionName\":\"MA\",\"ThreeLetterISORegionName\":\"MAR\"},{\"Name\":\"NP\",\"DisplayName\":\"Nepal\",\"TwoLetterISORegionName\":\"NP\",\"ThreeLetterISORegionName\":\"NPL\"},{\"Name\":\"NL\",\"DisplayName\":\"Netherlands\",\"TwoLetterISORegionName\":\"NL\",\"ThreeLetterISORegionName\":\"NLD\"},{\"Name\":\"NZ\",\"DisplayName\":\"New Zealand\",\"TwoLetterISORegionName\":\"NZ\",\"ThreeLetterISORegionName\":\"NZL\"},{\"Name\":\"NI\",\"DisplayName\":\"Nicaragua\",\"TwoLetterISORegionName\":\"NI\",\"ThreeLetterISORegionName\":\"NIC\"},{\"Name\":\"NG\",\"DisplayName\":\"Nigeria\",\"TwoLetterISORegionName\":\"NG\",\"ThreeLetterISORegionName\":\"NGA\"},{\"Name\":\"NO\",\"DisplayName\":\"Norway\",\"TwoLetterISORegionName\":\"NO\",\"ThreeLetterISORegionName\":\"NOR\"},{\"Name\":\"OM\",\"DisplayName\":\"Oman\",\"TwoLetterISORegionName\":\"OM\",\"ThreeLetterISORegionName\":\"OMN\"},{\"Name\":\"PA\",\"DisplayName\":\"Panama\",\"TwoLetterISORegionName\":\"PA\",\"ThreeLetterISORegionName\":\"PAN\"},{\"Name\":\"PY\",\"DisplayName\":\"Paraguay\",\"TwoLetterISORegionName\":\"PY\",\"ThreeLetterISORegionName\":\"PRY\"},{\"Name\":\"CN\",\"DisplayName\":\"People's Republic of China\",\"TwoLetterISORegionName\":\"CN\",\"ThreeLetterISORegionName\":\"CHN\"},{\"Name\":\"PE\",\"DisplayName\":\"Peru\",\"TwoLetterISORegionName\":\"PE\",\"ThreeLetterISORegionName\":\"PER\"},{\"Name\":\"PH\",\"DisplayName\":\"Philippines\",\"TwoLetterISORegionName\":\"PH\",\"ThreeLetterISORegionName\":\"PHL\"},{\"Name\":\"PL\",\"DisplayName\":\"Poland\",\"TwoLetterISORegionName\":\"PL\",\"ThreeLetterISORegionName\":\"POL\"},{\"Name\":\"PT\",\"DisplayName\":\"Portugal\",\"TwoLetterISORegionName\":\"PT\",\"ThreeLetterISORegionName\":\"PRT\"},{\"Name\":\"MC\",\"DisplayName\":\"Principality of Monaco\",\"TwoLetterISORegionName\":\"MC\",\"ThreeLetterISORegionName\":\"MCO\"},{\"Name\":\"PR\",\"DisplayName\":\"Puerto Rico\",\"TwoLetterISORegionName\":\"PR\",\"ThreeLetterISORegionName\":\"PRI\"},{\"Name\":\"QA\",\"DisplayName\":\"Qatar\",\"TwoLetterISORegionName\":\"QA\",\"ThreeLetterISORegionName\":\"QAT\"},{\"Name\":\"MD\",\"DisplayName\":\"Republica Moldova\",\"TwoLetterISORegionName\":\"MD\",\"ThreeLetterISORegionName\":\"MDA\"},{\"Name\":\"RE\",\"DisplayName\":\"Réunion\",\"TwoLetterISORegionName\":\"RE\",\"ThreeLetterISORegionName\":\"REU\"},{\"Name\":\"RO\",\"DisplayName\":\"Romania\",\"TwoLetterISORegionName\":\"RO\",\"ThreeLetterISORegionName\":\"ROU\"},{\"Name\":\"RU\",\"DisplayName\":\"Russia\",\"TwoLetterISORegionName\":\"RU\",\"ThreeLetterISORegionName\":\"RUS\"},{\"Name\":\"RW\",\"DisplayName\":\"Rwanda\",\"TwoLetterISORegionName\":\"RW\",\"ThreeLetterISORegionName\":\"RWA\"},{\"Name\":\"SA\",\"DisplayName\":\"Saudi Arabia\",\"TwoLetterISORegionName\":\"SA\",\"ThreeLetterISORegionName\":\"SAU\"},{\"Name\":\"SN\",\"DisplayName\":\"Senegal\",\"TwoLetterISORegionName\":\"SN\",\"ThreeLetterISORegionName\":\"SEN\"},{\"Name\":\"RS\",\"DisplayName\":\"Serbia\",\"TwoLetterISORegionName\":\"RS\",\"ThreeLetterISORegionName\":\"SRB\"},{\"Name\":\"CS\",\"DisplayName\":\"Serbia and Montenegro (Former)\",\"TwoLetterISORegionName\":\"CS\",\"ThreeLetterISORegionName\":\"SCG\"},{\"Name\":\"SG\",\"DisplayName\":\"Singapore\",\"TwoLetterISORegionName\":\"SG\",\"ThreeLetterISORegionName\":\"SGP\"},{\"Name\":\"SK\",\"DisplayName\":\"Slovakia\",\"TwoLetterISORegionName\":\"SK\",\"ThreeLetterISORegionName\":\"SVK\"},{\"Name\":\"SI\",\"DisplayName\":\"Slovenia\",\"TwoLetterISORegionName\":\"SI\",\"ThreeLetterISORegionName\":\"SVN\"},{\"Name\":\"SO\",\"DisplayName\":\"Soomaaliya\",\"TwoLetterISORegionName\":\"SO\",\"ThreeLetterISORegionName\":\"SOM\"},{\"Name\":\"ZA\",\"DisplayName\":\"South Africa\",\"TwoLetterISORegionName\":\"ZA\",\"ThreeLetterISORegionName\":\"ZAF\"},{\"Name\":\"ES\",\"DisplayName\":\"Spain\",\"TwoLetterISORegionName\":\"ES\",\"ThreeLetterISORegionName\":\"ESP\"},{\"Name\":\"LK\",\"DisplayName\":\"Sri Lanka\",\"TwoLetterISORegionName\":\"LK\",\"ThreeLetterISORegionName\":\"LKA\"},{\"Name\":\"SE\",\"DisplayName\":\"Sweden\",\"TwoLetterISORegionName\":\"SE\",\"ThreeLetterISORegionName\":\"SWE\"},{\"Name\":\"CH\",\"DisplayName\":\"Switzerland\",\"TwoLetterISORegionName\":\"CH\",\"ThreeLetterISORegionName\":\"CHE\"},{\"Name\":\"SY\",\"DisplayName\":\"Syria\",\"TwoLetterISORegionName\":\"SY\",\"ThreeLetterISORegionName\":\"SYR\"},{\"Name\":\"TW\",\"DisplayName\":\"Taiwan\",\"TwoLetterISORegionName\":\"TW\",\"ThreeLetterISORegionName\":\"TWN\"},{\"Name\":\"TJ\",\"DisplayName\":\"Tajikistan\",\"TwoLetterISORegionName\":\"TJ\",\"ThreeLetterISORegionName\":\"TAJ\"},{\"Name\":\"TH\",\"DisplayName\":\"Thailand\",\"TwoLetterISORegionName\":\"TH\",\"ThreeLetterISORegionName\":\"THA\"},{\"Name\":\"TT\",\"DisplayName\":\"Trinidad and Tobago\",\"TwoLetterISORegionName\":\"TT\",\"ThreeLetterISORegionName\":\"TTO\"},{\"Name\":\"TN\",\"DisplayName\":\"Tunisia\",\"TwoLetterISORegionName\":\"TN\",\"ThreeLetterISORegionName\":\"TUN\"},{\"Name\":\"TR\",\"DisplayName\":\"Turkey\",\"TwoLetterISORegionName\":\"TR\",\"ThreeLetterISORegionName\":\"TUR\"},{\"Name\":\"TM\",\"DisplayName\":\"Turkmenistan\",\"TwoLetterISORegionName\":\"TM\",\"ThreeLetterISORegionName\":\"TKM\"},{\"Name\":\"AE\",\"DisplayName\":\"U.A.E.\",\"TwoLetterISORegionName\":\"AE\",\"ThreeLetterISORegionName\":\"ARE\"},{\"Name\":\"UA\",\"DisplayName\":\"Ukraine\",\"TwoLetterISORegionName\":\"UA\",\"ThreeLetterISORegionName\":\"UKR\"},{\"Name\":\"GB\",\"DisplayName\":\"United Kingdom\",\"TwoLetterISORegionName\":\"GB\",\"ThreeLetterISORegionName\":\"GBR\"},{\"Name\":\"US\",\"DisplayName\":\"United States\",\"TwoLetterISORegionName\":\"US\",\"ThreeLetterISORegionName\":\"USA\"},{\"Name\":\"UY\",\"DisplayName\":\"Uruguay\",\"TwoLetterISORegionName\":\"UY\",\"ThreeLetterISORegionName\":\"URY\"},{\"Name\":\"UZ\",\"DisplayName\":\"Uzbekistan\",\"TwoLetterISORegionName\":\"UZ\",\"ThreeLetterISORegionName\":\"UZB\"},{\"Name\":\"VN\",\"DisplayName\":\"Vietnam\",\"TwoLetterISORegionName\":\"VN\",\"ThreeLetterISORegionName\":\"VNM\"},{\"Name\":\"YE\",\"DisplayName\":\"Yemen\",\"TwoLetterISORegionName\":\"YE\",\"ThreeLetterISORegionName\":\"YEM\"},{\"Name\":\"ZW\",\"DisplayName\":\"Zimbabwe\",\"TwoLetterISORegionName\":\"ZW\",\"ThreeLetterISORegionName\":\"ZWE\"}]";

            return(_jsonSerializer.DeserializeFromString <CountryInfo[]>(jsonCountries));
        }
Ejemplo n.º 14
0
        private void OnReceiveInternal(string message)
        {
            LastActivityDate = DateTime.UtcNow;

            if (!message.StartsWith("{", StringComparison.OrdinalIgnoreCase))
            {
                // This info is useful sometimes but also clogs up the log
                //_logger.Error("Received web socket message that is not a json structure: " + message);
                return;
            }

            if (OnReceive == null)
            {
                return;
            }

            try
            {
                var stub = (WebSocketMessage <object>)_jsonSerializer.DeserializeFromString(message, typeof(WebSocketMessage <object>));

                var info = new WebSocketMessageInfo
                {
                    MessageType = stub.MessageType,
                    Data        = stub.Data == null ? null : stub.Data.ToString(),
                    Connection  = this
                };

                OnReceive(info);
            }
            catch (Exception ex)
            {
                _logger.ErrorException("Error processing web socket message", ex);
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Posts the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        public void Post(UpdateDisplayPreferences request)
        {
            // Serialize to json and then back so that the core doesn't see the request dto type
            var displayPreferences = _jsonSerializer.DeserializeFromString <DisplayPreferences>(_jsonSerializer.SerializeToString(request));

            _displayPreferencesManager.SaveDisplayPreferences(displayPreferences, request.UserId, request.Client, CancellationToken.None);
        }
        private SmartMatchResult GetResultSmartMatch(IReadOnlyList <IResultSetValue> reader)
        {
            var index = 0;

            var result = new SmartMatchResult
            {
                Id = reader[0].ReadGuidFromBlob()
            };

            index++;
            result.ItemName = reader[index].ToString();

            index++;
            result.DisplayName = reader[index].ToString();

            index++;
            result.OrganizerType = (FileOrganizerType)Enum.Parse(typeof(FileOrganizerType), reader[index].ToString(), true);

            index++;
            if (reader[index].SQLiteType != SQLiteType.Null)
            {
                result.MatchStrings.AddRange(_jsonSerializer.DeserializeFromString <List <string> >(reader[index].ToString()));
            }

            return(result);
        }
Ejemplo n.º 17
0
        public static RemoteSrt DecodeId(string id, IJsonSerializer json)
        {
            byte[] decodedBytes = Convert.FromBase64String(id);
            var    str          = Encoding.Unicode.GetString(decodedBytes);

            return(json.DeserializeFromString <RemoteSrt>(str));
        }
Ejemplo n.º 18
0
        public async Task <IEnumerable <ChannelItemInfo> > GetAllItems(bool direct, CancellationToken cancellationToken)
        {
            if (!RegistrationInfo.Instance.IsRegistered)
            {
                return(GetNonSupporterItems().Items);
            }

            if (direct || Plugin.Instance.Configuration.ForceDownloadListings)
            {
                return(await GetDirectListings(cancellationToken).ConfigureAwait(false));
            }

            var json = await EntryPoint.Instance.GetAndCacheResponse("https://raw.githubusercontent.com/MediaBrowser/MediaBrowser.Channels/master/MediaBrowser.Plugins.Trailers/Listings/filteredlistings.txt?v=" + DataVersion,
                                                                     TimeSpan.FromDays(3), cancellationToken);

            var items = _json.DeserializeFromString <List <ChannelItemInfo> >(json);

            if (!Plugin.Instance.Configuration.EnableMovieArchive)
            {
                items = items.Where(i => i.TrailerTypes.Count != 1 || i.TrailerTypes[0] != TrailerType.Archive)
                        .ToList();
            }

            return(items);
        }
        protected async Task FetchLastfmData(MusicArtist item, string musicBrainzId, CancellationToken cancellationToken)
        {
            // Get artist info with provided id
            var url = RootUrl + String.Format("method=artist.getInfo&mbid={0}&api_key={1}&format=json", UrlEncode(musicBrainzId), ApiKey);

            LastfmGetArtistResult result;

            using (var json = await _httpClient.Get(new HttpRequestOptions
            {
                Url = url,
                CancellationToken = cancellationToken,
                DecompressionMethod = CompressionMethod.None
            }).ConfigureAwait(false))
            {
                using (var reader = new StreamReader(json))
                {
                    var jsonText = await reader.ReadToEndAsync().ConfigureAwait(false);

                    // Fix their bad json
                    jsonText = jsonText.Replace("\"#text\"", "\"url\"");

                    result = _json.DeserializeFromString <LastfmGetArtistResult>(jsonText);
                }
            }

            if (result != null && result.artist != null)
            {
                ProcessArtistData(item, result.artist, musicBrainzId);
            }
        }
Ejemplo n.º 20
0
        private T Clone<T>(T obj)
        {
            // Since we're going to be setting properties on MediaSourceInfos that come out of _mediaSourceManager, we should clone it
            // Should we move this directly into MediaSourceManager?

            var json = _json.SerializeToString(obj);
            return _json.DeserializeFromString<T>(json);
        }
Ejemplo n.º 21
0
        private async void FindServers(Action <ServerDiscoveryInfo> serverFound, Action <Exception> error, CancellationToken cancellationToken)
        {
            var serverIdsFound = new List <string>();

            // Create a udp client
            using (var client = new UdpClient(new IPEndPoint(IPAddress.Any, GetRandomUnusedPort())))
            {
                // Construct the message the server is expecting
                var bytes = Encoding.UTF8.GetBytes("who is EmbyServer?");

                // Send it - must be IPAddress.Broadcast, 7359
                var targetEndPoint = new IPEndPoint(IPAddress.Broadcast, 7359);

                try
                {
                    // Send the broadcast
                    await client.SendAsync(bytes, bytes.Length, targetEndPoint).ConfigureAwait(false);

                    while (!cancellationToken.IsCancellationRequested)
                    {
                        // Get a result back
                        var result = await client.ReceiveAsync().ConfigureAwait(false);

                        if (result.RemoteEndPoint.Port == targetEndPoint.Port)
                        {
                            // Convert bytes to text
                            var json = Encoding.UTF8.GetString(result.Buffer);

                            _logger.Debug("Received response from endpoint: " + result.RemoteEndPoint + ". Response: " + json);

                            if (!string.IsNullOrEmpty(json))
                            {
                                try
                                {
                                    var info = _jsonSerializer.DeserializeFromString <ServerDiscoveryInfo>(json);

                                    if (!serverIdsFound.Contains(info.Id))
                                    {
                                        serverIdsFound.Add(info.Id);
                                        info.EndpointAddress = result.RemoteEndPoint.Address.ToString();
                                        serverFound(info);
                                    }
                                }
                                catch (Exception ex)
                                {
                                    _logger.ErrorException("Error parsing server discovery info", ex);
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    error(ex);
                }
            }
        }
Ejemplo n.º 22
0
 private static RootConnectionInfoObject ParseConnectionInfo(Stream stream, IJsonSerializer json)
 {
     using (var reader = new StreamReader(stream, new UTF8Encoding()))
     {
         string resptext = reader.ReadToEnd();
         resptext = Regex.Replace(resptext, "{\"Version\": {\"Version\"", "{\"Version\": {\"Ver\"");
         return json.DeserializeFromString<RootConnectionInfoObject>(resptext);
     }
 }
Ejemplo n.º 23
0
 private static RootConnectionInfoObject ParseConnectionInfo(Stream stream, IJsonSerializer json)
 {
     using (var reader = new StreamReader(stream, new UTF8Encoding()))
     {
         string resptext = reader.ReadToEnd();
         resptext = Regex.Replace(resptext, "{\"Version\": {\"Version\"", "{\"Version\": {\"Ver\"");
         return(json.DeserializeFromString <RootConnectionInfoObject>(resptext));
     }
 }
Ejemplo n.º 24
0
        /// <summary>
        /// Posts the specified configuraiton.
        /// </summary>
        /// <param name="request">The request.</param>
        public void Post(UpdateConfiguration request)
        {
            // Silly, but we need to serialize and deserialize or the XmlSerializer will write the xml with an element name of UpdateConfiguration
            var json = _jsonSerializer.SerializeToString(request);

            var config = _jsonSerializer.DeserializeFromString <ServerConfiguration>(json);

            _configurationManager.ReplaceConfiguration(config);
        }
Ejemplo n.º 25
0
        /// <summary>
        /// 获取头像信息
        /// </summary>
        /// <param name="result"></param>
        /// <param name="_jsonSerializer"></param>
        /// <returns></returns>
        public static JavPersonIndex GetJavPersonIndex(this IHasProviderIds result, IJsonSerializer _jsonSerializer)
        {
            if (result.ProviderIds.TryGetValue($"{PersonName}-Json", out string json) == false)
            {
                return(null);
            }

            return(_jsonSerializer.DeserializeFromString <JavPersonIndex>(json));
        }
Ejemplo n.º 26
0
        public ClientCapabilities GetCapabilities(string id)
        {
            lock (_capabilitiesSyncLock)
            {
                ClientCapabilities result;
                if (_capabilitiesCache.TryGetValue(id, out result))
                {
                    return(result);
                }

                var path = Path.Combine(GetDevicePath(id), "capabilities.json");
                try
                {
                    return(_json.DeserializeFromFile <ClientCapabilities>(path));
                }
                catch
                {
                }
            }

            if (_enableDatabase)
            {
                using (WriteLock.Read())
                {
                    using (var connection = CreateConnection(true))
                    {
                        var statementTexts = new List <string>();
                        statementTexts.Add("Select Capabilities from Devices where Id=@Id");

                        return(connection.RunInTransaction(db =>
                        {
                            var statements = PrepareAllSafe(db, statementTexts).ToList();

                            using (var statement = statements[0])
                            {
                                statement.TryBind("@Id", id);

                                foreach (var row in statement.ExecuteQuery())
                                {
                                    if (row[0].SQLiteType != SQLiteType.Null)
                                    {
                                        return _json.DeserializeFromString <ClientCapabilities>(row.GetString(0));
                                    }
                                }

                                return new ClientCapabilities();
                            }
                        }, ReadTransactionMode));
                    }
                }
            }

            return(new ClientCapabilities());
        }
Ejemplo n.º 27
0
        private User GetUser(IReadOnlyList <IResultSetValue> row)
        {
            var id   = row[0].ToInt64();
            var guid = row[1].ReadGuidFromBlob();

            var user = _jsonSerializer.DeserializeFromString <User>(row.GetString(2));

            user.InternalId = id;
            user.Id         = guid;
            return(user);
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Recreates the object using serialization, to ensure it's not a subclass.
        /// If it's a subclass it may not serlialize properly to xml (different root element tag name)
        /// </summary>
        /// <param name="profile"></param>
        /// <returns></returns>
        private DeviceProfile ReserializeProfile(DeviceProfile profile)
        {
            if (profile.GetType() == typeof(DeviceProfile))
            {
                return(profile);
            }

            var json = _jsonSerializer.SerializeToString(profile);

            return(_jsonSerializer.DeserializeFromString <DeviceProfile>(json));
        }
Ejemplo n.º 29
0
        private IEnumerable <string> FindIds(SubtitleSearchRequest request, BaseItem item, CancellationToken cancellationToken, int depth = 0)
        {
            var query = "";

            string imdbId = "";

            switch (request.ContentType)
            {
            case VideoContentType.Episode:
                var series = ((Episode)item).Series;
                query  = series.OriginalTitle;
                imdbId = series.ProviderIds["Imdb"].Substring(2);
                break;

            case VideoContentType.Movie:
                query  = item.OriginalTitle;
                imdbId = item.ProviderIds["Imdb"].Substring(2);
                break;
            }
            if (!int.TryParse(imdbId, out var imdbIdInt))
            {
                imdbIdInt = -1;
            }

            var requestOptions = new HttpRequestOptions()
            {
                Url = string.Format(URL_BASE + "/legenda/sugestao/{0}", HttpUtility.HtmlEncode(query)),
                CancellationToken = cancellationToken,
            };

            using (var stream = _httpClient.Get(requestOptions).Result)
            {
                using (var reader = new StreamReader(stream))
                {
                    var response    = reader.ReadToEnd();
                    var suggestions = _jsonSerializer.DeserializeFromString <List <LegendasTVSuggestion> >(response);

                    foreach (var suggestion in suggestions)
                    {
                        var source = suggestion._source;
                        if (!int.TryParse(source.id_imdb, out var sourceImdb))
                        {
                            sourceImdb = -2;
                        }

                        if (((sourceImdb == imdbIdInt) || (source.id_imdb == imdbId)) &&
                            (request.ContentType == VideoContentType.Movie ? source.tipo == "M" : true))
                        {
                            yield return(source.id_filme);
                        }
                    }
                }
            }
        }
Ejemplo n.º 30
0
        private async Task UpdateUserPolicy(User user, UserPolicy userPolicy, bool fireEvent)
        {
            // The xml serializer will output differently if the type is not exact
            if (userPolicy.GetType() != typeof(UserPolicy))
            {
                var json = _jsonSerializer.SerializeToString(userPolicy);
                userPolicy = _jsonSerializer.DeserializeFromString <UserPolicy>(json);
            }

            var path = GetPolifyFilePath(user);

            _fileSystem.CreateDirectory(Path.GetDirectoryName(path));

            lock (_policySyncLock)
            {
                _xmlSerializer.SerializeToFile(userPolicy, path);
                user.Policy = userPolicy;
            }

            await UpdateConfiguration(user, user.Configuration, true).ConfigureAwait(false);
        }
        private async Task <LastfmGetAlbumResult> GetAlbumResult(string artist, string album, CancellationToken cancellationToken)
        {
            // Get albu info using artist and album name
            var url = LastfmArtistProvider.RootUrl + string.Format("method=album.getInfo&artist={0}&album={1}&api_key={2}&format=json", UrlEncode(artist), UrlEncode(album), LastfmArtistProvider.ApiKey);

            using (var response = await _httpClientFactory.CreateClient().GetAsync(url, cancellationToken).ConfigureAwait(false))
            {
                using (var stream = await response.Content.ReadAsStreamAsync())
                {
                    using (var reader = new StreamReader(stream))
                    {
                        var jsonText = await reader.ReadToEndAsync().ConfigureAwait(false);

                        // Fix their bad json
                        jsonText = jsonText.Replace("\"#text\"", "\"url\"");

                        return(_json.DeserializeFromString <LastfmGetAlbumResult>(jsonText));
                    }
                }
            }
        }
Ejemplo n.º 32
0
 public static EncoderList ParseEncoderList(Stream stream, IJsonSerializer json, ILogger logger)
 {
     using (var reader = new StreamReader(stream, new UTF8Encoding()))
     {
         string resptext = reader.ReadToEnd();
         UtilsHelper.DebugInformation(logger, string.Format("[MythTV] ParseEncoderList Response: {0}", resptext));
     
         //resptext = Regex.Replace(resptext, "{\"Version\": {\"Version\"", "{\"Version\": {\"Ver\"");
         var root = json.DeserializeFromString<RootEncoderObject>(resptext);
         return root.EncoderList;
     }           
 }