public ContentProvider(Plugin owner) { _owner = owner; _contents = new List<IPluginContent>(); string path = Path.GetDirectoryName(Assembly.GetCallingAssembly().Location) + "/p2ppl.csv"; if (!File.Exists(path)) using (var f = File.Create(path)) { f.Close(); } var sr = new StreamReader(path); while (!sr.EndOfStream) { var line = sr.ReadLine(); if (string.IsNullOrEmpty(line)) continue; var aitem = line.Split(";".ToCharArray(), 3, StringSplitOptions.None); if (string.IsNullOrEmpty(aitem[0])) continue; try { var item = new Content(); Uri url = new Uri(aitem[0], UriKind.Absolute); SourceUrl source = new SourceUrl(); source.Url = url.Host; source.Type = url.Scheme == "acestream" ? SourceType.ContentId : SourceType.Torrent; item.Source = source; item.Id = string.IsNullOrEmpty(aitem[2]) ? Guid.NewGuid().ToString("N") : aitem[2]; item.Title = string.IsNullOrEmpty(aitem[1]) ? item.Id : aitem[1]; item.Parent = this; _contents.Add(item); } catch (Exception e) { _owner.RaiseLog(e.Message); } } }
public TorrentStream GetContentUrl(SourceUrl url, MyWebRequest req) { //locker.isSet = true; if (url.Type == SourceType.Torrent) url.Url = new Uri(url.Url, UriKind.Absolute).ToString(); var ts = _device.Proxy.GetTsClient(url.Url); Task<string> waiter; try { if (ts == null) { if (!req.Client.Connected) return null; ts = new TorrentStream(req.Client); ts.Connect(); waiter = ts.Play(url.Url, (TTVApi.SourceType)(byte)url.Type, req.Headers.ContainsKey("index") ? int.Parse(req.Headers["index"]) : 0); if (waiter != null) _device.Proxy.AddToTsPool(ts); } else { waiter = ts.GetPlayTask(); ts.Owner[0].Close(); ts.Owner.Add(req.Client); ts.Owner.RemoveAt(0); } if (waiter != null && !waiter.IsCompleted) waiter.Wait(); else if (waiter == null) throw new FileNotFoundException(); if (string.IsNullOrEmpty(waiter.Result)) { _device.Proxy.RemoveFromTsPoos(ts); } return ts; } catch (Exception ex) { P2pProxyApp.Log.Write(ex.Message, TypeMessage.Error); ts.Disconnect(); _device.Proxy.RemoveFromTsPoos(ts); plaing = false; locker.isSet = false; return null; } }
private void PlayNew(MyWebRequest req, SourceUrl source) { var url = source.Url; if (source.Type == SourceType.Torrent) { TorrentStream ts1 = new TorrentStream(req.Client); ts1.Connect(); var respData = ts1.ReadTorrent(url, TTVApi.SourceType.Torrent); url = ts1.GetContentId(respData); } }