public Mp3Split(CueSheet s)
        {
            int error = 0;

            _sheet = s;

            _mp3_state = mp3splt_new_state(out error);
            error      = mp3splt_find_plugins(_mp3_state);
            Hyena.Log.Information("mp3splt: find_plugins result:" + error);

            mp3splt_set_int_option(_mp3_state, Mp3SpltOptions.SPLT_OPT_SET_FILE_FROM_CUE_IF_FILE_TAG_FOUND, 1);
            mp3splt_set_int_option(_mp3_state, Mp3SpltOptions.SPLT_OPT_OUTPUT_FILENAMES, (int)SpltOutputFileNamesOptions.SPLT_OUTPUT_FORMAT);
            mp3splt_set_oformat(_mp3_state, "@A - @b - @n - @t", out error);
            _file_format = "@A - @b - @n - @t";
            mp3splt_put_cue_splitpoints_from_file(_mp3_state, s.cueFile(), out error);
            mp3splt_set_default_genre_tag(_mp3_state, s.genre());

            int    count, ctags;
            IntPtr pointarray = mp3splt_get_splitpoints(_mp3_state, out count, out error);
            IntPtr tagarray   = mp3splt_get_tags(_mp3_state, out ctags, out error);

            Hyena.Log.Information("count=" + count + ", ctags=" + ctags);

            {
                int i;
                _tracks.Clear();
                int N = (count < ctags) ? count : ctags;
                for (i = 0; i < N; i++)
                {
                    _tracks.Add(new Mp3SplitTrack(pointarray, tagarray, i));
                }
            }
        }
        private void setLatinTag(int track, CueSheet s, CueSheetEntry e)
        {
            string fn = _file_format;

            fn = fn.Replace("@A", s.performer());
            fn = fn.Replace("@b", s.title());
            fn = fn.Replace("@n", (track + 1).ToString());
            fn = fn.Replace("@t", e.title());
            fn = _directory + "/" + fn + ".mp3";
            Hyena.Log.Information("file to convert:" + fn);
            if (File.Exists(fn))
            {
                TagLib.File file = TagLib.File.Create(fn);
                if (file == null)
                {
                    Hyena.Log.Error("Cannot create taglib file for " + fn);
                    return;
                }
                else
                {
                    Hyena.Log.Information("Setting tags for " + fn);
                    file.Tag.Album        = s.title();
                    file.Tag.AlbumArtists = new string[] { s.performer() };
                    file.Tag.Composers    = new string[] { s.composer() };
                    file.Tag.Genres       = new string[] { s.genre() };
                    file.Tag.Title        = e.title();
                    file.Tag.Track        = (uint)track + 1;
                    file.Tag.Performers   = new string[] { e.performer() };
                    file.Save();
                }
            }
        }
        //private Stack<DatabaseTrackInfo> stk=new Stack<DatabaseTrackInfo>();
        public void ImportSheet(CueSheet s)
        {
            if (import_manager==null) {
                try {
                    import_manager = new LibraryImportManager (false);
                    /*import_manager.ImportResult+=delegate(object sender,DatabaseImportResultArgs args) {
                        DatabaseTrackInfo trk=args.Track;
                        stk.Push (trk);
                    };*/
                } catch (Exception ex) {
                    Hyena.Log.Error (ex.ToString ());
                }
            }

            Hyena.Log.Debug ("Importsheet: Starting transaction");
            int i,N;
            for(i=0,N=s.nEntries ();i<N;i++) {
                try {
                    CueSheetEntry e=s.entry (i);
                    string file=e.file ();
                    string uuid=Regex.Replace(e.id (),"\\s","_");
                    string ext=".mp3";

                    string uid=Guid.NewGuid ().ToString ();
                    string u1=uid.Substring (0,1);
                    string u2=uid.Substring (0,2);
                    string dir=basedir+"/.banshee/"+u1;
                    if (!Directory.Exists (dir))  {
                        Directory.CreateDirectory(dir);
                    }
                    dir+="/"+u2;
                    if (!Directory.Exists(dir)) {
                        Directory.CreateDirectory(dir);
                    }
                    uuid=dir+"/"+uuid+ext;

                    UnixFileInfo f=new UnixFileInfo(file);
                    if (File.Exists (uuid)) { File.Delete(uuid); }
                    //f.CreateLink (uuid);
                    f.CreateSymbolicLink(uuid);

                    DatabaseTrackInfo trk=import_manager.ImportTrack(uuid);
                    //File.Delete (uuid);
                    /*if (trk==null) {
                        Hyena.Log.Warning ("track = null (file="+e.file ()+")");
                        if (stk.Count>0) { trk=stk.Pop (); }
                    }*/

                    if (trk==null) {
                        Hyena.Log.Error ("track = null (file="+e.file ()+")");
                    } else {
                        Hyena.Log.Information ("track!=null (file="+e.file ()+")");
                        //MySource.DbConnection.BeginTransaction();
                        trk.PartOfCue=1;
                        trk.CueAudioFile=e.file ();
                        trk.AlbumTitle=s.title ();
                        //trk.Album=s.title ();
                        trk.AlbumArtist=s.performer ();
                        trk.Composer=(e.Composer=="") ? s.composer () : e.Composer;
                        //trk.ArtworkId=s.getArtId ();
                        //trk.Artist=
                        trk.ArtistName=(e.performer ()=="") ? s.performer () : e.performer ();
                        trk.TrackTitle=e.title ();
                        trk.TrackNumber=i+1;
                        trk.Genre=s.genre ();
                        trk.BeginOffset=e.BeginOffset;
                        trk.EndOffset=e.EndOffset;
                        //trk.Uri=trk.CueAudioUri;
              						//trk.MediaAttributes = TrackMediaAttributes.ExternalResource;
                        //trk.PrimarySource = ServiceManager.SourceManager.MusicLibrary;

                        trk.Save ();
                        //MySource.DbConnection.CommitTransaction();
                    }
                } catch (Exception ex) {
                    Hyena.Log.Error (ex.ToString ());
                }
            }
            import_manager.NotifyAllSources ();
        }
