public AddCustomStreamView(NormalPlaylist playlist, MusicManager manager, Action<AddCustomStreamView> closeAction)
 {
     InitializeComponent();
     _closeAction = closeAction;
     _playlist = playlist;
     _manager = manager;
 }
 public TrackImportWindow(ObservableCollection<NormalPlaylist> playlists, NormalPlaylist selectedplaylist, string trackname)
 {
     Playlists = playlists;
     SelectedPlaylist = selectedplaylist;
     Trackname = trackname;
     InitializeComponent();
 }
Exemple #3
0
 public PlaylistItem(NormalPlaylist playlist)
 {
     Playlist = playlist;
     Name = Playlist.Name;
     Playlist.PropertyChanged += (s, e) =>
     {
         if (e.PropertyName == "Name")
             Name = Playlist.Name;
     };
 }
Exemple #4
0
        public void ImportLocalTracks()
        {
            var playlist = new NormalPlaylist();
            var task = playlist.AddFiles(_testFiles);
            task.Wait();
            
            Assert.AreEqual(2, playlist.Tracks.Count);
            var authenticationCodeList = new List<long>();

            foreach (var track in playlist.Tracks)
            {
                if(authenticationCodeList.Contains((track.AuthenticationCode)))
                    Assert.Fail("Same AuthenticationCodes");
                authenticationCodeList.Add(track.AuthenticationCode);
            }
        }
Exemple #5
0
        public async void OpenFile(FileInfo file, bool play)
        {
            foreach (var playlist in MusicManager.Playlists)
            {
                foreach (var track in playlist.Tracks.Where(track => track.GetType() == typeof(LocalTrack) && ((LocalTrack)track).Path == file.FullName))
                {
                    if (play) MusicManager.PlayTrack(track, playlist);
                    return;
                }
            }

            NormalPlaylist selectedplaylist = null;
            var config = HurricaneSettings.Instance.Config;

            if (config.RememberTrackImportPlaylist)
            {
                var items = MusicManager.Playlists.Where(x => x.Name == config.PlaylistToImportTrack).ToList();
                if (items.Any())
                {
                    selectedplaylist = items.First();
                }
                else { config.RememberTrackImportPlaylist = false; config.PlaylistToImportTrack = null; }
            }

            if (selectedplaylist == null)
            {
                if (_remember && MusicManager.Playlists.Contains(_rememberedPlaylist))
                {
                    selectedplaylist = _rememberedPlaylist;
                }
                else
                {
                    var selectedPlaylist = _musicmanager.SelectedPlaylist.CanEdit ? (NormalPlaylist)_musicmanager.SelectedPlaylist : _musicmanager.Playlists[0];
                    var window = new TrackImportWindow(_musicmanager.Playlists, selectedPlaylist, file.Name) { Owner = _baseWindow };
                    if (window.ShowDialog() == false) return;
                    selectedplaylist = window.SelectedPlaylist;
                    if (window.RememberChoice)
                    {
                        _remember = true;
                        _rememberedPlaylist = window.SelectedPlaylist;
                        if (window.RememberAlsoAfterRestart)
                        {
                            config.RememberTrackImportPlaylist = true;
                            config.PlaylistToImportTrack = selectedplaylist.Name;
                        }
                    }
                }
            }

            await ImportFiles(new[] { file.FullName }, selectedplaylist, (s, e) => OpenFile(file, play));
        }
Exemple #6
0
        async Task ImportFiles(IEnumerable<string> paths, NormalPlaylist playlist, EventHandler finished = null)
        {
            var controller = await _baseWindow.WindowDialogService.CreateProgressDialog(string.Empty, false);

            var tracks = Playlists.ImportFiles(paths, (s, e) =>
            {
                controller.SetProgress(e.Percentage);
                controller.SetMessage(e.CurrentFile);
                controller.SetTitle(string.Format(Application.Current.Resources["FilesGetImported"].ToString(), e.FilesImported, e.TotalFiles));
            });

            await playlist.AddFiles(tracks);

            MusicManager.SaveToSettings();
            MySettings.Save();
            await controller.Close();
            if (finished != null) Application.Current.Dispatcher.Invoke(() => finished(this, EventArgs.Empty));
        }
