Beispiel #1
0
        public LoginPlex(string username, int mediaserver_)
        {
            InitializeComponent();
            plexApi = new PlexClient();

            uname.Focus();
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            Thread.Sleep(TimeSpan.FromSeconds(10));
            var c = new PlexClient("nopDelay", new Connection("127.0.0.1", 1909));
            const int cont = 4;

            var keys = Enumerable.Range(0, cont).Select(p => p.ToString(CultureInfo.InvariantCulture)).ToArray();
            File.Copy("Test.NopDelay.exe", "Test.NopDelay.Clone.exe", true);
            c.InitTaskLocal(Directory.GetCurrentDirectory(), new[]{"Test.NopDelay.Clone.exe"});
            c.EnqueueToTask(keys.Take(cont/2).ToArray());
            c.EnqueueToTask(keys.Skip(cont / 2).ToArray());
            var rets = new List<SubTaskResult>();
            while(rets.Count < keys.Length)
            {
                //Trace.TraceInformation("Test: Пытаемся получить результат");
                var pack = c.GetTaskResults();
                if (pack.Length > 0)
                {
                    rets.AddRange(pack);
                    Trace.TraceInformation("Test: Получили пачку из " + pack.Length + " ответов. " + rets.Count + "/" + keys.Length);
                }
                Thread.Sleep(1000);

            }
            Console.WriteLine("finished. Result=" + string.Join(";", rets.Select(p => p.Result.Deserialize<NopDelayResult>().Key)));
            c.DropTask();
            Console.ReadKey();
        }
        public void GetAccessToken_ShouldHandleIncorrectCredentials()
        {
            var plexClient = new PlexClient();
            var response   = plexClient.GetAccessToken("user", "password");

            Assert.NotNull(response);
            Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
        }
        private string GetAccessToken()
        {
            Skip.If(_plexuser == null || _plexpass == null, "Define username and password in secrets!");

            var plexClient = new PlexClient();
            var response   = plexClient.GetAccessToken(_plexuser, _plexpass);

            return(response.Data.user.authentication_token);
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            Thread.Sleep(TimeSpan.FromSeconds(10));
            var c = new PlexClient("testFiles", new Connection("127.0.0.1", 1909));
            const int count = 125500;
            var rnd = new byte[count];
            (new Random()).NextBytes(rnd);
            File.Delete(TestFilesExec.FileName);
            File.WriteAllBytes(TestFilesExec.FileName, rnd);
            var keys = Enumerable.Range(0, count).Select(p => p.ToString(CultureInfo.InvariantCulture)).ToArray();
            File.Copy("Test.Files.exe", "Test.Files.Clone.exe", true);
            try
            {
                c.InitTaskLocal(Directory.GetCurrentDirectory(), new[] { "Test.Files.Clone.exe" }, new [] { TestFilesExec.FileName });

                c.EnqueueToTask(keys);
                //c.EnqueueToTask(keys.Take(count / 2).ToArray());
                //c.EnqueueToTask(keys.Skip(count / 2).ToArray());
                var rets = new List<SubTaskResult>();
                while (rets.Count < keys.Length)
                {
                    //Trace.TraceInformation("Test: Пытаемся получить результат");
                    var pack = c.GetTaskResults();

                    if (pack.Length > 0)
                    {
                        var ex1 = pack.Where(p => p == null || p.Type != SubTaskResult.ResultType.Success).ToArray();
                        if (ex1.Length != 0)
                            throw new Exception();
                        rets.AddRange(pack);
                        Trace.TraceInformation("Test: Получили пачку из " + pack.Length + " ответов. " + rets.Count +
                                               "/" + keys.Length);
                    }
                }
                var ex = rets.Where(p => p == null || p.Type != SubTaskResult.ResultType.Success).ToArray();
                if(ex.Length != 0)
                    throw new Exception();
                var nl = rets.Where(p => p.Result == null || p.Result.Length == 0).ToArray();
                if (nl.Length != 0)
                    throw new Exception();
                var data = rets.OrderBy(p => int.Parse(p.Key)).SelectMany(p => p.Result).ToArray();
                if (data.Length != rnd.Length)
                    throw new Exception("test error len");
                for (int i = 0; i < data.Length; i++)
                {
                    if (data[i] != rnd[i])
                        throw new Exception("test error data");
                }
                Console.WriteLine("finished.");
            }
            finally
            {
                c.DropTask();
            }
            Console.ReadKey();
        }
        public void GetAccessToken_ShouldHandleCorrectCredentials()
        {
            Skip.If(_plexuser == null || _plexpass == null, "Define username and password in secrets!");

            var plexClient = new PlexClient();
            var response   = plexClient.GetAccessToken(_plexuser, _plexpass);

            Assert.NotNull(response);
            Assert.Equal(HttpStatusCode.Created, response.StatusCode);

            _output.WriteLine($"authentication_token: {response.Data.user.authentication_token}");
            _output.WriteLine(Environment.NewLine);
            _output.WriteLine(JsonConvert.SerializeObject(response.Data, Formatting.Indented));
        }
