Пример #1
0
        public EPGMetaFile(EPGAccess access, int rid)
        {
            this.Meta  = access.GetRecordProgramByID(rid);
            this.mLogo = access.GetChannelLogoBytesByID(this.Meta.channelId);
            byte[] tmp = null;
            int    i   = 0;

            while ((tmp is null) & (i <= 3))
            {
                System.Threading.Tasks.Task.Delay(1000);
                tmp = access.GetRecordedThumbnailBytesByID(rid);
                i++;
            }
            this.mThumb = tmp;
        }
Пример #2
0
        /// <summary>
        /// Get <see cref="StreamFile"/> object from EPGStation's recorded file <see cref="Program"/>.
        /// </summary>
        /// <param name="body"></param>
        /// <param name="mEPG">A working access to EPGStation.</param>
        /// <returns></returns>
        public static StreamFile GetStreamFileObj(this Program body, EPGAccess mEPG)
        {
            if (body == null)
            {
                return(null);
            }
            StreamFile mFile = new StreamFile();

            mFile.ChannelName    = mEPG.GetChannelNameByID(body.channelId);
            mFile.Content        = body.description;
            mFile.Infomation     = body.extended;
            mFile.Title          = body.name;
            mFile.recTitle       = body.name;
            mFile.recKeyWord     = "EPGStation " + body.id.ToString();
            mFile.recSubTitle    = body.videoResolution + body.videoResolution + body.videoType;
            mFile.recKeywordInfo = string.Format("Error:E({0})D({1})S({2})", body.errorCnt, body.dropCnt, body.scramblingCnt);
            mFile.Genre          = body.Genre;
            mFile.StartTime      = GetTimeFromUNIXTime(body.startAt);
            mFile.EndTime        = GetTimeFromUNIXTime(body.endAt);
            mFile.FilePath       = System.IO.Path.Combine(mEPG.BaseFolder, System.Web.HttpUtility.UrlDecode(body.filename));
            mFile.EPGStation     = new EPGMetaFile(mEPG, body);
            return(mFile);
        }
