コード例 #1
0
            public void RAR_EachFileInDir(RadProgressBar radProgress, string DirPath, bool NewThread = true, bool EpNumRARName = true, string Prefix = "")
            {
                _AHK ahk = new _AHK();

                if (NewThread)
                {
                    Thread imdbTVParseThread = new Thread(() => RAR_EachFileInDir(radProgress, DirPath, false, EpNumRARName, Prefix));
                    imdbTVParseThread.Start();
                }
                else
                {
                    _TelerikLib.RadProgress pro = new _TelerikLib.RadProgress();
                    _Lists lst = new _Lists();
                    _Parse prs = new _Parse();

                    string rar = @"C:\_Code\LucidProjects\ADBindex\ComPress\bin\Debug\Lib\rar.exe";

                    List <string> files = lst.FileList(DirPath);

                    pro.SetupProgressBar(radProgress, files.Count);

                    string RelativePath = "-ep";

                    string fileDir = ahk.FileDir(DirPath); int i = 0;
                    foreach (string file in files)
                    {
                        if (ahk.FileExt(file).ToUpper() == ".URL")
                        {
                            continue;
                        }


                        // extract season/ep number from file name
                        string epNum = prs.SeasonEpNums(file);

                        i++; pro.UpdateProgress(radProgress, ahk.FileName(file) + " " + i + "/" + files.Count);
                        string newRAR = fileDir + "\\" + Prefix + epNum + ".rar";

                        // use the file name as the zip file name
                        if (!EpNumRARName)
                        {
                            newRAR = fileDir + "\\" + ahk.FileNameNoExt(file) + ".rar";
                        }

                        if (File.Exists(newRAR))
                        {
                            continue;
                        }


                        string FIle = file.Replace(",", "`,");

                        string cmd = rar + " A -m0 " + RelativePath + " " + "\"" + newRAR + "\" \"" + FIle + "\"";
                        ahk.RunWait(cmd, "", "Hide");
                    }

                    ahk.MsgBox("Finished RARing " + files.Count + " Files");
                }
            }
コード例 #2
0
ファイル: _FileFolderExt.cs プロジェクト: yongzhi444/sharpAHK
        /// <summary>Returns File's Parent Directory Path</summary>
        /// <param name="FilePath">File Location to Parse</param>
        /// <param name="CheckIfExists">Option to check to see if FilePath exists - FileDir returns blank if file not found</param>
        public static string FileDir(this string FilePath, bool CheckIfExists = false)  //
        {
            _AHK ahk = new _AHK();

            return(ahk.FileDir(FilePath, CheckIfExists));
        }