Exemple #7
0
        public static IPlaylist Import(string basePath, StreamReader reader)
        {
            var playlist = new NormalPlaylist();

            var cue = new CueSheet(reader);

            if (cue.Tracks.Length == 0 || cue.Tracks[0].DataFile.Filename == null)
                return null;

            var genre = string.Empty;
            var year = 0u;
            if (cue.Comments != null && cue.Comments.Length > 0)
            {
                foreach (var comment in cue.Comments)
                    if (comment.StartsWith("GENRE "))
                        genre = comment.Substring(6);
                    else if (comment.StartsWith("DATE "))
                    {
                        uint.TryParse(comment.Substring(5), out year);
                        if (year <= 1000 || year >= 3000)
                            year = 0;
                    }
            }


            var audioFile = cue.Tracks[0].DataFile.Filename;

            int i = 1;

            foreach (var track in cue.Tracks)
            {
                if (track.Indices.Length == 0)
                    continue;

                var offset = track.Offset;
                var duration = TimeSpan.Zero;

                if (i < cue.Tracks.Length)
                {
                    TimeSpan nextOffset = cue.Tracks[i].Offset;
                    duration = nextOffset - offset;
                }
                else
                {
                    // there's no way of knowing what's the last track's duration without decoding audio file
                    // and checking it's duration first; deferred to track info reading code
                }

                var element = new LocalTrackFragment(offset, duration, track.Title)
                {
                    Path = Path.Combine(basePath, audioFile),
                    Artist = track.Performer ?? cue.Performer,
                    Album = track.Title ?? cue.Title,
                    TrackNumber = track.TrackNumber,
                    Genres = new List<Genre> { PlayableBase.StringToGenre(genre) },
                    Year = year
                };

                playlist.AddTrack(element);

                ++i;
            }

            return playlist;
        }
        public static IPlaylist Import(string basePath, StreamReader reader)
        {
            var playlist = new NormalPlaylist();

            for (int trackNumber = 1; ; )
            {
                var line = reader.ReadLine();

                if (line == null)
                    break;

                line = line.Trim();
                if (string.IsNullOrWhiteSpace(line))
                    continue;

                if (line.ToUpper().StartsWith("#EXTINF:"))
                {
                    try
                    {
                        var split = line.Substring(8).TrimStart(',');
                        var parts = split.Split(new[] { ',' }, 2);

                        var location = reader.ReadLine();
                        if (string.IsNullOrEmpty(location))
                            break; //corrupt file

                        PlayableBase track;
                        if (location.StartsWith("http:"))
                        {
                            track = new CustomStream {StreamUrl = location};
                        }
                        else
                        {
                        
                         var localTrack = new LocalTrack();
                            var file = new FileInfo(FileSystemHelper.GetAbsolutePath(location, basePath));
                            if (!file.Exists)
                                continue;
                            localTrack.Path = file.FullName;
                            track = localTrack;
                        }

                        track.Title = parts.Length == 2
                            ? parts[1].Trim()
                            : split.Trim();
                        track.TrackNumber = trackNumber++;

                        playlist.AddTrack(track);
                        continue;
                    }
                    catch (Exception ex)
                    {
                        // ignore it
                        Debug.WriteLine("M3U ext track import error: " + ex.Message);
                    }
                }

                if (line.StartsWith("http"))
                {
                    Uri uri;
                    try
                    {
                        uri = new Uri(line);
                    }
                    catch (Exception)
                    {
                        Debug.Print("M3U track import error: invalid uri - '{0}'", line);
                        continue;
                    }
                    playlist.AddTrack(new CustomStream { StreamUrl = line, Title = uri.Host, TrackNumber = trackNumber++ });
                    continue;
                }

                if (line[0] != '#')	// skip comments
                {
                    var file = new FileInfo(FileSystemHelper.GetAbsolutePath(line, basePath));
                    if (!file.Exists)
                        continue;

                    playlist.AddTrack(new LocalTrack
                    {
                        Path = file.FullName,
                        TrackNumber = trackNumber++,
                        Title = Path.GetFileNameWithoutExtension(file.FullName)
                    });
                }
            }

            return playlist;
        }
