Inheritance: Database
コード例 #1
0
        private void EpisodeImageContent(HttpListenerContext context)
        {
            Regex epidPattern = new Regex(@"^\?epid=([0-9]+)$");
            Match match       = epidPattern.Match(context.Request.Url.Query);

            int epid;

            if (!int.TryParse(match.Groups[1].Value, out epid))
            {
                // Request doesn't contain a valid episode id
                this.ErrorPage404(context);
                return;
            }

            Model.Episode episode;

            try
            {
                episode = new Model.Episode(epid);
            }
            catch (DataNotFoundException)
            {
                // Episode ID does not exist
                this.ErrorPage404(context);
                return;
            }

            CompressedImage image = episode.Image;

            if (image == null)
            {
                // Specified episode does not have an image
                this.ErrorPage404(context);
                return;
            }

            context.Response.ContentType = "image/png";

            // Find the appropriate codec for saving the image as a png
            System.Drawing.Imaging.ImageCodecInfo pngCodec = null;

            foreach (System.Drawing.Imaging.ImageCodecInfo codec in System.Drawing.Imaging.ImageCodecInfo.GetImageEncoders())
            {
                if (codec.MimeType == context.Response.ContentType)
                {
                    pngCodec = codec;
                    break;
                }
            }

            try
            {
                image.Image.Save(context.Response.OutputStream, pngCodec, null);
            }
            catch (HttpListenerException)
            {
                // Don't worry about dropped connections etc.
            }
        }
コード例 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EpisodeInfo" /> class with the values
 /// contained in the specified Episode object.
 /// </summary>
 /// <param name="epInfo">Episode object specifying initial values.</param>
 internal EpisodeInfo(Model.Episode epInfo)
     : this()
 {
     this.Name        = epInfo.Name;
     this.Description = epInfo.Description;
     this.Date        = epInfo.Date;
     this.Duration    = epInfo.Duration;
 }
コード例 #3
0
        private void TextFileNameFormat_TextChanged(object sender, EventArgs e)
        {
            Model.Programme dummyProg = new Model.Programme();
            dummyProg.Name = "Programme Name";

            Model.Episode dummyEp = new Model.Episode();
            dummyEp.Name = "Episode Name";
            dummyEp.Date = DateTime.Now;

            this.LabelFilenameFormatResult.Text = "Result: " + Model.Download.CreateSaveFileName(this.TextFileNameFormat.Text, dummyProg, dummyEp) + ".mp3";
        }
コード例 #4
0
        public DownloadHandler(int epid)
        {
            using (SQLiteCommand command = new SQLiteCommand("select pr.progid, pluginid, pr.image as progimg, ep.duration, ep.image as epimg, pr.extid as progextid, ep.extid as epextid from episodes as ep, programmes as pr where ep.epid=@epid and ep.progid=pr.progid", FetchDbConn()))
            {
                command.Parameters.Add(new SQLiteParameter("@epid", epid));

                using (SQLiteMonDataReader reader = new SQLiteMonDataReader(command.ExecuteReader()))
                {
                    if (!reader.Read())
                    {
                        throw new DataNotFoundException(epid, "Episode does not exist");
                    }

                    this.pluginId     = new Guid(reader.GetString(reader.GetOrdinal("pluginid")));
                    this.progExtId    = reader.GetString(reader.GetOrdinal("progextid"));
                    this.episodeExtId = reader.GetString(reader.GetOrdinal("epextid"));

                    this.progInfo    = new Model.Programme(reader.GetInt32(reader.GetOrdinal("progid")));
                    this.episodeInfo = new Model.Episode(epid);

                    this.providerProgInfo = new Provider.ProgrammeInfo(this.progInfo);

                    if (reader.IsDBNull(reader.GetOrdinal("progimg")))
                    {
                        this.providerProgInfo.Image = null;
                    }
                    else
                    {
                        this.providerProgInfo.Image = RetrieveImage(reader.GetInt32(reader.GetOrdinal("progimg")));
                    }

                    this.providerEpisodeInfo = new Provider.EpisodeInfo(this.episodeInfo);

                    if (reader.IsDBNull(reader.GetOrdinal("duration")))
                    {
                        this.providerEpisodeInfo.Duration = null;
                    }
                    else
                    {
                        this.providerEpisodeInfo.Duration = reader.GetInt32(reader.GetOrdinal("duration"));
                    }

                    if (reader.IsDBNull(reader.GetOrdinal("epimg")))
                    {
                        this.providerEpisodeInfo.Image = null;
                    }
                    else
                    {
                        this.providerEpisodeInfo.Image = RetrieveImage(reader.GetInt32(reader.GetOrdinal("epimg")));
                    }

                    using (SQLiteCommand extCommand = new SQLiteCommand("select name, value from episodeext where epid=@epid", FetchDbConn()))
                    {
                        extCommand.Parameters.Add(new SQLiteParameter("@epid", epid));

                        using (SQLiteMonDataReader extReader = new SQLiteMonDataReader(extCommand.ExecuteReader()))
                        {
                            while (extReader.Read())
                            {
                                this.providerEpisodeInfo.ExtInfo.Add(extReader.GetString(extReader.GetOrdinal("name")), extReader.GetString(extReader.GetOrdinal("value")));
                            }
                        }
                    }
                }
            }
        }