コード例 #3
0
            // takes tiled screen shot to generate a single preview image - returns path to new preview image (blank if failed)
            public string VidCap_Tiles(string videoFilePath, string saveDir = "", int TilesWide = 3, int TilesTall = 3, string Scale = "320:240", string SaveFormat = "jpg", string CaptureOpt = "1000")
            {
                if (!ahk.isVideo(videoFilePath))
                {
                    sb(videoFilePath + " Not Recognized Video Format... Skipping");
                    return("");
                }

                VideoFile vidInfo = GetVideoInfo(videoFilePath);

                // Extract FPS From video Info returned

                //h264(Main)(avc1 / 0x31637661), yuv420p, 600x450, 750 kb / s, SAR 1:1 DAR 4:3, 29.97 fps, 29.97 tbr, 30k tbn, 59.94 tbc(default)



                int seconds      = vidInfo.Duration.TotalSeconds.ToInt(); //getDuration(videoFilePath);
                int egs          = TilesWide * TilesTall;                 // ex 3 x 3 = 9 segs - dfivide total time by 9 for even timing
                int shotDistance = seconds / egs;

                //TimeSpan t = TimeSpan.FromMilliseconds(shotDistance);
                TimeSpan t = TimeSpan.FromSeconds(shotDistance);

                int MinBetween            = t.Minutes; // # of minutes between tile shots (in video)
                int SecondsBetween        = t.Seconds; // # of seconds between tile shots (in video)
                int distanceBetweenFrames = (seconds * vidInfo.FPS).ToInt();

                //string SaveFormat = "jpg";
                //Scale = "0:0";
                int FrameCount = 1;

                //Scale = "320:240";

                //int TileX = 2;
                //int TileY = 3;
                //string Scale = "320:240";
                //string[] shots = new string[numShots];

                // default save dir under neath original file
                if (saveDir == "")
                {
                    saveDir = ahk.FileDir(videoFilePath) + "\\Previews";
                }

                string outImage = saveDir + "\\" + ahk.FileNameNoExt(videoFilePath) + "." + SaveFormat;

                if (File.Exists(outImage))
                {
                    return("");
                }


                outImage = saveDir + "\\" + ahk.FileNameNoExt(videoFilePath) + "_%03d" + SaveFormat;

                ahk.FileCreateDir(saveDir);

                string args = "";
                string opt  = CaptureOpt;



                //-i video.mkv -vf scale=500:-1 -t 10 -r 10 image.gif

                // one every 1000 frames, works but didn't alway fill all the boxes
                if (opt == "1000")
                {
                    args = " -ss 00:" + MinBetween + ":" + SecondsBetween + " -i \"" + videoFilePath + "\" -frames: " + FrameCount + " -vf \"select=not(mod(n\\,1000)),scale=" + Scale + ",tile=" + TilesWide + "x" + TilesTall + "\" \"" + outImage + "\"";
                }

                // one every 3000 frames - works but SLOWER
                if (opt == "3000")
                {
                    args = " -ss 00:" + MinBetween + ":" + SecondsBetween + " -i \"" + videoFilePath + "\" -vf \"select=not(mod(n\\,3000)),scale=" + Scale + ",tile=" + TilesWide + "x" + TilesTall + "\" \"" + outImage + "\"";
                }

                //string args = " -ss 00:" + MinBetween + ":" + SecondsBetween + " -i \"" + videoFilePath + "\" -vf \"-r 0.0033,scale=" + Scale + ",tile=" + TilesWide + "x" + TilesTall + "\" \"" + outImage + "\"";
                //string args = " -ss 00:" + MinBetween + ":" + SecondsBetween + " -i \"" + videoFilePath + "\" -vf \"select=not(mod(n\\,3500)),scale=" + Scale + ",tile=" + TilesWide + "x" + TilesTall + "\" \"" + outImage + "\"";

                // one frame per video (thumbnails no rows)
                if (opt == "1")
                {
                    args = " -ss 00:" + MinBetween + ":" + SecondsBetween + " -i \"" + videoFilePath + "\" -vf thumbnail,scale=" + Scale + " -frames:v 1 \"" + outImage + "\"";
                }

                // export ALL action frames (about 1K images in 40min example video)
                if (opt == "ActionFrames")
                {
                    args = "-i \"" + videoFilePath + "\" -vf \"select = 'eq(pict_type,PICT_TYPE_I)'\" -vsync vfr \"" + saveDir + "\\" + ahk.FileNameNoExt(videoFilePath) + "_%04d." + SaveFormat + "\"";
                }

                // One screen shot at specific time stamp
                if (opt == "TimeShot")
                {
                    args = " -i \"" + videoFilePath + "\" -ss 00:02:05.000 -vframes 1 \"" + saveDir + "\\" + ahk.FileNameNoExt(videoFilePath) + "." + SaveFormat + "\"";
                }

                // mosasic option - works
                if (opt == "Mosasic")
                {
                    args = " -i \"" + videoFilePath + "\" -vf select='gt(scene\\,0.5)',scale=" + Scale + ",tile -frames:v 5  \"" + outImage + "\"";
                }


                //args = "-ss 3 -i \"" + videoFilePath + "\" -vf \"select = gt(scene\\, 0.5)\" -frames:v 5 -vsync vfr \"" + outImage + "\"";
                //args = "-i \"" + videoFilePath + "\" -vf  \"select = gt(scene\\, 0.4),scale = 640:360\" -frames:v 5 \"" + outImage + "\"";
                //args = "-i \"" + videoFilePath + "\" -vf fps=1/60 \"" + outImage + "\""; // one image per minute
                //int dur = getDuration(videoFilePath);
                // 2,266 = 37 min video


                string FPS = "";  // number of frames to capture

                try
                {
                    int totalFPS = vidInfo.Duration.TotalSeconds.ToInt() / 10;  // divide total seconds by 10
                    FPS = "1/" + totalFPS.ToString();
                }
                catch { FPS = "1/60"; }  // 1 frame per min



                args = "-i \"" + videoFilePath + "\" -vf fps=" + FPS + " \"" + outImage + "\""; //


                ahk.FileAppend(videoFilePath, ahk.AppDir() + "\\FFMpeg_Log.txt");
                StartFFMpeg(args);


                if (File.Exists(outImage))
                {
                    return(outImage);
                }
                else
                {
                    return("");
                }
            }
