コード例 #1
0
ファイル: Dvds.cs プロジェクト: rlittletht/UpcInv
        void AddDVDToUpdateQueue(DvdElementEx dvdex, DVD.ScrapeSet scrapedSet)
        {
            StreamWriter sw = new StreamWriter(m_config.SqlFile, true /*fAppend*/, System.Text.Encoding.Default);

            sw.WriteLine(BuildSetString(dvdex, null, scrapedSet));
            sw.Close();
        }
コード例 #2
0
ファイル: Dvds.cs プロジェクト: rlittletht/UpcInv
        void LogDvdUpdateError(DvdElementEx dvdex, DVD.ScrapeSet scrapedSet, string sReason)
        {
            StreamWriter swSql = new StreamWriter(m_config.SqlFile, true /*fAppend*/, System.Text.Encoding.Default);
            StreamWriter swLog = new StreamWriter(m_config.LogFile, true /*fAppend*/, System.Text.Encoding.Default);

            swLog.WriteLine($"{dvdex.ScanCode}: {dvdex.Title}: FAILED: {sReason}");
            swLog.Close();

            swSql.WriteLine(BuildSetString(dvdex, " -- FAILED QUERY!", scrapedSet));

            swSql.Close();
        }
コード例 #3
0
ファイル: Dvds.cs プロジェクト: rlittletht/UpcInv
        string BuildSetString(DvdElementEx dvdex, string sComment, DVD.ScrapeSet set)
        {
            List <string> plsSet = new List <string>();

            UpdateStatus status = (UpdateStatus)dvdex.UpdateStatus;

            plsSet.Add(String.Format(" LastUpdate='{0}' ", DateTime.Now.ToString("d")));

            if (!String.IsNullOrEmpty(dvdex.MediaType) && set.HasFlag(DVD.ScrapeSet.MediaType))
            {
                plsSet.Add(String.Format(" MediaType='{0}' ", dvdex.MediaType));
                status |= UpdateStatus.MediaType;
            }

            if (!String.IsNullOrEmpty(dvdex.Classification) && set.HasFlag(DVD.ScrapeSet.Categories))
            {
                plsSet.Add($" Classification='{Sql.Sqlify(dvdex.Classification)}' ");
                status |= UpdateStatus.Categories;
            }

            if (!String.IsNullOrEmpty(dvdex.CoverSrc) && set.HasFlag(DVD.ScrapeSet.CoverSrc))
            {
                plsSet.Add($" CoverSrc='{Sql.Sqlify(dvdex.CoverSrc)}' ");
                status |= UpdateStatus.CoverSrc;
            }

            if (!String.IsNullOrEmpty(dvdex.Summary) && set.HasFlag(DVD.ScrapeSet.Summary))
            {
                string s = Sql.Sqlify(dvdex.Summary);

                s = s.Replace("\n", "' + CHAR(13) + CHAR(10) + '");
                plsSet.Add($" Summary='{s}' ");
                status |= UpdateStatus.Summary;
            }

            StringBuilder sb = new StringBuilder(256);

            sb.Append($"UPDATE upc_DVD SET UpdateStatus={(int)status} ");

            foreach (string s in plsSet)
            {
                sb.Append(", ");
                sb.Append(s);
            }

            sb.Append($"WHERE ID='{dvdex.DvdID}'");
            if (!String.IsNullOrEmpty(sComment))
            {
                sb.Append(sComment);
            }

            return(sb.ToString());
        }
コード例 #4
0
ファイル: Dvds.cs プロジェクト: rlittletht/UpcInv
        private bool DownloadCoverForDvd(DvdElementEx dvdex, string sLocalRoot, string sLocalPath, out string sError)
        {
            sError = null;
            try
            {
                string sFullPath = Path.Combine(sLocalRoot, sLocalPath);

                if (!Directory.Exists(sFullPath))
                {
                    Directory.CreateDirectory(sFullPath);
                }

                Uri        uri = new Uri($"http://{dvdex.CoverSrc}");
                WebRequest req = WebRequest.Create(uri);

                string sPathname    = uri.GetComponents(UriComponents.Path, UriFormat.SafeUnescaped);
                string sFilename    = Path.GetFileName(sPathname);
                string sFullOutPath = Path.Combine(sFullPath, sFilename);
                string sOutPath     = $"{sLocalPath}\\{sFilename}";

                WebResponse response = req.GetResponse();

                Stream stream = response.GetResponseStream();
                Stream stmOut = new FileStream(sFullOutPath, FileMode.Create);

                stream.CopyTo(stmOut);
                stmOut.Close();
                stmOut.Dispose();
                stream.Close();
                stream.Dispose();
                response.Close();
                response.Dispose();

                dvdex.CoverSrc = sOutPath;
                return(true);
            }
            catch (Exception exc)
            {
                dvdex.CoverSrc = null;
                sError         = $"failed to download cover art: {dvdex.CoverSrc}: {exc.Message}";
                return(false);
            }
        }