コード例 #5
0
        private static void CheckSubscriptions()
        {
            // Fetch the current subscriptions into a list, so that the reader doesn't remain open while
            // checking all of the subscriptions, as this blocks writes to the database from other threads
            List<Subscription> subscriptions = FetchAll();

            // Work through the list of subscriptions and check for new episodes
            foreach (Subscription subscription in subscriptions)
            {
                List<string> episodeExtIds = null;

                try
                {
                    episodeExtIds = GetAvailableEpisodes(subscription.Progid, false);
                }
                catch (ProviderException)
                {
                    // Ignore any unhandled provider exceptions
                    continue;
                }

                if (episodeExtIds != null)
                {
                    foreach (string episodeExtId in episodeExtIds)
                    {
                        int? epid = null;

                        try
                        {
                            epid = Episode.FetchInfo(subscription.Progid, episodeExtId);
                        }
                        catch (ProviderException)
                        {
                            // Ignore any unhandled provider exceptions
                            continue;
                        }

                        if (epid == null)
                        {
                            continue;
                        }

                        try
                        {
                            Episode.UpdateInfoIfRequired(epid.Value);
                        }
                        catch (ProviderException)
                        {
                            // Ignore any unhandled provider exceptions
                            continue;
                        }

                        if (!subscription.SingleEpisode)
                        {
                            Episode info = new Episode(epid.Value);

                            if (!info.AutoDownload)
                            {
                                // Don't download the episode automatically, skip to the next one
                                continue;
                            }
                            else if (info.Date.AddDays(14) < DateTime.Now)
                            {
                                // Stop checking the episodes for this subscription, this and the rest
                                // are past the automatic download threshold
                                break;
                            }
                        }

                        if (!Download.IsDownload(epid.Value))
                        {
                            Download.Add(new int[] { epid.Value });
                        }
                    }
                }
            }

            // Wait for 10 minutes to give a pause between each check for new episodes
            Thread.Sleep(600000);

            // Queue the next subscription check.  This is used instead of a loop as
            // it frees up a slot in the thread pool in case other actions are waiting.
            ThreadPool.QueueUserWorkItem(delegate { CheckSubscriptions(); });
        }
コード例 #6
0
        private void TextFileNameFormat_TextChanged(object sender, EventArgs e)
        {
            Model.Programme dummyProg = new Model.Programme();
            dummyProg.Name = "Programme Name";

            Model.Episode dummyEp = new Model.Episode();
            dummyEp.Name = "Episode Name";
            dummyEp.Date = DateTime.Now;

            this.LabelFilenameFormatResult.Text = "Result: " + Model.Download.CreateSaveFileName(this.TextFileNameFormat.Text, dummyProg, dummyEp) + ".mp3";
        }
