예제 #1
0
        private static async Task <MediathekViewWebResult> ProcessQuery(Query query)
        {
            JsonSerializerOptions querySerializerOptions = new JsonSerializerOptions {
                IgnoreNullValues = true
            };
            var text        = JsonSerializer.Serialize(query, querySerializerOptions);
            var httpContent = new StringContent(text, Encoding.UTF8, "text/plain");
            var streamTask  = await client.PostAsync("https://mediathekviewweb.de/api/query", httpContent);

            if (streamTask.IsSuccessStatusCode)
            {
                var stream = await streamTask.Content.ReadAsStreamAsync();

                JsonSerializerOptions resultSerializerOptions = new JsonSerializerOptions();
                resultSerializerOptions.Converters.Add(new Models.Utilities.NullableDateTimeConverter());
                resultSerializerOptions.Converters.Add(new Models.Utilities.NullableUInt32Converter());
                MediathekViewWebResult res = null;
                try
                {
                    res = await JsonSerializer.DeserializeAsync <MediathekViewWebResult>(stream, resultSerializerOptions);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
                return(res);
            }
            return(new MediathekViewWebResult {
                err = streamTask.ReasonPhrase
            });
        }
예제 #2
0
        public async Task <List <Models.MediaElement> > SearchForMediaElements(string searchterm)
        {
            _query.size   = 100;
            _query.future = false;
            _query.addFieldAndQuery("title", "topic", searchterm);
            var result = await sendQuery();

            return(MediathekViewWebResult.ToMediaElements(result));
        }
예제 #3
0
        public async Task <List <Models.MediaElement> > GetLatestMediaElements()
        {
            _query.size      = 1000;
            _query.sortBy    = "timestamp";
            _query.sortOrder = "desc";
            _query.future    = false;
            var result = await sendQuery();

            return(MediathekViewWebResult.ToMediaElements(result));
        }
예제 #4
0
        public static List <Mediathekar.Models.MediaElement> ToMediaElements(MediathekViewWebResult mediathekResult)
        {
            if (mediathekResult.hasErrors())
            {
                return(null);
            }
            List <Mediathekar.Models.MediaElement> mediaElements = new List <Mediathekar.Models.MediaElement>();

            foreach (var medium in mediathekResult.result.results)
            {
                string url = medium.url_video_hd;
                if (String.IsNullOrEmpty(url))
                {
                    url = medium.url_video;
                    if (String.IsNullOrEmpty(url))
                    {
                        url = medium.url_video_low;
                        if (String.IsNullOrEmpty(url))
                        {
                            continue;
                        }
                    }
                }
                var element = new Mediathekar.Models.MediaElement
                {
                    Channel      = medium.channel,
                    IdInChannel  = "MediathekViewWeb" + medium.id,      // reuse id, add channel for uniqueness
                    LastModified = medium.timestamp,
                    Title        = medium.title,
                    Topic        = medium.topic,
                    Url          = url,
                    Duration     = medium.duration,
                    Size         = medium.size,
                    MediaType    = Mediathekar.Models.MediaType.Movie // standard
                };
                uint?season  = null;
                uint?episode = null;

                if (Mediathekar.Models.Utilities.MediaElementUtilities.ContainsSeasonEpisode(medium.title, ref season, ref episode))
                {
                    element.Season    = season;
                    element.Episode   = episode;
                    element.MediaType = Mediathekar.Models.MediaType.Series;
                }
                if (medium.duration < 60 * 60)
                {
                    // less than 60min -> not a movie
                    element.MediaType = Mediathekar.Models.MediaType.Series;
                }
                mediaElements.Add(element);
            }
            return(mediaElements);
        }