Exemple #1
0
        /// <summary>
        /// Adds the downloaded item to a playlist in iTunes.
        /// </summary>
        /// <remarks>The title of the playlist is the name of the feed in RSS Bandit.</remarks>
        /// <param name="podcast"></param>
        private void AddPodcastToITunes(DownloadItem podcast)
        {
            try
            {
                if (!IsITunesFile(Path.GetExtension(podcast.File.LocalName)))
                {
                    return;
                }

                string     playlistName = Preferences.SinglePlaylistName;
                FeedSource source       = guiMain.FeedSourceOf(podcast.OwnerFeedId);

                if (!Preferences.SinglePodcastPlaylist && source != null)
                {
                    playlistName = source.GetFeeds()[podcast.OwnerFeedId].title;
                }

                // initialize iTunes application connection
                iTunesApp itunes = new iTunesApp();

                //get a handle to the playlist if it exists or create it if it doesn't
                IITUserPlaylist podcastPlaylist = null;

                foreach (IITPlaylist pl in itunes.LibrarySource.Playlists)
                {
                    if (pl.Name.Equals(playlistName))
                    {
                        podcastPlaylist = (IITUserPlaylist)pl;
                    }
                }

                if (podcastPlaylist == null)
                {
                    podcastPlaylist = (IITUserPlaylist)itunes.CreatePlaylist(playlistName);
                }

                //add podcast to our playlist for this feed
                podcastPlaylist.AddFile(Path.Combine(podcast.TargetFolder, podcast.File.LocalName));
            }
            catch (Exception e)
            {
                _log.Error("The following error occured in AddPodcastToITunes(): ", e);
            }
        }
        public override bool Play(string strFile)
        {
            try
            {
                if (_iTunesApplication == null)
                {
                    _iTunesApplication = new iTunesAppClass();
                    _iTunesApplication.OnPlayerPlayEvent +=
                        new _IiTunesEvents_OnPlayerPlayEventEventHandler(_iTunesApplication_OnPlayerPlayEvent);
                    _iTunesApplication.OnPlayerStopEvent +=
                        new _IiTunesEvents_OnPlayerStopEventEventHandler(_iTunesApplication_OnPlayerStopEvent);
                    _iTunesApplication.OnPlayerPlayingTrackChangedEvent +=
                        new _IiTunesEvents_OnPlayerPlayingTrackChangedEventEventHandler(
                            _iTunesApplication_OnPlayerPlayingTrackChangedEvent);
                    IITPlaylist playList = null;
                    foreach (IITPlaylist pl in _iTunesApplication.LibrarySource.Playlists)
                    {
                        if (pl.Name.Equals("MediaPortalTemporaryPlaylist"))
                        {
                            playList = pl;
                            break;
                        }
                    }
                    if (playList == null)
                    {
                        _playList = (IITUserPlaylist)_iTunesApplication.CreatePlaylist("MediaPortalTemporaryPlaylist");
                    }
                    else
                    {
                        _playList = (IITUserPlaylist)playList;
                    }
                    _playList.SongRepeat = ITPlaylistRepeatMode.ITPlaylistRepeatModeOff;
                }

                // stop other media which might be active until now.
                if (g_Player.Playing)
                {
                    g_Player.Stop();
                }

                GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_PLAYBACK_STARTED, 0, 0, 0, 0, 0, null);
                msg.Label = strFile;
                GUIWindowManager.SendThreadMessage(msg);

                _started = false;
                _ended   = false;
                foreach (IITTrack track in _playList.Tracks)
                {
                    track.Delete();
                }
                _playList.AddFile(strFile);
                _playList.PlayFirstTrack();

                _playerIsPaused  = false;
                _currentFile     = strFile;
                _duration        = -1;
                _currentPosition = -1;
                _playerState     = ITPlayerState.ITPlayerStateStopped;
                _updateTimer     = DateTime.MinValue;

                UpdateStatus();
                _notifyPlaying = true;
                return(true);
            }
            catch (Exception ex)
            {
                Log.Error("ITunesPlugin.Play: Exception");
                Log.Error(ex);
                _notifyPlaying     = false;
                _iTunesApplication = null;
            }
            return(false);
        }
Exemple #3
0
        // Process all files in the directory passed in, recurse on any directories
        // that are found, and process the files they contain.
        public static void ProcessDirectory(string path, IITUserPlaylist parent)
        {
            Console.WriteLine("Processing directory '{0}'.", path);

            if (Directory.Exists(path))
            {
                var dir = new DirectoryInfo(path);

                IITUserPlaylist folder   = null;
                var             isFolder = DirectoryHelper.ContainsDirectories(path);
                if (isFolder)
                {
                    var fName = dir.Name;
                    // check if playlist folder exists at current location
                    folder = playlistHelper.Find(fName, ITUserPlaylistSpecialKind.ITUserPlaylistSpecialKindFolder, parent);
                    if (folder == null)
                    {
                        if (parent != null)
                        {
                            folder = (IITUserPlaylist)parent.CreateFolder(fName);
                        }
                        else
                        {
                            folder = (IITUserPlaylist)itunes.CreateFolder(fName);
                        }
                    }
                }

                IITUserPlaylist playlist = null;
                if (DirectoryHelper.ContainsFiles(path))
                {
                    var pName            = isFolder ? "## Tracks ##" : dir.Name;
                    var playlistLocation = isFolder ? folder : parent;
                    playlist = playlistHelper.Find(pName, ITUserPlaylistSpecialKind.ITUserPlaylistSpecialKindNone, playlistLocation);
                    if (playlist == null)
                    {
                        if (playlistLocation != null)
                        {
                            playlist = (IITUserPlaylist)playlistLocation.CreatePlaylist(pName);
                        }
                        else
                        {
                            playlist = (IITUserPlaylist)itunes.CreatePlaylist(pName);
                        }
                    }

                    var tracks     = playlist.Tracks;
                    var trackPaths = new List <string>();
                    foreach (IITTrack track in tracks)
                    {
                        trackPaths.Add(track.)
                    }

                    string[] fileEntries = Directory.GetFiles(path);
                    foreach (var file in fileEntries)
                    {
                        Console.WriteLine("Processing file '{0}'.", file);

                        playlist.AddFile(file);
                    }
                }

                // Recursively process the child folders
                string[] subDirectories = Directory.GetDirectories(path);
                foreach (string subDirectory in subDirectories)
                {
                    ProcessDirectory(subDirectory, folder);
                }
            }
            else
            {
                Console.WriteLine("{0} is not a valid directory.", path);
            }
        }