Beispiel #7
0
 public PlexDeviceInfo(string device, string product, string version, string platform)
 {
     if ((product != null && product.ToUpperInvariant().Contains("IOS")) ||
         (platform != null && platform.ToUpperInvariant().Contains("IOS")))
     {
         Client = PlexClient.IOS;
     }
     else if ((product != null && product.ToUpperInvariant().Contains("ANDROID")) ||
              (platform != null && platform.ToUpperInvariant().Contains("ANDROID")))
     {
         Client = PlexClient.Android;
     }
     else if ((product != null && product.ToUpperInvariant().Contains("PLEX MEDIA PLAYER")) ||
              (platform != null && platform.ToUpperInvariant().Contains("KONVERGO")))
     {
         Client = PlexClient.PlexMediaPlayer;
     }
     else if ((product != null && product.ToUpperInvariant().Contains("KODI")) ||
              (platform != null && platform.ToUpperInvariant().Contains("KODI")))
     {
         Client = PlexClient.Kodi;
     }
     else if ((product != null && product.ToUpperInvariant().Contains("WINDOWS")))
     {
         Client = PlexClient.PlexForWindows;
     }
     else if ((product != null && product.ToUpperInvariant().Contains("PLEX MEDIA SERVER")))
     {
         Client = PlexClient.PlexMediaPlayer;
     }
     else if ((product != null && product.ToUpperInvariant().Contains("PLEX WEB")))
     {
         Client = PlexClient.Web;
     }
     else if ((device != null && device.ToUpperInvariant().Contains("WEBOS")))
     {
         Client = PlexClient.WebOs;
     }
     else
     {
         Client = PlexClient.Other;
     }
     Device   = device;
     Product  = product;
     Version  = version;
     Platform = platform;
 }
Beispiel #8
0
        public async Task SyncToTrakt()
        {
            var _plexClient  = new PlexClient(_plexClientSecret);
            var _traktClient = new TraktClient(_traktClientId, _traktClientSecret);

            try
            {
                _plexClient.SetAuthToken(_plexKey);
                _plexClient.SetPlexServerUrl(_plexUrl);

                _traktClient.Authorization = TraktAuthorization.CreateWith(_traktKey);

                await MigrateMovies(_plexClient, _traktClient);

                //await MigrateTvShows(_plexClient, _traktClient);

                await SendEmail(_emailSendTo);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
Beispiel #9
0
 public HomeController(PlexClient plexClient, IConfiguration config)
 {
     _plexClient = plexClient;
     _config     = config;
 }
Beispiel #10
0
        private async Task MigrateMovies(PlexClient _plexClient, TraktClient _traktClient)
        {
            await ReportProgress("--------------------------------------------");
            await ReportProgress("Started syncing Movies!");
            await ReportProgress("--------------------------------------------");

            await ReportProgress("Importing Trakt movies..");

            var traktMovies =
                (await _traktClient.Sync.GetWatchedMoviesAsync(new TraktExtendedInfo().SetFull())).ToArray();

            await ReportProgress($"Found {traktMovies.Length} movies on Trakt");

            await ReportProgress("Importing Plex movies..");

            var plexMovies = await _plexClient.GetMovies();

            await ReportProgress($"Found {plexMovies.Length} movies on Plex");

            await ReportProgress("Going through all movies on Plex, to see if we find a match on Trakt..");

            var i = 0;
            var notMarkedMovies = new List <Movie>();

            foreach (var plexMovie in plexMovies.Where(x => x.ViewCount != null && x.ViewCount > 0))
            {
                i++;
                var traktMovie = traktMovies.FirstOrDefault(x => HasMatchingIdMovies(plexMovie, x.Ids));
                if (traktMovie == null)
                {
                    notMarkedMovies.Add(plexMovie);
                }
            }

            var traktSyncHistoryPostMovies = new TraktSyncHistoryPostBuilder();

            foreach (var notMarkedMovie in notMarkedMovies)
            {
                if (notMarkedMovie.ImdbId == null)
                {
                    await ReportProgress($"{notMarkedMovie.Title} doesnt have an IMDB.  SKIPPING!");
                }
                else
                {
                    Debug.Assert(notMarkedMovie.LastViewedAtDateTime != null, "notMarkedMovie.LastViewedAtDateTime != null");
                    traktSyncHistoryPostMovies.AddMovie(new TraktMovie()
                    {
                        Title  = notMarkedMovie.Title
                        , Year = (int?)notMarkedMovie.Year
                        , Ids  = new TraktMovieIds()
                        {
                            Imdb = notMarkedMovie.ImdbId
                        }
                    }, (DateTime)notMarkedMovie.LastViewedAtDateTime);
                }
            }

            var payload = traktSyncHistoryPostMovies.Build();

            if (payload.Movies != null)
            {
                await _traktClient.Sync.AddWatchedHistoryItemsAsync(payload);
            }

            await ReportProgress("--------------------------------------------");
            await ReportProgress("Finished syncing Movies!");
            await ReportProgress("--------------------------------------------");
        }
Beispiel #11
0
 public Plex()
 {
     plexAPI = new PlexClient();
 }
Beispiel #12
0
 public MigrationHub(IConfiguration config, PlexClient plexClient)
 {
     _config      = config;
     _plexClient  = plexClient;
     _traktClient = new TraktClient(_config["TraktConfig:ClientId"], _config["TraktConfig:ClientSecret"]);
 }