Wednesday, July 28, 2010

The Bong Parser

BongParser.exe is a console application written in C#. I have developed and tested it on my windows system, but thanks to Mono it runs without any changes on my Linux Box. (DS209). 

What does it do:
  • it is executed via cron-job every 30 minutes.
  • read settings from config file (BongParser.exe.config)
  • Read current recordings from Bong.TV server. It comes in the shape of a xml-file which has to be downloaded via http-get.
  • parse xml and create a list of recordings (List<Recordings> itemList)
The structure looks like this:

    class Recordings
        public int Refnr { get; set; }
        public int BongId { get; set; }
        public string Title { get; set; }
        public string Description { get; set; }
        public string Channel { get; set; }
        public DateTime BroadcastDate { get; set; }
        public TimeSpan Duration { get; set; }
        public string ImageUrl { get; set; }
        public string Quality { get; set; }
        public string MediaUrl { get; set; }
        public string MediaFilename { get; set; }
        public int Status { get; set; }
        public int Deleted { get; set; }
        public DateTime StartDate { get; set; }
        public DateTime FinishDate { get; set; }
        public int Retries { get; set; }
        public string Category { get; set; }
        public int Progress { get; set; }
        public string ErrorText { get; set; }
  • inserts each of the items of the list into the MySQL database (table content). It checks of course if the item allready exists in the database (checks this via BongId).
  • checks if there are hanging downloads. (This is done via the FinishDate. If Status = Downloading and FinishDate is more than 0.5 x Duration away from the current time, a hanging download is detected). In this case the entry is reset. (Status -> Waiting, Progress -> 0%, etc.)
  • checks if entries are successfully downloaded. In this case the recording is deleted from the Bong.TV server via http-delete.
  • a logfile is written (for each step)
  • applications exits

No comments:

Post a Comment