コード例 #7
0
ファイル: Main.cs プロジェクト: kleopatra999/RadioDownloader
        private void ButtonAutoDownload_Click()
        {
            List<int> epids = new List<int>();

            foreach (ListViewItem item in this.ListEpisodes.SelectedItems)
            {
                epids.Add(Convert.ToInt32(item.Name, CultureInfo.InvariantCulture));
            }

            Model.Episode info = new Model.Episode(epids[0]);
            Model.Episode.SetAutoDownload(epids.ToArray(), !info.AutoDownload);
        }
コード例 #8
0
ファイル: Main.cs プロジェクト: kleopatra999/RadioDownloader
        private void Episode_Updated(int epid)
        {
            if (this.IsDisposed)
            {
                return;
            }

            if (this.InvokeRequired)
            {
                this.Invoke((MethodInvoker)delegate { this.Episode_Updated(epid); });
                return;
            }

            if (this.view.CurrentView == ViewState.View.ProgEpisodes)
            {
                Model.Episode info = new Model.Episode(epid);

                if ((int)this.view.CurrentViewData == info.Progid)
                {
                    ListViewItem item = this.ListEpisodes.Items[epid.ToString(CultureInfo.InvariantCulture)];
                    item = this.EpisodeListItem(info, item);

                    if (item.Selected)
                    {
                        this.ShowEpisodeInfo();
                    }
                }
            }
        }
コード例 #9
0
ファイル: Main.cs プロジェクト: kleopatra999/RadioDownloader
        private void ShowEpisodeInfo()
        {
            int progid = (int)this.view.CurrentViewData;

            if (this.ListEpisodes.SelectedItems.Count == 1)
            {
                int epid = Convert.ToInt32(this.ListEpisodes.SelectedItems[0].Name, CultureInfo.InvariantCulture);
                Model.Episode epInfo = new Model.Episode(epid);
                string infoText = string.Empty;

                if (epInfo.Description != null)
                {
                    infoText += epInfo.Description + Environment.NewLine + Environment.NewLine;
                }

                infoText += "Date: " + epInfo.Date.ToString("ddd dd/MMM/yy HH:mm", CultureInfo.CurrentCulture);
                infoText += TextUtils.DescDuration(epInfo.Duration) + Environment.NewLine;
                infoText += "Auto download: " + (epInfo.AutoDownload ? "Yes" : "No");

                this.SetSideBar(TextUtils.StripDateFromName(epInfo.Name, epInfo.Date), infoText, Model.Episode.GetImage(epid));
            }
            else
            {
                this.SetSideBar(Convert.ToString(this.ListEpisodes.SelectedItems.Count, CultureInfo.CurrentCulture) + " episodes selected", string.Empty, null);
            }

            List<ToolBarButton> buttons = new List<ToolBarButton>();
            buttons.Add(this.ButtonDownload);
            buttons.Add(this.ButtonSetAuto);

            if (Model.Favourite.IsFavourite(progid))
            {
                buttons.Add(this.ButtonRemFavourite);
            }
            else
            {
                buttons.Add(this.ButtonAddFavourite);
            }

            if (Model.Subscription.IsSubscribed(progid))
            {
                buttons.Add(this.ButtonUnsubscribe);
            }
            else
            {
                buttons.Add(this.ButtonSubscribe);
            }

            this.SetToolbarButtons(buttons.ToArray());
        }
コード例 #10
0
ファイル: Main.cs プロジェクト: kleopatra999/RadioDownloader
        private void ProgData_EpisodeAdded(int epid)
        {
            if (this.IsDisposed)
            {
                return;
            }

            if (this.InvokeRequired)
            {
                this.Invoke((MethodInvoker)delegate { this.ProgData_EpisodeAdded(epid); });
                return;
            }

            Model.Episode info = new Model.Episode(epid);

            ListViewItem addItem = this.EpisodeListItem(info, null);
            this.ListEpisodes.Items.Add(addItem);
        }
