Exemple #1
0
        private async void CheckTranscripts(object sender, RoutedEventArgs e)
        {
            Progress progress = new Progress();

            progress.Show();
            EnsureLoginToken();

            var transcripts = Directory.GetFiles(@"C:\Users\James\Downloads\BBC Batch 1A  - 11th March");

            foreach (var path in transcripts)
            {
                string diskref = Path.GetFileNameWithoutExtension(path);
                string url     = string.Format("http://api.bbcredux.com/content/{0}/data?token={1}", diskref, loginToken);
                try
                {
                    XElement data = await GetXml(url);

                    progress.WriteLine("{0} succeeded", url);
                }
                catch (WebException)
                {
                    progress.WriteLine("{0} failed", url);
                }
            }
        }
Exemple #2
0
        async private void RunAsyncFetches()
        {
            Progress progress = new Progress();

            progress.Show();

            int genrecount = await TaskEx.Run <int>(() =>
            {
                var ctx = new ReduxEntities();
                return(ctx.genres.Count());
            });

            progress.WriteLine("We have {0} genres", genrecount);

            WebClient client = new WebClient();

            progress.WriteLine("Fetching daily schedule");
            var result = await client.DownloadStringTaskAsync("http://www.bbc.co.uk/bbcone/programmes/schedules/london/today.xml");

            progress.WriteLine("Got Schedule");
            var doc = XElement.Parse(result);

            var pids = from pid in doc.XPathSelectElements("./day/broadcasts/broadcast/programme[@type='episode']/pid")
                       select pid.Value;
            await TaskEx.WhenAll((from p in pids select FetchPidDataAsync(p, progress)));

            progress.WriteLine("Finished");
        }
Exemple #3
0
        private async Task FetchPidDataAsync(string pid, Progress progress)
        {
            if (progress.IsCancelled)
            {
                return;
            }
            progress.WriteLine("Fetching {0}", pid);
            WebClient client = new WebClient();
            var       result = await client.DownloadStringTaskAsync("http://www.bbc.co.uk/programmes/" + pid + ".xml");

            progress.WriteLine("Got {0}", pid);
        }
Exemple #4
0
        //private Task<int> GetMaxIdScanned()
        //{
        //    TaskCompletionSource<int> tcs = new TaskCompletionSource<int>();
        //    TaskEx.Run(() =>
        //        {
        //            var ctx = new ReduxEntities();
        //            tcs.SetResult(ctx.genres.Max(g => g.pips_id));
        //        });
        //    return tcs.Task;
        //}

        //private Task<bool> CountGenres()
        //{
        //    TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>();
        //    TaskEx.Ru
        //}

        private void AddGenres(string pid, int pips_id, Progress progress)
        {
            try
            {
                var progpage = XElement.Load("http://www.bbc.co.uk/programmes/" + pid + ".xml");
                var genres   = (from cat in progpage.XPathSelectElements("categories//category[ancestor-or-self::category[@type='genre']]")
                                let cats = from c in cat.XPathSelectElements("./descendant-or-self::category") select c.Attribute("key").Value
                                           select new
                {
                    pips_id = pips_id,
                    title = cat.Element("title").Value,
                    name = cat.Attribute("key").Value,
                    //Cats = cats,
                    path = string.Join("/", cats.Reverse().ToArray())
                }
                                ).Distinct();
                progress.WriteLine("");
                progress.WriteLine("Fetching genres for {0} ({1})", pid, pips_id);
                var data = new ReduxEntities();
                foreach (var g in genres)
                {
                    progress.WriteLine("{0}, {1}, {2}", g.title, g.name, g.path);
                    data.genres.AddObject(new genre
                    {
                        pips_id = g.pips_id,
                        name    = g.name,
                        title   = g.title,
                        path    = g.path
                    });
                }
                data.SaveChanges();
            }
            catch (WebException)
            {
            }
        }
Exemple #5
0
        private async void GetDataAsync(object sender, RoutedEventArgs e)
        {
            Progress progress = new Progress();

            progress.Show();
            Thumbnail thumbnail = new Thumbnail();

            thumbnail.Show();
            var       context = new ReduxEntities();
            Stopwatch watch   = new Stopwatch();

            watch.Start();
            do
            {
                watch.Restart();
                int firstID = 0;

                if (await TaskEx.Run <bool>(() => { return(context.genres.Count() > 0); }))
                {
                    firstID = (from g in context.genres
                               select g.pips_id).Max();
                    //firstID = await TaskEx.Run<int>(() =>
                    //{
                    //    return (from g in context.genres
                    //            select g.pips_id).Max();
                    //});
                }

                var pids = (from p in context.pips_programmes
                            where p.id > firstID
                            select new PidItem {
                    Pid = p.pid, Id = p.id
                }).Take(50).ToList();

                //var pids = await TaskEx.Run<List<PidItem>>(() =>
                //{
                //    return (from p in context.pips_programmes
                //            where p.id > firstID
                //            select new PidItem { Pid = p.pid, Id = p.id }).Take(50).ToList();
                //});
                if (pids.Count == 0)
                {
                    break;
                }

                //foreach (var pid in pids)
                //{
                //    thumbnail.ShowImage("http://node2.bbcimg.co.uk/iplayer/images/episode/" + pid.Pid + "_314_176.jpg");
                //}

                await TaskEx.WhenAll(from pid in pids select AddGenresAsync(pid.Pid, pid.Id, progress, thumbnail));

                //foreach (var pid in pids)
                //{
                //    AddGenresAsync(pid.Pid, pid.Id, progress);
                //    if (progress.IsCancelled)
                //    {
                //        break;
                //    }
                //}
            } while (progress.IsCancelled == false);
            progress.WriteLine("Fetching has been cancelled");
        }
