Exemplo n.º 1
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;
        }
Exemplo n.º 2
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;

                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;
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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);
        }