コード例 #11
0
        public DownloadHandler(int epid)
        {
            using (SQLiteCommand command = new SQLiteCommand("select pr.progid, pluginid, pr.image as progimg, ep.duration, ep.image as epimg, pr.extid as progextid, ep.extid as epextid from episodes as ep, programmes as pr where ep.epid=@epid and ep.progid=pr.progid", FetchDbConn()))
            {
                command.Parameters.Add(new SQLiteParameter("@epid", epid));

                using (SQLiteMonDataReader reader = new SQLiteMonDataReader(command.ExecuteReader()))
                {
                    if (!reader.Read())
                    {
                        throw new DataNotFoundException(epid, "Episode does not exist");
                    }

                    this.pluginId = new Guid(reader.GetString(reader.GetOrdinal("pluginid")));
                    this.progExtId = reader.GetString(reader.GetOrdinal("progextid"));
                    this.episodeExtId = reader.GetString(reader.GetOrdinal("epextid"));

                    this.progInfo = new Model.Programme(reader.GetInt32(reader.GetOrdinal("progid")));
                    this.episodeInfo = new Model.Episode(epid);

                    this.providerProgInfo = new ProgrammeInfo(this.progInfo);

                    if (reader.IsDBNull(reader.GetOrdinal("progimg")))
                    {
                        this.providerProgInfo.Image = null;
                    }
                    else
                    {
                        this.providerProgInfo.Image = Database.RetrieveImage(reader.GetInt32(reader.GetOrdinal("progimg")));
                    }

                    this.providerEpisodeInfo = new EpisodeInfo(this.episodeInfo);

                    if (reader.IsDBNull(reader.GetOrdinal("duration")))
                    {
                        this.providerEpisodeInfo.Duration = null;
                    }
                    else
                    {
                        this.providerEpisodeInfo.Duration = reader.GetInt32(reader.GetOrdinal("duration"));
                    }

                    if (reader.IsDBNull(reader.GetOrdinal("epimg")))
                    {
                        this.providerEpisodeInfo.Image = null;
                    }
                    else
                    {
                        this.providerEpisodeInfo.Image = Database.RetrieveImage(reader.GetInt32(reader.GetOrdinal("epimg")));
                    }

                    using (SQLiteCommand extCommand = new SQLiteCommand("select name, value from episodeext where epid=@epid", FetchDbConn()))
                    {
                        extCommand.Parameters.Add(new SQLiteParameter("@epid", epid));

                        using (SQLiteMonDataReader extReader = new SQLiteMonDataReader(extCommand.ExecuteReader()))
                        {
                            while (extReader.Read())
                            {
                                this.providerEpisodeInfo.ExtInfo.Add(extReader.GetString(extReader.GetOrdinal("name")), extReader.GetString(extReader.GetOrdinal("value")));
                            }
                        }
                    }
                }
            }
        }
コード例 #12
0
        public static string CreateSaveFileName(string formatString, Programme progInfo, Episode epInfo)
        {
            if (string.IsNullOrEmpty(formatString))
            {
                // The format string is an empty string, so the output must be an empty string
                return(string.Empty);
            }

            string fileName = formatString;

            // Convert %title% -> %epname% for backwards compatability
            fileName = fileName.Replace("%title%", "%epname%");

            // Make variable substitutions
            fileName = fileName.Replace("%progname%", progInfo.Name.Replace(Path.DirectorySeparatorChar, ' '));
            fileName = fileName.Replace("%epname%", epInfo.Name.Replace(Path.DirectorySeparatorChar, ' '));
            fileName = fileName.Replace("%hour%", epInfo.Date.ToString("HH", CultureInfo.CurrentCulture));
            fileName = fileName.Replace("%minute%", epInfo.Date.ToString("mm", CultureInfo.CurrentCulture));
            fileName = fileName.Replace("%day%", epInfo.Date.ToString("dd", CultureInfo.CurrentCulture));
            fileName = fileName.Replace("%month%", epInfo.Date.ToString("MM", CultureInfo.CurrentCulture));
            fileName = fileName.Replace("%shortmonthname%", epInfo.Date.ToString("MMM", CultureInfo.CurrentCulture));
            fileName = fileName.Replace("%monthname%", epInfo.Date.ToString("MMMM", CultureInfo.CurrentCulture));
            fileName = fileName.Replace("%year%", epInfo.Date.ToString("yy", CultureInfo.CurrentCulture));
            fileName = fileName.Replace("%longyear%", epInfo.Date.ToString("yyyy", CultureInfo.CurrentCulture));

            // Replace invalid file name characters with spaces (except for directory separators
            // as this then allows the flexibility of storing the downloads in subdirectories)
            foreach (char removeChar in Path.GetInvalidFileNameChars())
            {
                if (removeChar != Path.DirectorySeparatorChar)
                {
                    fileName = fileName.Replace(removeChar, ' ');
                }
            }

            // Replace runs of spaces with a single space
            fileName = Regex.Replace(fileName, " {2,}", " ");

            return(fileName.Trim());
        }