コード例 #4
0
ファイル: _Parse.cs プロジェクト: brillyints/sharpAHK_Dev
        /// <summary>
        /// Extract Season/EpNum Format from FilePath (or string) and Return S00E00 Format
        /// </summary>
        /// <param name="FilePath">FilePath or String Containing Season/EpNum Info to Parse</param>
        /// <param name="RenameFile">Option to Replace Unformatted Season/EpNum with Standard S00E00 Naming Convention</param>
        /// <returns></returns>
        public string SeasonEpNums(string FilePath, bool RenameFile = false)
        {
            _AHK ahk = new _AHK();

            bool   msgDisp       = false;
            string FileNameNoExt = "";
            bool   FileFound     = false;
            string dir           = "";
            string ext           = "";


            if (RenameFile)
            {
                if (File.Exists(FilePath))
                {
                    FileNameNoExt = ahk.FileNameNoExt(FilePath);
                    ext           = ahk.FileExt(FilePath);
                    dir           = ahk.FileDir(FilePath);
                    FileFound     = true;
                }
            }
            else
            {
                if (FilePath.Contains(":"))
                {
                    FilePath      = FilePath.Replace(":", "-");
                    FileNameNoExt = ahk.FileNameNoExt(FilePath);
                }
                else
                {
                    FileNameNoExt = FilePath;
                }
            }

            FileNameNoExt = FileNameNoExt.Replace("x264", "");
            FileNameNoExt = FileNameNoExt.Replace("x265", "");
            FileNameNoExt = FileNameNoExt.Replace("720p", "");
            FileNameNoExt = FileNameNoExt.Replace("1080p", "");
            FileNameNoExt = FileNameNoExt.ToUpper();

            // nothing to do, name already matches format
            Regex regex = new Regex(@"S\d{2}E\d{2}");  // hawaii.five-0.2010.S08E01
            Match match = regex.Match(FileNameNoExt);

            if (match.Success)
            {
                //if (msgDisp) { ahk.MsgBox(match.Value); }
                return(match.Value);
            }


            // find 3 digit season/ep format, rename file to S00E00 Format
            regex = new Regex(@"(\.|_)\d{3}(\.|_)");   // "hawaii.five-0.2010.805.hdtv-lol"
            match = regex.Match(FileNameNoExt);
            if (match.Success)
            {
                string MatchText = match.Value;
                string seasonEp  = match.Value.Replace(".", "");
                seasonEp = match.Value.Replace("_", "");

                string season = ahk.FirstCharacters(seasonEp, 1);
                string ep     = ahk.LastCharacters(seasonEp, 2);
                seasonEp = "S0" + season + "E" + ep;

                if (FileFound && RenameFile)
                {
                    FileNameNoExt = FileNameNoExt.Replace(MatchText, "." + seasonEp + ".");
                    string newName = dir + "\\" + FileNameNoExt + ext;

                    bool renamed = ahk.FileRename(FilePath, newName);

                    if (msgDisp)
                    {
                        ahk.MsgBox("Renamed = " + renamed.ToString() + "\n\n" + FilePath + "\n\n" + newName);
                    }
                }

                return(seasonEp);
            }


            // find 3 digit season/ep format, rename file to S00E00 Format
            regex = new Regex(@"\.\d{1,2}X\d{2}(\.|_)");  // .4x23. OR .4x23_
            match = regex.Match(FileNameNoExt);
            if (match.Success)
            {
                string MatchText = match.Value;
                string seasonEp  = match.Value.Replace(".", "");
                seasonEp = match.Value.Replace("_", "");

                string season = ahk.FirstCharacters(seasonEp, 1);
                string ep     = ahk.LastCharacters(seasonEp, 2);
                seasonEp = "S0" + season + "E" + ep;

                if (FileFound && RenameFile)
                {
                    FileNameNoExt = FileNameNoExt.Replace(MatchText, "." + seasonEp + ".");
                    string newName = dir + "\\" + FileNameNoExt + ext;

                    bool renamed = false;

                    renamed = ahk.FileRename(FilePath, newName);

                    if (msgDisp)
                    {
                        ahk.MsgBox("Renamed = " + renamed.ToString() + "\n\n" + FilePath + "\n\n" + newName);
                    }
                }

                return(seasonEp);
            }


            regex = new Regex(@"\.\d{1-2}X\d{1-2}\.");   // 7th_heaven.6x02.teased.dvdrip_xvid-fov
            match = regex.Match(FileNameNoExt);
            if (match.Success)
            {
                string seasonEp = match.Value.Replace(".", "");
                string season   = ahk.FirstCharacters(seasonEp, 1);
                string ep       = ahk.LastCharacters(seasonEp, 2);
                seasonEp = "S0" + season + "E" + ep.AddLeadingZeros(2);
                if (msgDisp)
                {
                    ahk.MsgBox(seasonEp);
                }
                return(seasonEp);
            }

            regex = new Regex(@"\d{4}.\d{2}.d{2}");   // conan.2018.01.18.gerard.butler.720p.web.x264 - tbs
            match = regex.Match(FileNameNoExt);
            if (match.Success)
            {
                if (msgDisp)
                {
                    ahk.MsgBox(match.Value);
                }

                //string seasonEp = match.Value.Replace(".", "");
                string seasonEp = match.Value;
                return(seasonEp);
            }

            regex = new Regex(@"\d{4}\s\d{2}\s\d{2}");   // conan 2018 01 18 gerard butler 720p web x264 - tbs
            match = regex.Match(FileNameNoExt);
            if (match.Success)
            {
                if (msgDisp)
                {
                    ahk.MsgBox(match.Value);
                }
                return(match.Value);
            }


            regex = new Regex(@"\d{4}");   // hap.and.leonard.0304-yestv
            match = regex.Match(FileNameNoExt);
            if (match.Success)
            {
                string seasonEp = match.Value.Replace(".", "");
                string season   = ahk.FirstCharacters(seasonEp, 2);
                string ep       = ahk.LastCharacters(seasonEp, 2);
                seasonEp = "S" + season + "E" + ep.AddLeadingZeros(2);
                if (msgDisp)
                {
                    ahk.MsgBox(seasonEp);
                }
                return(seasonEp);
            }



            return("");
        }