Exemple #6
0
        private async void RunMatcherClick(object sender, RoutedEventArgs e)
        {
            Thumbnail thumbnails = new Thumbnail();

            thumbnails.Show();
            Progress progress = new Progress();

            progress.Show();
            ReduxEntities ctx = new ReduxEntities();
            //DateTime cutoff = new DateTime(2010, 5, 1);
            var unmatched = (from r in ctx.redux_items
                             from rp in ctx.redux_to_pips
                             where r.id == rp.redux_id && rp.pips_id == 0
                             //&& r.aired >= cutoff
                             select r).ToList();;
            int count = 0;

            foreach (var unmatcheditem in unmatched)
            {
                if (progress.IsCancelled)
                {
                    break;
                }

                var item = new UnmatchedItem(unmatcheditem, ctx.redux_to_pips.FirstOrDefault(rp => rp.redux_id == unmatcheditem.id));
                if (item.rp == null || item.rp.pips_id > 0)
                {
                    continue;
                }

                var rangestart  = item.r.aired.AddMinutes(-5);
                var rangeend    = item.r.aired.AddMinutes(5);
                var pipsmatches = await TaskEx.Run <List <pips_programmes> >(() =>
                {
                    return((from p in ctx.pips_programmes
                            where p.start_gmt == item.r.aired &&
                            p.service_id == item.r.service_id
                            select p).ToList());
                });

                string matchedpid  = null;
                bool   isMatchMade = false;
                if (pipsmatches.Count == 0)
                {
                    //progress.WriteLine("Unmatched: {0} {1} {2}", item.r.disk_reference, item.r.programme_name, item.r.aired);
                }
                else if (pipsmatches.Count == 1)
                {
                    var p = pipsmatches.First();
                    if (PartialMatch.GetSimpleWeighting(item.r, p) > 0)
                    {
                        MakeMatch(ctx, item, p);
                        matchedpid  = p.pid;
                        isMatchMade = true;
                        //progress.WriteLine("Matched: {0} {1} {2} -> {3} {4} {5}", item.r.disk_reference, item.r.programme_name, item.r.aired, p.pid, p.display_title, p.start_gmt);
                    }
                }
                else
                {
                    //progress.WriteLine("Matched: {0} {1} {2} ->", item.r.disk_reference, item.r.programme_name, item.r.aired);
                    //foreach (var pipsmatch in pipsmatches)
                    //{
                    //    var p = pipsmatch;
                    //    progress.WriteLine("         -> {0} {1} {2}", p.pid, p.display_title, p.start_gmt);
                    //}
                    //matchedpid = pipsmatches.First().pid;
                }

                if (isMatchMade == false)
                {
                    pipsmatches = await TaskEx.Run <List <pips_programmes> >(() =>
                    {
                        DateTime fiveminutesbefore = item.r.aired.AddMinutes(-5);
                        DateTime fiveminutesafter  = item.r.aired.AddMinutes(5);
                        return((from p in ctx.pips_programmes
                                join rp in ctx.redux_to_pips on p.id equals rp.pips_id into joined
                                from j in joined.DefaultIfEmpty()
                                where j == null && p.start_gmt >= fiveminutesbefore &&
                                p.start_gmt <= fiveminutesafter &&
                                p.service_id == item.r.service_id
                                select p).ToList());
                    });

                    var suitable = pipsmatches.Where(p => PartialMatch.GetSimpleWeighting(item.r, p) > 0)
                                   .OrderByDescending(p => PartialMatch.GetSimpleWeighting(item.r, p))
                                   .OrderBy(p => Math.Abs((p.start_gmt - item.r.aired).TotalSeconds))
                                   .OrderBy(p => Math.Abs(p.duration - item.r.duration))
                                   .ToList();
                    if (suitable.Count > 0)
                    {
                        pips_programmes matchedpips = suitable.First();
                        MakeMatch(ctx, item, matchedpips);
                        isMatchMade = true;
                        matchedpid  = matchedpips.pid;
                    }
                }

                if (matchedpid != null)
                {
                    thumbnails.ShowImage("http://node2.bbcimg.co.uk/iplayer/images/episode/" + matchedpid + "_314_176.jpg");
                }
                if (isMatchMade == false)
                {
                    progress.WriteLine("Failed to match {0} {1} {2}", item.r.programme_name, item.r.disk_reference, item.r.aired);
                }
            }
            MessageBox.Show("Finished matching unmatched items");
        }