Exemple #9
0
        public static IPlaylist Import(string basePath, StreamReader reader)
        {
            var playlist = new NormalPlaylist();

            for (int trackNumber = 1; ;)
            {
                var line = reader.ReadLine();

                if (line == null)
                {
                    break;
                }

                line = line.Trim();

                if (string.IsNullOrWhiteSpace(line))
                {
                    continue;
                }

                // TODO: support http

                if (line.StartsWith("#EXTINF:"))
                {
                    try
                    {
                        var        split = line.Substring(8).TrimStart(',');
                        var        parts = split.Split(new [] { ',' }, 2);
                        LocalTrack track;
                        if (parts.Length == 2)
                        {
                            track = new LocalTrack {
                                Title = parts[1].Trim()
                            };
                            track.ResetDuration(new TimeSpan(0, 0, int.Parse(parts[0])));
                        }
                        else
                        {
                            track = new LocalTrack {
                                Title = split.Trim()
                            };
                        }
                        playlist.AddTrack(track);
                    }
                    catch (Exception ex)
                    {
                        // ignore it
                        Debug.WriteLine("M3U ext track import error: " + ex.Message);
                    }
                }
                else if (line.StartsWith("http"))
                {
                    Uri uri;
                    try
                    {
                        uri = new Uri(line);
                    }
                    catch (Exception)
                    {
                        Debug.Print("M3U track import error: invalid uri - '{0}'", line);
                        continue;
                    }
                    playlist.AddTrack(new CustomStream {
                        StreamUrl = line, Title = uri.Host
                    });
                }
                else if (line[0] != '#')        // skip comments
                {
                    playlist.AddTrack(new LocalTrack {
                        Path = Path.Combine(basePath, line), TrackNumber = trackNumber++
                    });
                }
            }

            return(playlist);
        }
Exemple #10
0
        public static IPlaylist Import(string basePath, StreamReader reader)
        {
            var playlist = new NormalPlaylist();

            var cue = new CueSheet(reader);

            if (cue.Tracks.Length == 0 || cue.Tracks[0].DataFile.Filename == null)
            {
                return(null);
            }

            var genre = string.Empty;
            var year  = 0u;

            if (cue.Comments != null && cue.Comments.Length > 0)
            {
                foreach (var comment in cue.Comments)
                {
                    if (comment.StartsWith("GENRE "))
                    {
                        genre = comment.Substring(6);
                    }
                    else if (comment.StartsWith("DATE "))
                    {
                        uint.TryParse(comment.Substring(5), out year);
                        if (year <= 1000 || year >= 3000)
                        {
                            year = 0;
                        }
                    }
                }
            }


            var audioFile = cue.Tracks[0].DataFile.Filename;

            int i = 1;

            foreach (var track in cue.Tracks)
            {
                if (track.Indices.Length == 0)
                {
                    continue;
                }

                var offset   = track.Offset;
                var duration = TimeSpan.Zero;

                if (i < cue.Tracks.Length)
                {
                    TimeSpan nextOffset = cue.Tracks[i].Offset;
                    duration = nextOffset - offset;
                }
                else
                {
                    // there's no way of knowing what's the last track's duration without decoding audio file
                    // and checking it's duration first; deferred to track info reading code
                }

                var element = new LocalTrackFragment(offset, duration, track.Title)
                {
                    Path        = Path.Combine(basePath, audioFile),
                    Artist      = track.Performer ?? cue.Performer,
                    Album       = track.Title ?? cue.Title,
                    TrackNumber = track.TrackNumber,
                    Genres      = new List <Genre> {
                        PlayableBase.StringToGenre(genre)
                    },
                    Year = year
                };

                playlist.AddTrack(element);

                ++i;
            }

            return(playlist);
        }
Exemple #11
0
        public static IPlaylist Import(string basePath, StreamReader reader)
        {
            var        playlist = new NormalPlaylist();
            LocalTrack track    = null;

            for (int trackNumber = 1; ;)
            {
                var line = reader.ReadLine();

                if (line == null)
                {
                    break;
                }

                line = line.Trim();

                if (line.Length == 0)
                {
                    continue;
                }

                // TODO: support http

                if (line.StartsWith("#EXTINF:"))
                {
                    try
                    {
                        var split = line.Substring(8).TrimStart(',');
                        var parts = split.Split(new [] { ',' }, 2);

                        if (parts.Length == 2)
                        {
                            track = new LocalTrack {
                                Title = parts[1].Trim()
                            };
                            track.ResetDuration(new TimeSpan(0, 0, int.Parse(parts[0])));
                        }
                        else
                        {
                            track = new LocalTrack {
                                Title = split.Trim()
                            };
                        }
                    }
                    catch (Exception ex)
                    {
                        // ignore it
                        Debug.WriteLine("M3U ext track import error: " + ex.Message);
                    }
                }
                else if (line[0] != '#')        // skip comments
                {
                    if (track == null)
                    {
                        track = new LocalTrack();
                    }

                    track.Path        = Path.Combine(basePath, line);
                    track.TrackNumber = trackNumber++;

                    playlist.AddTrack(track);

                    track = null;
                }
            }

            return(playlist);
        }