public virtual void StartMedia(RemoteMedia media, string command)
 {
     switch (media)
     {
     case Torrent _:
     case MagnetLink _:
         StartInTorrentClient(command);
         break;
     }
 }
        public bool CanDownload(RemoteMedia media, Anime anime)
        {
            if (anime == null || media == null)
            {
                return(false);
            }

            // Most likely wrong torrent
            if (anime.NameStrict && !anime.Name.ToLower().Equals(media.StrippedWithNoEpisode.ToLower()))
            {
                return(false);
            }

            // Not the right subgroup
            if (!string.IsNullOrEmpty(anime.PreferredSubgroup))
            {
                if (!media.HasSubgroup())
                {
                    return(false);
                }

                if (!media.Subgroup().ToLower().Contains(anime.PreferredSubgroup.ToLower()))
                {
                    return(false);
                }
            }

            if (SettingsRepository.FlagConfig.OnlyWhitelisted)
            {
                // Torrent listing with no subgroup in the title
                if (!media.HasSubgroup())
                {
                    return(false);
                }

                // Torrent listing with wrong subgroup
                if (!SettingsRepository.Subgroups.Select(s => s.ToLower()).Contains(media.Subgroup().ToLower()))
                {
                    return(false);
                }
            }

            return(true);
        }
        public async Task <bool> DownloadEpisode(Anime anime, int episode, RemoteMedia media, Action <string> output)
        {
            output($"Downloading '{anime.Title}' episode '{episode}'.");

            var download = await DownloadMedia(anime, media);

            if (download.successful)
            {
                StartMedia(media, download.command);
                await Log(anime, episode);
            }

            else
            {
                output($"Download of '{anime.Title}' failed (most likely due to server error).");
            }

            return(download.successful);
        }
        public async Task <(bool successful, string command)> DownloadMedia(Anime anime, RemoteMedia media)
        {
            var  path = "";
            bool successful;

            var destination = SettingsRepository.PathConfig.Unwatched;

            if (SettingsRepository.FlagConfig.IndividualShowFolders)
            {
                destination = Path.Combine(destination, anime.Title);
            }

            // Create directory
            if (!Directory.Exists(destination))
            {
                Directory.CreateDirectory(destination);
            }

            switch (media)
            {
            case Torrent torrent:
            {
                (successful, path) = await DownloadTorrent(torrent);

                if (!successful)
                {
                    return(false, null);
                }
                break;
            }

            case MagnetLink magnet:
            {
                (successful, path) = await Aria.Retrieve(magnet);

                if (!successful)
                {
                    return(false, null);
                }
                break;
            }
            }

            var command = SettingsRepository.TorrentDownloaderCommand(path, destination);

            return(true, command);
        }
Exemple #5
0
        private Connection Connection(PeerClient remoteClient)
        {
            string peerName = "Unknown";

            FM.WebSync.Record r;
            if (remoteClient.BoundRecords != null && remoteClient.BoundRecords.TryGetValue("userName", out r))
            {
                if (!String.IsNullOrEmpty(r.ValueJson))
                {
                    peerName = r.ValueJson.Trim('"');
                }
            }

            // Create remote media to manage the remote audio/video tracks.
            RemoteMedia remoteMedia = null;

#if __IOS__
            Utilities.DispatchSync(() =>
            {
                remoteMedia = new RemoteMedia(false, false, null);
            });
#else
            FM.IceLink.Android.Utility.DispatchToMainThread(() =>
            {
                remoteMedia = new RemoteMedia(Android.App.Application.Context, false, false, null);
            }, true);
#endif

            // Initialize the audio/video streams for the connection with the
            // local media outputs (sender) and the remote media inputs (receiver).
            AudioStream audioStream = null;
            VideoStream videoStream = null;
            if (LocalCameraMedia != null)
            {
                audioStream = new AudioStream(LocalCameraMedia, remoteMedia)
                {
                    LocalSend    = EnableAudioSend,
                    LocalReceive = EnableAudioReceive
                };

                videoStream = new VideoStream(LocalCameraMedia, remoteMedia)
                {
                    LocalSend    = EnableVideoSend,
                    LocalReceive = EnableVideoReceive
                };
            }

            if (LocalScreenMedia != null)
            {
                audioStream = new AudioStream(LocalScreenMedia, remoteMedia)
                {
                    LocalSend    = EnableAudioSend,
                    LocalReceive = EnableAudioReceive
                };

                videoStream = new VideoStream(LocalScreenMedia, remoteMedia)
                {
                    LocalSend    = EnableVideoSend,
                    LocalReceive = EnableVideoReceive
                };
            }

            // Initialize the connection with the streams.
            Connection connection = new Connection(new Stream[] { audioStream, videoStream });

            // Provide STUN/TURN servers to assist with NAT traversal.
            try
            {
                var items = JsonConvert.DeserializeObject <List <LoginModel.LoginIceServer> >(Settings.IceLinkServers);
                List <IceServer> servers = new List <IceServer>();
                foreach (var item in items)
                {
                    if (string.IsNullOrEmpty(item.sPassword) || string.IsNullOrEmpty(item.sUser))
                    {
                        servers.Add(new IceServer(item.sServer));
                    }
                    else
                    {
                        servers.Add(new IceServer(item.sServer, item.sUser, item.sPassword));
                    }
                }
                _iceServers = servers.ToArray();
            }
            catch (Exception e)
            {
                _iceServers = new[]
                {
                    //new IceServer("stun:turn.v3.icelink.fm:3478?transport=udp"),
                    //new IceServer("stun:turn.v3.icelink.fm:80?transport=udp", "*****@*****.**", "Meditocicelink1!")

                    //otros servidores de icelink
                    //new IceServer("stun:turn.frozenmountain.com:3478?transport=udp"),
                    new IceServer("turn:turn.frozenmountain.com:80?transport=udp", "test", "pa55w0rd!"),

                    //NB: url "turn:turn.icelink.fm:443" implies that the relay server supports both TCP and UDP
                    //if you want to restrict the network protocol, use "turn:turn.icelink.fm:443?transport=udp"
                    //or "turn:turn.icelink.fm:443?transport=tcp". For further info, refer to RFC 7065 3.1 URI Scheme Syntax
                    //new IceServer("turn:turn.frozenmountain.com:80?transport=udp", "test", "pa55w0rd!"),
                    //new IceServer("turns:turn.frozenmountain.com:443", "test", "pa55w0rd!")
                };
            }


            connection.IceServers = _iceServers;


            // Add the remote view to the layout.
            var remoteView = remoteMedia.View;
            if (remoteView != null)
            {
                LayoutManager.AddRemoteView(remoteMedia.Id, new FMView(remoteMedia.View));
            }

            connection.OnStateChange += (c) =>
            {
                if (c.State == ConnectionState.Connected)
                {
                    OnPeerJoined(peerName);
                }
                // Remove the remote view from the layout.
                else if (c.State == ConnectionState.Closing || c.State == ConnectionState.Failing)
                {
                    var layoutManager = LayoutManager;
                    if (layoutManager != null)
                    {
                        layoutManager.RemoveRemoteView(remoteMedia.Id);
                    }
                    RemoteMedias.Remove(remoteMedia);
                    remoteMedia.Destroy();
                }
                else if (c.State == ConnectionState.Failed)
                {
                    OnPeerLeft(peerName);
                    if (!SIGNAL_MANUALLY)
                    {
                        _signalling.Reconnect(remoteClient, c);
                    }
                }
            };

            // Track the remote media in a collection.
            RemoteMedias.Add(remoteMedia);

            connection.LocalDtlsCertificate = _certificate;

            return(connection);
        }