Exemple #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var s = Request["show"];

            if (!string.IsNullOrEmpty(s))
            {
                int showId = -1;
                if (int.TryParse(s, out showId))
                {
                    show = new TmdbShow(showId);
                }
            }
            if (null == show)
            {
                show = new TmdbShow(2919);
            }
            s = Request["season"];
            if (!string.IsNullOrEmpty(s))
            {
                var i = 0;
                if (int.TryParse(s, out i))
                {
                    season = show.GetSeasonByNumber(i);
                }
            }
            if (null == season)
            {
                season = show.FirstSeason;
            }
        }
Exemple #2
0
        public async Task <List <InternalSeason> > GetSeasons(TmdbShow tmdbShowSimple, string id)
        {
            var _tmdbSeasons = new List <TmdbSeason>();

            foreach (var season in tmdbShowSimple.Seasons)
            {
                var notSimpleTmdbSeason =
                    await new WebClientManager().Get <TmdbSeason>(
                        $"{_endpoint}/3/tv/{int.Parse(id)}/season/{season.SeasonNumber}?api_key={_key}&language={_lang}");
                _tmdbSeasons.Add(notSimpleTmdbSeason);
            }
            return(InternalConverter.ConvertTmdbSeasonToInternalSeason(_tmdbSeasons));
        }
Exemple #3
0
        static void Main()
        {
            using (var reader = JsonTextReader.CreateFrom(@"..\..\data.json"))
            {
                if (reader.SkipTo("seasons", 7))
                {
                    // move past the field name "name"
                    if (JsonNodeType.Key != reader.NodeType || reader.Read())
                    {
                        Console.WriteLine(reader.ParseSubtree());
                    }
                }
            }
            // or...
            using (var reader = JsonTextReader.CreateFrom(@"..\..\data.json"))
            {
                if (reader.SkipToField("created_by"))
                {
                    if (reader.SkipToIndex(0))
                    {
                        reader.Read();
                        if (reader.SkipToField("name"))
                        {
                            if (reader.Read())
                            {
                                Console.WriteLine(reader.Value);
                            }
                        }
                    }
                }
            }

            return;

            Tmdb.ApiKey     = ApiKey;
            Tmdb.CacheLevel = JsonRpcCacheLevel.Aggressive;

            // hit it *hard* - 10 pages of movies, 10 of TV
            foreach (var movie in TmdbMovie.GetTopRated(0, 9))
            {
                _RunMovieDemo(movie.Id);
            }

            foreach (var show in TmdbShow.GetTopRated(0, 9))
            {
                _RunShowDemo(show.Id);
            }
        }
Exemple #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var s = Request["show"];

            if (!string.IsNullOrEmpty(s))
            {
                int showId = -1;
                if (int.TryParse(s, out showId))
                {
                    show = new TmdbShow(showId);
                }
            }
            if (null == show)
            {
                show = new TmdbShow(2919);
            }
        }
Exemple #5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var s = Request["show"];

            if (!string.IsNullOrEmpty(s))
            {
                int showId = -1;
                if (int.TryParse(s, out showId))
                {
                    show = new TmdbShow(showId);
                }
            }
            if (null == show)
            {
                show = new TmdbShow(2919);
            }

            s = Request["season"];
            if (!string.IsNullOrEmpty(s))
            {
                int seasonNumber = -1;
                if (int.TryParse(s, out seasonNumber))
                {
                    season = new TmdbSeason(show.Id, seasonNumber);
                }
            }
            if (null == season)
            {
                season = new TmdbSeason(show.Id, 1);
            }
            s = Request["episode"];
            if (!string.IsNullOrEmpty(s))
            {
                int episodeNumber = -1;
                if (int.TryParse(s, out episodeNumber))
                {
                    episode = new TmdbEpisode(show.Id, season.Number, episodeNumber);
                }
            }
            if (null == episode)
            {
                episode = new TmdbEpisode(show.Id, season.Number, 1);
            }
        }