Пример #3
0
        private static bool MoveFile(StreamFile para, SettingObj mySetting, EPGAccess epgAccess = null)
        {
            if (!System.IO.File.Exists(para.FilePath))
            {
                return(false);                                       // Ops! file is not there.
            }
            string fileName = System.IO.Path.GetFileName(para.FilePath);

            string[] FolderList   = System.IO.Directory.GetDirectories(mySetting.StorageFolder); //Get local preset base folder's child folers.
            string   Targetfolder = mySetting.StorageFolder;
            RmtFile  mFile        = new RmtFile();                                               // Object for Upload process

            if (!string.IsNullOrWhiteSpace(mySetting.GetFolderTag(para.Genre)))
            {
                try //try get full path of genre folder.
                {
                    Targetfolder = FolderList.First(x => Strings.InStr(x, mySetting.GetFolderTag(para.Genre)) > 0);
                }
                catch (Exception e)// In case the preset genre folder is not there.
                {
                    Targetfolder = System.IO.Path.Combine(mySetting.StorageFolder, mySetting.GetFolderTag(para.Genre));
                    Console.WriteLine(e.Message);
                }
            }
            if (!System.IO.Directory.Exists(Targetfolder)) //if genre folder is not there make one.
            {
                System.IO.Directory.CreateDirectory(Targetfolder);
            }
            if (para.Genre.HasFlag(ProgramGenre.Anime) || para.Genre.HasFlag(ProgramGenre.Drama) || para.Genre.HasFlag(ProgramGenre.Variety))
            {                                                            // those programs has genre of anime drama or variety could be in series. if that is the case make a folder to hold them.
                string programName = MasterHelper.FindTitle(para.Title); //find title.
                if (!programName.Equals(para.Title))                     // if the title find by program doesn't match it's full name means it's in a series.
                {
                    FolderList = System.IO.Directory.GetDirectories(Targetfolder);
                    try // from here on is basicly copy plast the folder exist thing.
                    {
                        Targetfolder = FolderList.First(x =>
                        { // find a folder matchs series name
                            var str = x.Substring(x.LastIndexOf(@"\") + 1);
                            str     = str.Substring(str.IndexOf("]") + 1);
                            return(Strings.InStr(x, programName) > 0 ||
                                   Strings.InStr(x, Strings.StrConv(programName, VbStrConv.Wide)) > 0 ||
                                   Strings.InStr(programName, str) > 0 ||
                                   Strings.InStr(Strings.StrConv(programName, VbStrConv.Wide), str) > 0);
                        });
                    }
                    catch (Exception e)
                    { //no match so far so make a one.
                        Targetfolder = System.IO.Path.Combine(Targetfolder, MasterHelper.GetTimeSpan(para.StartTime, para.StartTime) + programName);
                        Console.WriteLine("Try find folder : " + e.Message);
                    }
                    mFile.FullFilePath = System.IO.Path.Combine(Targetfolder, fileName);
                    //this will make sure the date period at the head of folder name is correct.
                    if (MasterHelper.RenameDirUpToDate(ref Targetfolder, para.EndTime))
                    {//this is for upload process . notify that the folder name has been changed.
                        mFile.OldFatherName  = System.IO.Path.GetFileName(System.IO.Path.GetDirectoryName(mFile.FullFilePath));
                        mFile.IsFatherUpdate = true;
                        mFile.FullFilePath   = System.IO.Path.Combine(Targetfolder, fileName);
                    }
                    Console.WriteLine("Target folder is : " + Targetfolder);
                    if (!System.IO.Directory.Exists(Targetfolder))
                    {
                        System.IO.Directory.CreateDirectory(Targetfolder);
                        "Create folder: {0}".InfoLognConsole(Targetfolder);
                    }
                }
                //Move file to where it belongs.
                FileMovier(para.FilePath, System.IO.Path.Combine(Targetfolder, fileName));
                para.FilePath = System.IO.Path.Combine(Targetfolder, fileName);
                if (epgAccess == null)
                {// if the epgAccess is null means this process is called by tvrock
                    //no need to get extra information from server.
                    //XML file is standerd meta data format for tvrock for now.
                    para.ToXml(System.IO.Path.Combine(Targetfolder, fileName));
                }
                else
                {// this process is called by epgstation or else.
                    //information is from server, it will be stored in a
                    //*.meta file, it could also include a station logo and a thumbnail of video.
                    var tmp = para.EPGStation.WtiteFile(System.IO.Path.Combine(Targetfolder, fileName));
                    if (tmp)
                    {
                        epgAccess.DeleteRecordByID(para.EPGStation.Meta.id);
                    }
                }
                //comit upload
                AddToDatabase(mFile, mySetting, para.StartTime);
                OKBeep(mySetting); // beep
            }
            else
            {
                mFile.FullFilePath = System.IO.Path.Combine(Targetfolder, fileName);
                FileMovier(para.FilePath, System.IO.Path.Combine(Targetfolder, fileName));
                para.FilePath = System.IO.Path.Combine(Targetfolder, fileName);
                if (epgAccess == null)
                {
                    para.ToXml(System.IO.Path.Combine(Targetfolder, fileName));
                }
                else
                {
                    var tmp = para.EPGStation.WtiteFile(System.IO.Path.Combine(Targetfolder, fileName));
                    if (tmp)
                    {
                        epgAccess.DeleteRecordByID(para.EPGStation.Meta.id);
                    }
                }
                //Do upload same here..
                AddToDatabase(mFile, mySetting, para.StartTime);
                OKBeep(mySetting);
            }
            return(true);
        }
Пример #4
0
        public static bool SortFile(string[] margs)
        {
            "App started.".InfoLognConsole();
            SettingObj mySetting = null;
            bool       a         = false;

            while (!a)
            {
                Console.WriteLine("Reading settings.");

                try
                {
                    mySetting = SettingObj.Read();
                    //mySetting = ((dynamic)Activator.CreateInstance(SettingObj)).Read();
                    a = true;
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error : {0}", ex.Message);
                    "Fail to read settings [{0}]".InfoLognConsole(ex.Message);
                    Console.WriteLine("Sleep 10 sec...");
                    System.Threading.Tasks.Task.Delay(10000);
                }
            }
            EPGAccess  mAccess = null;
            StreamFile mpars   = null;

            if (margs.Any(x => x.Equals("-main", StringComparison.OrdinalIgnoreCase)))
            {
                var wpfwindow = new MasterView.MasterViewControl();
                ElementHost.EnableModelessKeyboardInterop(wpfwindow);
                if (wpfwindow.ShowDialog() == true)
                {
                    return(true);
                }
            }
            if (margs.Any(x => x.Equals("-mirakurun", StringComparison.OrdinalIgnoreCase)))
            {
                var wpfwindow = new MirakurunWarpper.MirakurunViewer();
                ElementHost.EnableModelessKeyboardInterop(wpfwindow);
                if (wpfwindow.ShowDialog() == true)
                {
                    return(true);
                }
            }
            if (margs.Any(x => x.Equals("-setup", StringComparison.OrdinalIgnoreCase)))
            {
                var wpfwindow = new MasterView.Setting();
                ElementHost.EnableModelessKeyboardInterop(wpfwindow);
                if (wpfwindow.ShowDialog() == true)
                {
                    return(true);
                }
            }
            if (margs.Any(x => x.Equals("-rcdbview", StringComparison.OrdinalIgnoreCase)))
            {
                var wpfwindow = new MasterView.RecordedListView();
                ElementHost.EnableModelessKeyboardInterop(wpfwindow);
                if (wpfwindow.ShowDialog() == true)
                {
                    return(true);
                }
            }
            if (margs.Any(x => x.Equals("-cloud", StringComparison.OrdinalIgnoreCase)))
            {
                var wpfwindow = new MasterView.CloudViewer();
                ElementHost.EnableModelessKeyboardInterop(wpfwindow);
                if (wpfwindow.ShowDialog() == true)
                {
                    return(true);
                }
            }
            if (margs.Any(x => x.Equals("-upload", StringComparison.OrdinalIgnoreCase)))
            {
                var wpfwindow = new MasterView.Uploader();
                ElementHost.EnableModelessKeyboardInterop(wpfwindow);
                if (wpfwindow.ShowDialog() == true)
                {
                    return(true);
                }
            }
            if (margs.Any(x => x.Equals("-epgstation", StringComparison.OrdinalIgnoreCase)))
            {
                Console.WriteLine("-=-=-=-=-=-=-=-=-=-=-=EPGstation=-=-=-=-=-=-=-=-=-=-=-");
                // Start process the parameters, group them to their own entries.
                List <string> clPara = new List <string>();
                if (margs.Count() <= 1)
                {
                    return(false);/* TODO Change to default(_) if this is not a reference type */
                }
                System.Text.StringBuilder sbb = new System.Text.StringBuilder();
                foreach (var p in margs)
                {
                    if (p.StartsWith("-"))
                    {
                        var tmp = sbb.ToString();
                        if (tmp.Length > 1 && tmp.StartsWith("-"))
                        {
                            clPara.Add(tmp);
                        }
                        sbb.Clear(); // Clear the stringbuilder every time it hits the char "-"
                        sbb.Append(p);
                    }
                    else
                    {
                        sbb.AppendFormat(" {0}", p);
                    }
                }
                "App start with parameter\"{0}\"".InfoLognConsole(sbb.ToString());
                clPara.Add(sbb.ToString()); // Lack of the last run in the loop, so add the last parameter manuly.
                int  id      = -1;
                bool t_check = false;
                try
                {//first see para -id
                    t_check = int.TryParse(clPara.First(x => x.StartsWith("-id")).Substring(4), out id);
                }
                catch
                {
                    t_check = false;
                }
                if (!t_check)
                {//if -id is not working, try get enviroment variable. maybe not working.
                    "parameter -id not found or not a number.".ErrorLognConsole();
                    var e_id = Environment.GetEnvironmentVariable("RECORDEDID");
                    if (!e_id.IsNullOrEmptyOrWhiltSpace() && !int.TryParse(e_id, out id))
                    {
                        "Failed to find \"RECORDEDID\" from Enviorment variable".ErrorLognConsole();
                        "App catch error. exiting...".InfoLognConsole();
                        return(false);
                    }
                    "Environment Variable \"RECORDEDID={0}\"".InfoLognConsole(id.ToString());
                }
                Console.WriteLine("Preparing for access Epgstation server.");
                mAccess = new EPGAccess(mySetting);
                mpars   = mAccess.GetStreamFileObj(id);
                if (mpars == null)
                {
                    "Remote file is missing or \"ID:{0}\" does not exsits.".ErrorLognConsole(id.ToString());
                    "App catch error. exiting...".InfoLognConsole();
                    return(false);
                }
                if (mpars.ChannelName.IsNullOrEmptyOrWhiltSpace())
                {
                    string channel = "";
                    try
                    {
                        channel = clPara.First(x => x.StartsWith("-cn")).Substring(4);
                    }
                    catch
                    {
                        channel = "UNKNOW";
                    }
                    finally
                    {
                        mpars.ChannelName = channel;
                    }
                }
            }
            else
            {
                mpars = GetPara(margs);
            }
            if (mpars == null)
            {
                return(false);
            }
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            foreach (var p in margs)
            {
                sb.Append(p + " ");
            }
            PrintInfomation(mpars);
            if (!MoveFile(mpars, mySetting, mAccess))
            {
                "Local file is missing : \"File:{0}\" does not exsit.".ErrorLognConsole(System.IO.Path.GetFileName(mpars.FilePath));
                "App catch error. exiting...".InfoLognConsole();
                return(false);
            }
            ;
            "App has completed job. exiting...".InfoLognConsole();
            return(true);
        }