コード例 #13
0
        public static string FindFreeSaveFileName(string formatString, Programme progInfo, Episode epInfo, string baseSavePath)
        {
            string rootName = Path.Combine(baseSavePath, CreateSaveFileName(formatString, progInfo, epInfo));
            string savePath = rootName;

            // Make sure the save folder exists (to support subfolders in the save file name template)
            string saveDir = Path.GetDirectoryName(savePath);

            Directory.CreateDirectory(saveDir);

            string currentFileName = null;

            // If the passed episode info is actually a download, get it's current path
            if (typeof(Download) == epInfo.GetType())
            {
                currentFileName = ((Download)epInfo).DownloadPath;

                // Remove the extension from the current name if applicable
                if (currentFileName != null)
                {
                    int extensionPos = currentFileName.LastIndexOf('.');

                    if (extensionPos > -1)
                    {
                        currentFileName = currentFileName.Substring(0, extensionPos);
                    }
                }
            }

            int diffNum = 1;

            // Check for a pre-existing file with the same name (ignoring the current name for this file)
            while (Directory.GetFiles(saveDir, Path.GetFileName(savePath) + ".*").Length > 0 &&
                   savePath != currentFileName)
            {
                savePath = rootName + Convert.ToString(diffNum, CultureInfo.CurrentCulture);
                diffNum += 1;
            }

            return(savePath);
        }
コード例 #14
0
ファイル: Download.cs プロジェクト: ribbons/RadioDownloader
        public static string FindFreeSaveFileName(string formatString, Programme progInfo, Episode epInfo, string baseSavePath)
        {
            string rootName = Path.Combine(baseSavePath, CreateSaveFileName(formatString, progInfo, epInfo));
            string savePath = rootName;

            // Make sure the save folder exists (to support subfolders in the save file name template)
            string saveDir = Path.GetDirectoryName(savePath);
            Directory.CreateDirectory(saveDir);

            string currentFileName = null;

            // If the passed episode info is actually a download, get it's current path
            if (typeof(Download) == epInfo.GetType())
            {
                currentFileName = ((Download)epInfo).DownloadPath;

                // Remove the extension from the current name if applicable
                if (currentFileName != null)
                {
                    int extensionPos = currentFileName.LastIndexOf('.');

                    if (extensionPos > -1)
                    {
                        currentFileName = currentFileName.Substring(0, extensionPos);
                    }
                }
            }

            int diffNum = 1;

            // Check for a pre-existing file with the same name (ignoring the current name for this file)
            while (Directory.GetFiles(saveDir, Path.GetFileName(savePath) + ".*").Length > 0 &&
                   savePath != currentFileName)
            {
                savePath = rootName + Convert.ToString(diffNum, CultureInfo.CurrentCulture);
                diffNum += 1;
            }

            return savePath;
        }
