Beispiel #1
0
        }// -----------------------------------------

        // --
        public override void start()
        {
            base.start();

            p = (RestoreParams)jobData;

            log("Restoring track -" + track.storedFileName);

            // --
            crushedTrackPath = Path.Combine(p.tempDir, track.storedFileName);
            // Set the final track pathname now, I need this for later.
            track.workingFile = Path.Combine(p.tempDir, track.getFilenameRaw());

            // --
            if (track.isData)
            {
                var ecm = new EcmTools(CDCRUSH.TOOLS_PATH);
                ecm.onComplete = (s) => {
                    if (s)
                    {
                        deleteOldFile();
                        if (!checkTrackMD5())
                        {
                            fail(msg: "MD5 checksum is wrong!");
                            return;
                        }
                        complete();
                    }
                    else
                    {
                        fail(msg: ecm.ERROR);
                    }
                };
                ecm.unecm(crushedTrackPath);
                killExtra = () => ecm.kill();
            }
            else
            {
                if (Path.GetExtension(track.storedFileName) == ".ogg")
                {
                    isOgg = true;
                }
                else
                {
                    isFlac = true;             // must be flac
                }

                var ffmp = new FFmpeg(CDCRUSH.FFMPEG_PATH);
                ffmp.onComplete = (s) => {
                    if (s)
                    {
                        deleteOldFile();                 // Don't need it
                        if (isOgg)
                        {
                            correctPCMSize();
                        }
                        if (isFlac)
                        {
                            if (!checkTrackMD5())
                            {
                                fail(msg: "MD5 checksum is wrong!");
                                return;
                            }
                        }
                        complete();
                    }
                    else
                    {
                        fail(msg: ffmp.ERROR);
                    }
                };

                ffmp.audioToPCM(crushedTrackPath);
                killExtra = () => ffmp.kill();
            }
        }// -----------------------------------------
        }// -----------------------------------------

        // --
        public override void start()
        {
            base.start();

            p = (CrushParams)jobData;

            // Working file is already set and points to either TEMP or INPUT folder
            sourceTrackFile = track.workingFile;

            // Before compressing the tracks, get and store the MD5 of the track
            using (var md5 = System.Security.Cryptography.MD5.Create())
            {
                using (var str = File.OpenRead(sourceTrackFile))
                {
                    track.md5 = BitConverter.ToString(md5.ComputeHash(str)).Replace("-", "").ToLower();
                }
            }

            // --
            if (track.isData)
            {
                var ecm = new EcmTools(CDCRUSH.TOOLS_PATH);
                ecm.onProgress = handleProgress;
                ecm.onComplete = (s) => {
                    if (s)
                    {
                        deleteOldFile();
                        complete();
                    }
                    else
                    {
                        fail(msg: ecm.ERROR);
                    }
                };

                // In case the task ends abruptly
                killExtra = () => ecm.kill();

                // New filename that is going to be generated:
                setupFiles(".bin.ecm");
                ecm.ecm(sourceTrackFile, track.workingFile); // old .bin file from wherever it was to temp/bin.ecm
            }
            else                                             // AUDIO TRACK :
            {
                var ffmp = new FFmpeg(CDCRUSH.FFMPEG_PATH);
                ffmp.onProgress = handleProgress;
                ffmp.onComplete = (s) => {
                    if (s)
                    {
                        deleteOldFile();
                        complete();
                    }
                    else
                    {
                        fail(msg: ffmp.ERROR);
                    }
                };

                // In case the task ends abruptly
                killExtra = () => ffmp.kill();

                // Cast for easy coding
                Tuple <int, int> audioQ = jobData.audioQuality;

                // NOTE: I know this redundant, but it works :
                switch (audioQ.Item1)
                {
                case 0:                 // FLAC
                    setupFiles(".flac");
                    ffmp.audioPCMToFlac(sourceTrackFile, track.workingFile);
                    break;

                case 1:                 // VORBIS
                    setupFiles(".ogg");
                    ffmp.audioPCMToOggVorbis(sourceTrackFile, audioQ.Item2, track.workingFile);
                    break;

                case 2:                 // OPUS
                    setupFiles(".ogg");
                    // Opus needs an actual bitrate, not an index
                    ffmp.audioPCMToOggOpus(sourceTrackFile, FFmpeg.OPUS_QUALITY[audioQ.Item2], track.workingFile);
                    break;

                case 3:                 // MP3
                    setupFiles(".mp3");
                    ffmp.audioPCMToMP3(sourceTrackFile, audioQ.Item2, track.workingFile);
                    break;
                } //- end switch
            }     //- end if (track.isData)
        }// -----------------------------------------
        }// -----------------------------------------

        // --
        public override void start()
        {
            base.start();

            p = (RestoreParams)jobData;

            // --
            crushedTrackPath = Path.Combine(p.tempDir, track.storedFileName);
            // Set the final track pathname now, I need this for later.
            track.workingFile = Path.Combine(p.tempDir, track.getFilenameRaw());

            // --
            if (track.isData)
            {
                var ecm = new EcmTools(CDCRUSH.TOOLS_PATH);
                ecm.onComplete = (s) => {
                    ecm.onProgress = handleProgress;
                    if (s)
                    {
                        deleteOldFile();
                        if (!checkTrackMD5())
                        {
                            fail(msg: "MD5 checksum is wrong!");
                            return;
                        }
                        complete();
                    }
                    else
                    {
                        fail(msg: ecm.ERROR);
                    }
                };
                ecm.unecm(crushedTrackPath);
                killExtra = () => ecm.kill();
            }
            else
            {
                // No need to convert back
                if (p.flag_encCue)
                {
                    // Fix current file
                    track.workingFile = crushedTrackPath;
                    complete();
                    return;
                }

                // --
                isFlac = (Path.GetExtension(track.storedFileName) == ".flac");

                var ffmp = new FFmpeg(CDCRUSH.FFMPEG_PATH);
                ffmp.onProgress = handleProgress;
                ffmp.onComplete = (s) => {
                    if (s)
                    {
                        deleteOldFile();                 // Don't need it
                        if (!isFlac)
                        {
                            // OGG and MP3 don't restore to the exact byte length
                            correctPCMSize();
                        }
                        else
                        {
                            // FLAC restores to exact bytes
                            if (!checkTrackMD5())
                            {
                                fail(msg: "MD5 checksum is wrong!");
                                return;
                            }
                        }
                        complete();
                    }
                    else
                    {
                        fail(msg: ffmp.ERROR);
                    }
                };

                ffmp.audioToPCM(crushedTrackPath);
                killExtra = () => ffmp.kill();
            }

            log("Restoring track -" + track.storedFileName);
        }// -----------------------------------------
        }// -----------------------------------------

        // --
        public override void start()
        {
            base.start();

            p = (CrushParams)jobData;

            // Working file is already set and points to either TEMP or INPUT folder
            trackFile = track.workingFile;

            // Before compressing the tracks, get and store the MD5 of the track
            using (var md5 = System.Security.Cryptography.MD5.Create())
            {
                using (var str = File.OpenRead(trackFile))
                {
                    track.md5 = BitConverter.ToString(md5.ComputeHash(str)).Replace("-", "").ToLower();
                }
            }

            // --
            if (track.isData)
            {
                var ecm = new EcmTools(CDCRUSH.TOOLS_PATH);
                ecm.onComplete = (s) => {
                    if (s)
                    {
                        deleteOldFile();
                        complete();
                    }
                    else
                    {
                        fail(msg: ecm.ERROR);
                    }
                };

                // In case the task ends abruptly
                killExtra = () => ecm.kill();

                // New filename that is going to be generated:
                track.storedFileName = track.getTrackName() + ".bin.ecm";
                track.workingFile    = Path.Combine(jobData.tempDir, track.storedFileName);
                ecm.ecm(trackFile, track.workingFile); // old .bin file from wherever it was to temp/bin.ecm
            }
            else                                       // AUDIO TRACK :
            {
                var ffmp = new FFmpeg(CDCRUSH.FFMPEG_PATH);
                ffmp.onComplete = (s) => {
                    if (s)
                    {
                        deleteOldFile();
                        complete();
                    }
                    else
                    {
                        fail(msg: ffmp.ERROR);
                    }
                };

                // In case the task ends abruptly
                killExtra = () => ffmp.kill();

                // Cast for easy coding
                Tuple <int, int> audioQ = jobData.audioQuality;

                switch (audioQ.Item1)
                {
                case 0:                 // FLAC
                    track.storedFileName = track.getTrackName() + ".flac";
                    track.workingFile    = Path.Combine(jobData.tempDir, track.storedFileName);
                    ffmp.audioPCMToFlac(trackFile, track.workingFile);
                    break;

                case 1:                 // VORBIS
                    track.storedFileName = track.getTrackName() + ".ogg";
                    track.workingFile    = Path.Combine(jobData.tempDir, track.storedFileName);
                    ffmp.audioPCMToOggVorbis(trackFile, audioQ.Item2, track.workingFile);
                    break;

                case 2:                 // OPUS
                    track.storedFileName = track.getTrackName() + ".ogg";
                    track.workingFile    = Path.Combine(jobData.tempDir, track.storedFileName);
                    ffmp.audioPCMToOggOpus(trackFile, CDCRUSH.OPUS_QUALITY[audioQ.Item2], track.workingFile);
                    break;
                } //- end switch
            }     //- end if (track.isData)
        }// -----------------------------------------