Ejemplo n.º 1
0
        public List <Track> singlePlaylistFromChannel(Playlist _playlist, string _user = "")
        {
            List <Track> playlist = null;

            if (_playlist != null && this.MusicPlaylistsAvailable)
            {
                if (PlaylistSettings.theSettings().ChannelPreferDataFolder&& PlaylistSettings.ValidChannelDataFolder && !String.IsNullOrEmpty(_user))
                {
                    playlist = this.readChannelSinglePlaylistFromFolder(_playlist, _user);
                }
                if ((playlist == null || playlist.Count() == 0) && this.MusicPlaylistInstalled)
                {
                    var elements = getSinglePlaylist(_playlist.Key);
                    playlist = new List <Track>();
                    foreach (XElement element in elements)
                    {
                        Track track = new Track(playlist)
                        {
                            Key       = attributeValue(element, KEY),
                            Title     = attributeValue(element, TITLE),
                            Duration  = attributeValueAsInt(element, DURATION) / 1000,
                            TrackType = attributeValue(element, ALBUM, PMSBase.TYPE_TRACK)
                        };
                        playlist.Add(track);
                    }
                }
                if (playlist.Count() == 0 && !PlaylistSettings.theSettings().ChannelPreferDataFolder&& PlaylistSettings.ValidChannelDataFolder && !String.IsNullOrEmpty(_user))
                {
                    // Music playlist channel not installed: read direclty from data folder
                    playlist = this.readChannelSinglePlaylistFromFolder(_playlist, _user);
                }
            }
            return(playlist ?? new List <Track>());
        }
Ejemplo n.º 2
0
        public List <Playlist> allPlaylistsFromChannel(string _user = "")
        {
            List <Playlist> playlists = new List <Playlist>();

            if (this.MusicPlaylistsAvailable)
            {
                if (PlaylistSettings.theSettings().ChannelPreferDataFolder&& PlaylistSettings.ValidChannelDataFolder && !String.IsNullOrEmpty(_user))
                {
                    playlists = this.readChannelPlaylistsFromFolder(_user);
                }
                if (this.MusicPlaylistInstalled && playlists.Count() == 0)
                {
                    var elements = getAllPlaylists();
                    foreach (XElement element in elements)
                    {
                        playlists.Add(new Playlist()
                        {
                            Key         = attributeValue(element, KEY),
                            Title       = attributeValue(element, TITLE),
                            Description = attributeValue(element, SUMMARY),
                            Duration    = attributeValueAsInt(element, DURATION),
                            AccountId   = currentUser.Id
                        });
                    }
                }
                if (playlists.Count() == 0 && !PlaylistSettings.theSettings().ChannelPreferDataFolder&& PlaylistSettings.ValidChannelDataFolder && !String.IsNullOrEmpty(_user))
                {
                    // Music playlist channel not installed: read direclty from data folder
                    playlists = this.readChannelPlaylistsFromFolder(_user);
                }
            }
            return(playlists);
        }
Ejemplo n.º 3
0
        public List <PLUser> userList(bool _forceFromChannel)
        {
            if (!_forceFromChannel && playlistMode == PlaylistMode.PlexNative)
            {
                return(m_PlexPlaylistCreator.userList());
            }
            List <PLUser> userlist = null;

            if (this.MusicPlaylistsAvailable)
            {
                if (PlaylistSettings.theSettings().ChannelPreferDataFolder&& PlaylistSettings.ValidChannelDataFolder)
                {
                    userlist = this.readChannelUsersFromFolder();
                }
                if ((userlist == null || userlist.Count() == 0) && this.MusicPlaylistInstalled)
                {
                    var elements = getUserList();
                    foreach (XElement element in elements)
                    {
                        userlist.Add(new PLUser()
                        {
                            Name  = attributeValue(element, KEY),
                            Title = attributeValue(element, TITLE),
                        });
                    }
                }
                // Music playlist channel not installed: read direclty from data folder
                if (!PlaylistSettings.theSettings().ChannelPreferDataFolder&& PlaylistSettings.ValidChannelDataFolder)
                {
                    userlist = this.readChannelUsersFromFolder();
                }
            }
            return(userlist ?? new List <PLUser>());
        }