コード例 #15
0
ファイル: Download.cs プロジェクト: ribbons/RadioDownloader
        public static string CreateSaveFileName(string formatString, Programme progInfo, Episode epInfo)
        {
            if (string.IsNullOrEmpty(formatString))
            {
                // The format string is an empty string, so the output must be an empty string
                return string.Empty;
            }

            string fileName = formatString;

            // Convert %title% -> %epname% for backwards compatability
            fileName = fileName.Replace("%title%", "%epname%");

            // Make variable substitutions
            fileName = fileName.Replace("%progname%", progInfo.Name.Replace(Path.DirectorySeparatorChar, ' '));
            fileName = fileName.Replace("%epname%", epInfo.Name.Replace(Path.DirectorySeparatorChar, ' '));
            fileName = fileName.Replace("%hour%", epInfo.Date.ToString("HH", CultureInfo.CurrentCulture));
            fileName = fileName.Replace("%minute%", epInfo.Date.ToString("mm", CultureInfo.CurrentCulture));
            fileName = fileName.Replace("%day%", epInfo.Date.ToString("dd", CultureInfo.CurrentCulture));
            fileName = fileName.Replace("%month%", epInfo.Date.ToString("MM", CultureInfo.CurrentCulture));
            fileName = fileName.Replace("%shortmonthname%", epInfo.Date.ToString("MMM", CultureInfo.CurrentCulture));
            fileName = fileName.Replace("%monthname%", epInfo.Date.ToString("MMMM", CultureInfo.CurrentCulture));
            fileName = fileName.Replace("%year%", epInfo.Date.ToString("yy", CultureInfo.CurrentCulture));
            fileName = fileName.Replace("%longyear%", epInfo.Date.ToString("yyyy", CultureInfo.CurrentCulture));

            // Replace invalid file name characters with spaces (except for directory separators
            // as this then allows the flexibility of storing the downloads in subdirectories)
            foreach (char removeChar in Path.GetInvalidFileNameChars())
            {
                if (removeChar != Path.DirectorySeparatorChar)
                {
                    fileName = fileName.Replace(removeChar, ' ');
                }
            }

            // Replace runs of spaces with a single space
            fileName = Regex.Replace(fileName, " {2,}", " ");

            return fileName.Trim();
        }
コード例 #16
0
        private static void CheckSubscriptions()
        {
            // Fetch the current subscriptions into a list, so that the reader doesn't remain open while
            // checking all of the subscriptions, as this blocks writes to the database from other threads
            List <Subscription> subscriptions = FetchAll();

            // Work through the list of subscriptions and check for new episodes
            foreach (Subscription subscription in subscriptions)
            {
                List <string> episodeExtIds = null;

                try
                {
                    episodeExtIds = GetAvailableEpisodes(subscription.Progid, false);
                }
                catch (ProviderException)
                {
                    // Ignore any unhandled provider exceptions
                    continue;
                }

                if (episodeExtIds != null)
                {
                    foreach (string episodeExtId in episodeExtIds)
                    {
                        int?epid = null;

                        try
                        {
                            epid = Episode.FetchInfo(subscription.Progid, episodeExtId);
                        }
                        catch (ProviderException)
                        {
                            // Ignore any unhandled provider exceptions
                            continue;
                        }

                        if (epid == null)
                        {
                            continue;
                        }

                        try
                        {
                            Episode.UpdateInfoIfRequired(epid.Value);
                        }
                        catch (ProviderException)
                        {
                            // Ignore any unhandled provider exceptions
                            continue;
                        }

                        if (!subscription.SingleEpisode)
                        {
                            Episode info = new Episode(epid.Value);

                            if (!info.AutoDownload)
                            {
                                // Don't download the episode automatically, skip to the next one
                                continue;
                            }
                            else if (info.Date.AddDays(14) < DateTime.Now)
                            {
                                // Stop checking the episodes for this subscription, this and the rest
                                // are past the automatic download threshold
                                break;
                            }
                        }

                        if (!Download.IsDownload(epid.Value))
                        {
                            Download.Add(new int[] { epid.Value });
                        }
                    }
                }
            }

            // Wait for 10 minutes to give a pause between each check for new episodes
            Thread.Sleep(600000);

            // Queue the next subscription check.  This is used instead of a loop as
            // it frees up a slot in the thread pool in case other actions are waiting.
            ThreadPool.QueueUserWorkItem(state => { CheckSubscriptions(); });
        }