Exemple #6
0
        static void _RunShowDemo(int id = 2919 /*Burn Notice*/)
        {
            // fetch a show - you can use SearchShows() or if you already know the id
            // of the object you want, just create it with the given id.
            var show = new TmdbShow(id);

            //Console.WriteLine(show.Json); // write the json - for now just an id


            Console.WriteLine();

            var name     = show.Name;
            var overview = show.Overview;

            // watch how it grew after getting some properties
            Console.WriteLine(show.Json);
            Console.WriteLine();

            Console.WriteLine(name);
            Console.WriteLine(overview);
            Console.WriteLine();
            //
            // write out the genres
            Console.Write("Genres:");
            var gbid = show.GenresById;

            if (null != gbid)
            {
                foreach (var g in gbid)
                {
                    Console.Write(string.Concat(" ", g.Value));
                }
            }
            Console.WriteLine();

            Console.WriteLine();

            // write out the cast
            Console.Write("Cast:");
            foreach (var c in show.Cast)
            {
                Console.WriteLine("\t{0} as {1}", c.Name, c.Character);
            }

            Console.WriteLine();

            // write out the crew.
            Console.Write("Crew:");
            foreach (var c in from cs in show.Crew select cs)
            {
                Console.WriteLine("\t{1} - {0}", c.Name, c.Job);
            }
            Console.WriteLine();
            // Seasons zero is Specials when the series has them
            // To account for that, we look to TotalSeasons instead
            // of Seasons.Length
            Console.WriteLine(
                "{0} Seasons and {1} Episodes in {2} years",
                show.TotalSeasons,
                show.TotalEpisodes,
                Math.Round((show.LastAirDate - show.FirstAirDate).TotalDays / 365)
                );

            // write out the reviews we found, if their are any.
            // this is not cached, which is why it's a paged method
            // the individual reviews are still cached
            var reviews = show.GetReviews();

            if (0 < reviews.Length)
            {
                Console.WriteLine();
                Console.WriteLine("Reviews:");
                foreach (var r in reviews)
                {
                    Console.WriteLine("\t\"{1}\" - {0}", r.Author, r.Content);
                }
            }
            var images = show.Images;

            if (0 < images.Length)
            {
                Console.WriteLine();
                Console.WriteLine("Images:");
                foreach (var i in images)
                {
                    Console.WriteLine("{0}: {1}", i.ImageType, Tmdb.GetImageUrl(i.Path));
                }
            }
            // note how the Json data associated with the object grew even more
            // in response to use using the object.
            // Console.WriteLine(show.Json); // write the json again
        }
Exemple #7
0
        static void _RunCacheDemo()
        {
            // Normally, you don't really have to mess with the cache in a desktop app
            // or a console app. Long running apps and services will require some
            // maintenance. Otherwise caching is automatic.

            // Fetch a show.
            var show  = new TmdbShow(2919);            // get "Burn Notice"
            var movie = new TmdbMovie(219);            // fetch "Volver"

            // right now our entries only have an id. use some properties
            // so we can get the show into the cache.
            Console.WriteLine("Fetched {0} from tmdb", show.Name);
            Console.WriteLine("Fetched {0} from tmdb", movie.Name);

            // write the cache to a file in the project directory
            //Tmdb.SaveCacheTo(@"..\..\cache.json");
            // we won't use the above helper method since we want our cache to
            // be pretty printed
            JsonObject.SaveTo(Tmdb.Json, @"..\..\cache.json", "    ");


            // Note that the cache is thread static. It's per thread instance.
            // Do not pass objects between threads. Serialize if you must like above
            // or in memory.

            // clear our cache.
            Tmdb.Json.Clear();

            // any existing instances will be orphaned. this impacts equality as well.

            // if you MUST re-cache an orphaned object, what you can do is this:
            movie = new TmdbMovie(movie.Json);
            // this will copy the old json data into a new movie instance which will then root
            // that in the current cache.

            // should only have the movie we just re-rooted above in it.
            Console.WriteLine(Tmdb.Json);

            // that's cool but how about we load our cache that we saved?

            Tmdb.LoadCacheFrom(@"..\..\cache.json");
            // Note that this MERGES the loaded data with the existing data.
            // You can call it multiple times in a row with different files
            // if you ever wanted to. This might be useful down the road
            // for cache differentials in a distributed system. There's also
            // LoadCacheFromUrl() with an eye toward distribution down the
            // road

            // remember if we create new TmdbEntry instances like movie or
            // TV objects, they will use the existing cache rather than
            // fetching from TMDB.

            // So, since we loaded the cache we should now be able to do
            show = new TmdbShow(3050);
            Console.WriteLine("This is cached: {0}", show.Name);
            // without making any remote requests.

            // use value equality semantics.
            // get the show again, this time through a search.
            // searches themselves are not cached, but each individual result
            // is. That means The Practice will get filled in with any additional
            // data returned from the search query.
            var showComparand = Tmdb.SearchShows("The Practice", minPage: 0, maxPage: 0)[0];

            // check to make sure showComparand and show are actually two different TmdbShow wrapper instances
            // should report that they are different
            Console.WriteLine("Instances are {0} actual objects", ReferenceEquals(show, showComparand) ? "the same" : "different");

            // check to make sure showComparand and show are actually logically equal.
            // should report that they are the equal
            Console.WriteLine("Instances are logically {0}", show == showComparand ? "equal" : "not equal");


            // NOTES:
            // Clearing the cache "unroots" all existing instances of TmdbEntry
            // derived classes. They will no longer operate on anything you have a
            // root for. In fact, they are still writing to parts of the old cache.
            // The moral is don't hang on to object instances for longer than you need
            // them. Don't store them as class members or in collections just because.
            // Instead, use them and throw them away. Get a new object when you need
            // it. This will ensure that the most current cache is the one being used.

            // our show and movie instances are still valid, but are not writing or
            // reading from the current cache.

            // This also impacts equality. Objects from the old cache cannot be compared
            // to objects from the new cache. They will always return false.

            // Because of the above, it's best to release all instances of the old objects
            // when you clear the cache. The system does not track which object instances
            // are expired objects. You can check if an object is expired manually, but it's
            // expensive.

            // ideally, a batch of operations is performed, then the cache can be cleared, then
            // the next batch (with all new objects) is performed, if you clear the cache at all.
            // a server app or a long running desktop app should clear it periodically, but doing
            // so will make a bunch of HTTP requests happen again, even if they already happened
            // since they weren't cached anymore.
            // The HTTP requests might be cached through the second level caching mechanism.
            //
            // if you like, you can save and load the cache from disk, that way you can keep the cache
            // across application runs. Eventually it will get big and stale though. In the future I
            // might monitor the Tmdb.Configuration.ChangeKeys to expire old objects, if i can figure
            // out how it works exactly.
        }