Ejemplo n.º 4
0
        private List <Playlist> readChannelPlaylistsFromFolder(string _user)
        {
            _user = _user.Trim();
            List <Playlist> playlists = new List <Playlist>();

            if (PlaylistSettings.ValidChannelDataFolder && !String.IsNullOrEmpty(_user))
            {
                // Find all files named: "<Username>_allPlaylists.xml"
                string playlistFile = Path.Combine(PlaylistSettings.theSettings().ChannelDataFolder, String.Format("{0}_allPlaylists.xml", _user));
                if (File.Exists(playlistFile))
                {
                    // Read the playlist
                    try
                    {
                        //Load xml
                        XDocument xdoc = XDocument.Load(playlistFile);

                        //Run query
                        var plist = from pl in xdoc.Descendants("playlist")
                                    select new
                        {
                            Key         = pl.Attribute("key").Value,
                            Title       = pl.Attribute("title").Value,
                            Description = pl.Attribute("description").Value,
                            Duration    = pl.Attribute("duration").Value,
                            //urationTracks = pl.Attribute("durationTracks").Value
                        };
                        foreach (var pl in plist)
                        {
                            playlists.Add(new Playlist()
                            {
                                Key         = pl.Key,
                                Title       = pl.Title,
                                Description = pl.Description,
                                Duration    = String.IsNullOrEmpty(pl.Duration) ? 0 : Convert.ToInt32(pl.Duration),
                                AccountId   = currentUser.Id
                            });
                        }
                    }
                    catch { }
                }
            }
            return(playlists);
        }
Ejemplo n.º 5
0
        private List <PLUser> readChannelUsersFromFolder()
        {
            List <PLUser> users = new List <PLUser>();

            if (PlaylistSettings.ValidChannelDataFolder)
            {
                // Find all files named: "<Username>_allPlaylists.xml"
                var playlistFiles = Directory.EnumerateFiles(PlaylistSettings.theSettings().ChannelDataFolder).Where(f => f.EndsWith("_allPlaylists.xml"));
                foreach (string file in playlistFiles)
                {
                    // Extract the username
                    string user = Path.GetFileName(file);
                    user = user.Remove(user.Length - "_allPlaylists.xml".Length);
                    users.Add(new PLUser()
                    {
                        Name = user
                    });
                }
            }
            return(users);
        }
Ejemplo n.º 6
0
        public List <Track> readChannelSinglePlaylistFromFolder(Playlist _playlist, string _user)
        {
            List <Track> trackList = new List <Track>();

            if (_playlist != null && !String.IsNullOrEmpty(_user) && PlaylistSettings.ValidChannelDataFolder)
            {
                string playlistFile = Path.Combine(PlaylistSettings.theSettings().ChannelDataFolder, String.Format("{0} - {1}.xml", _user, _playlist.Key));
                if (File.Exists(playlistFile))
                {
                    // Read the playlist
                    try
                    {
                        //Load xml
                        XDocument xdoc = XDocument.Load(playlistFile);

                        //Run query
                        var tlist = from tr in xdoc.Descendants("Track")
                                    select new
                        {
                            Key       = tr.Attribute("key").Value,
                            Title     = tr.Attribute("title").Value,
                            Duration  = tr.Attribute("duration").Value,
                            TrackType = tr.Attribute("type") != null?tr.Attribute("type").Value : "track"
                        };
                        foreach (var tr in tlist)
                        {
                            trackList.Add(new Track(trackList)
                            {
                                Key       = tr.Key,
                                Title     = tr.Title,
                                Duration  = String.IsNullOrEmpty(tr.Duration) ? 0 : Convert.ToInt32(tr.Duration),
                                TrackType = tr.TrackType
                            });
                        }
                    }
                    catch { }
                }
            }
            return(trackList);
        }
Ejemplo n.º 7
0
 public PlaylistManager(string _ip, int _port) : base(_ip, _port)
 {
     playlistMode = PlaylistSettings.theSettings().GUIPlaylistMode;
 }