Ejemplo n.º 4
0
        //private Stack<DatabaseTrackInfo> stk=new Stack<DatabaseTrackInfo>();

        public void ImportSheet(CueSheet s)
        {
            if (import_manager == null)
            {
                try {
                    import_manager = new LibraryImportManager(false);

                    /*import_manager.ImportResult+=delegate(object sender,DatabaseImportResultArgs args) {
                     *      DatabaseTrackInfo trk=args.Track;
                     *      stk.Push (trk);
                     * };*/
                } catch (Exception ex) {
                    Hyena.Log.Error(ex.ToString());
                }
            }

            Hyena.Log.Debug("Importsheet: Starting transaction");
            int i, N;

            for (i = 0, N = s.nEntries(); i < N; i++)
            {
                try {
                    CueSheetEntry e    = s.entry(i);
                    string        file = e.file();
                    string        uuid = Regex.Replace(e.id(), "\\s", "_");
                    string        ext  = ".mp3";

                    string uid = Guid.NewGuid().ToString();
                    string u1  = uid.Substring(0, 1);
                    string u2  = uid.Substring(0, 2);
                    string dir = basedir + "/.banshee/" + u1;
                    if (!Directory.Exists(dir))
                    {
                        Directory.CreateDirectory(dir);
                    }
                    dir += "/" + u2;
                    if (!Directory.Exists(dir))
                    {
                        Directory.CreateDirectory(dir);
                    }
                    uuid = dir + "/" + uuid + ext;

                    UnixFileInfo f = new UnixFileInfo(file);
                    if (File.Exists(uuid))
                    {
                        File.Delete(uuid);
                    }
                    //f.CreateLink (uuid);
                    f.CreateSymbolicLink(uuid);

                    DatabaseTrackInfo trk = import_manager.ImportTrack(uuid);
                    //File.Delete (uuid);

                    /*if (trk==null) {
                     *      Hyena.Log.Warning ("track = null (file="+e.file ()+")");
                     *      if (stk.Count>0) { trk=stk.Pop (); }
                     * }*/

                    if (trk == null)
                    {
                        Hyena.Log.Error("track = null (file=" + e.file() + ")");
                    }
                    else
                    {
                        Hyena.Log.Information("track!=null (file=" + e.file() + ")");
                        //MySource.DbConnection.BeginTransaction();
                        trk.PartOfCue    = 1;
                        trk.CueAudioFile = e.file();
                        trk.AlbumTitle   = s.title();
                        //trk.Album=s.title ();
                        trk.AlbumArtist = s.performer();
                        trk.Composer    = (e.Composer == "") ? s.composer() : e.Composer;
                        //trk.ArtworkId=s.getArtId ();
                        //trk.Artist=
                        trk.ArtistName  = (e.performer() == "") ? s.performer() : e.performer();
                        trk.TrackTitle  = e.title();
                        trk.TrackNumber = i + 1;
                        trk.Genre       = s.genre();
                        trk.BeginOffset = e.BeginOffset;
                        trk.EndOffset   = e.EndOffset;
                        //trk.Uri=trk.CueAudioUri;
                        //trk.MediaAttributes = TrackMediaAttributes.ExternalResource;
                        //trk.PrimarySource = ServiceManager.SourceManager.MusicLibrary;

                        trk.Save();
                        //MySource.DbConnection.CommitTransaction();
                    }
                } catch (Exception ex) {
                    Hyena.Log.Error(ex.ToString());
                }
            }
            import_manager.NotifyAllSources();
        }
        public Mp3Split(CueSheet s)
        {
            int error=0;
            _sheet=s;

            _mp3_state=mp3splt_new_state (out error);
            error=mp3splt_find_plugins (_mp3_state);
            Hyena.Log.Information ("mp3splt: find_plugins result:"+error);

            mp3splt_set_int_option(_mp3_state,Mp3SpltOptions.SPLT_OPT_SET_FILE_FROM_CUE_IF_FILE_TAG_FOUND,1);
            mp3splt_set_int_option(_mp3_state,Mp3SpltOptions.SPLT_OPT_OUTPUT_FILENAMES,(int) SpltOutputFileNamesOptions.SPLT_OUTPUT_FORMAT);
            mp3splt_set_oformat(_mp3_state,"@A - @b - @n - @t",out error);
            _file_format="@A - @b - @n - @t";
            mp3splt_put_cue_splitpoints_from_file(_mp3_state,s.cueFile (),out error);
            mp3splt_set_default_genre_tag(_mp3_state,s.genre ());

            int count,ctags;
            IntPtr pointarray=mp3splt_get_splitpoints(_mp3_state,out count,out error);
            IntPtr tagarray=mp3splt_get_tags (_mp3_state,out ctags,out error);
            Hyena.Log.Information ("count="+count+", ctags="+ctags);

            {
                int i;
                _tracks.Clear ();
                int N=(count<ctags) ? count : ctags;
                for(i=0;i<N;i++) {
                    _tracks.Add (new Mp3SplitTrack(pointarray,tagarray,i));
                }
            }
        }
 private void setLatinTag(int track,CueSheet s,CueSheetEntry e)
 {
     string fn=_file_format;
     fn=fn.Replace ("@A",s.performer());
     fn=fn.Replace ("@b",s.title ());
     fn=fn.Replace ("@n",(track+1).ToString ());
     fn=fn.Replace ("@t",e.title ());
     fn=_directory+"/"+fn+".mp3";
     Hyena.Log.Information ("file to convert:"+fn);
     if (File.Exists(fn)) {
         TagLib.File file=TagLib.File.Create(fn);
         if (file==null) {
             Hyena.Log.Error ("Cannot create taglib file for "+fn);
             return;
         } else {
             Hyena.Log.Information("Setting tags for "+fn);
             file.Tag.Album=s.title ();
             file.Tag.AlbumArtists=new string[]{s.performer ()};
             file.Tag.Composers=new string[]{s.composer ()};
             file.Tag.Genres=new string[]{s.genre ()};
             file.Tag.Title=e.title ();
             file.Tag.Track=(uint) track+1;
             file.Tag.Performers=new string[]{e.performer ()};
             file.Save ();
         }
     }
 }