Exemple #8
0
        static void Main()
        {
            var url = "http://api.themoviedb.org/3/tv/2129?api_key=c83a68923b7fe1d18733e8776bba59bb";

            using (var reader = JsonTextReader.CreateFromUrl(url))
            {
                // skip to "$.created_by[1].name" <-- JSON path syntax
                if (reader.SkipTo("created_by", 0, "name"))
                {
                    // we're currently on the *key*/field name
                    // we have to move to the value if we want 
                    // just that.
                    if (reader.Read())
                    {
                        Console.WriteLine(reader.ParseSubtree());
                    }
                    else                     // below should never execute
                    {
                        Console.WriteLine("Sanity check failed, key has no value");
                    }
                    // we need to move outward in the tree
                    // so we can read the next array element
                    // so we skip the rest of this object
                    reader.SkipToEndObject();
                    if (reader.Read())                     // read past the end of the object
                    {
                        reader.SkipToField("name");
                        // we're currently on the *key*/field name
                        if (reader.Read())
                        {
                            Console.WriteLine(reader.ParseSubtree());
                        }
                        else                         // below should never execute
                        {
                            Console.WriteLine("Sanity check failed, key has no value");
                        }
                    }
                    else                     // below should never execute, we didn't expect to reach the end
                    {
                        Console.WriteLine("Sanity check failed, unexpected end of document");
                    }
                }
                else
                {
                    Console.WriteLine("Not found");
                }
            }
            return;

            using (var reader = JsonTextReader.CreateFromUrl("http://api.themoviedb.org/3/tv/2129?api_key=c83a68923b7fe1d18733e8776bba59bb"))
            {
                // skip to "$.created_by[1].name" <-- JSON path syntax
                if (reader.SkipTo("created_by", 1, "name"))
                {
                    // we're currently on the *key*/field name
                    // we have to move to the value if we want 
                    // just that.
                    if (reader.Read())
                    {
                        Console.WriteLine(reader.ParseSubtree());
                    }
                    else                     // below should never execute
                    {
                        Console.WriteLine("Sanity check failed, key has no value");
                    }
                }
                else
                {
                    Console.WriteLine("Not found");
                }
            }
            return;

            using (var reader = JsonTextReader.CreateFrom(@"..\..\data.json"))
            {
                while (reader.Read())
                {
                    Console.Write(reader.NodeType);
                    if (JsonNodeType.Value == reader.NodeType ||
                        JsonNodeType.Key == reader.NodeType)
                    {
                        Console.Write(" " + reader.Value);
                    }
                    Console.WriteLine();
                }
            }
            return;

            using (var reader = JsonTextReader.CreateFrom(@"..\..\data.json"))
            {
                if (reader.SkipTo("seasons", 7, "episodes", 3, "guest_stars", 0, "character"))
                {
                    // move past the field name if it's a key.
                    if (JsonNodeType.Key != reader.NodeType || reader.Read())
                    {
                        Console.WriteLine(reader.ParseSubtree());
                    }
                }
            }
            // or...
            using (var reader = JsonTextReader.CreateFrom(@"..\..\data.json"))
            {
                if (reader.SkipToField("created_by"))
                {
                    if (reader.SkipToIndex(0))
                    {
                        reader.Read();
                        if (reader.SkipToField("name"))
                        {
                            if (reader.Read())
                            {
                                Console.WriteLine(reader.Value);
                            }
                        }
                    }
                }
            }

            return;

            Tmdb.ApiKey     = ApiKey;
            Tmdb.CacheLevel = JsonRpcCacheLevel.Aggressive;

            // hit it *hard* - 10 pages of movies, 10 of TV
            foreach (var movie in TmdbMovie.GetTopRated(0, 9))
            {
                _RunMovieDemo(movie.Id);
            }

            foreach (var show in TmdbShow.GetTopRated(0, 9))
            {
                _RunShowDemo(show.Id);
            }
        }