Exemplo n.º 1
0
        public async Task <IActionResult> AddDlc(IFormFile Dlc)
        {
            AddDlcModel model = await DlcHelper.ParseDlc(Dlc.OpenReadStream());

            if (model == null)
            {
                RedirectToAction("Index"); // TODO show error message
            }
            Match m = new Regex(@"[a-z \.\\\/\(\-]((19|20)[0-9]{2})[a-z \.\\\/\)\-]").Match(model.Name);

            if (m.Success)
            {
                string search = model.Name.Substring(0, model.Name.LastIndexOf(m.Groups[1].Value) - 1).Replace('.', ' ');
                if (search.EndsWith(' '))
                {
                    search = search.Substring(0, search.ToString().Length);
                }
                ViewData["searchString"] = search;
                model.Type = DownloadType.Movie;
            }
            else
            {
                m = new Regex("(English|German)").Match(model.Name);
                if (m.Success)
                {
                    string search = model.Name.Substring(0, model.Name.LastIndexOf(m.Value)).Replace('.', ' ');
                    if (search.EndsWith(' '))
                    {
                        search = search.Substring(0, search.ToString().Length - 1);
                    }
                    ViewData["searchString"] = search;
                    model.Type = DownloadType.Movie;
                }
            }

            m = new Regex(@"S([0-9]{1,2})[a-z \.\\\/\)\-]").Match(model.Name);
            if (m.Success)
            {
                string search = model.Name.Substring(0, model.Name.LastIndexOf(m.Value)).Replace('.', ' ');
                if (search.EndsWith(' '))
                {
                    search = search.Substring(0, search.ToString().Length - 1);
                }
                ViewData["searchString"] = search;
                model.Type = DownloadType.Soap;
            }

            return(View(model));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> AddDlcConfirm(string[] items, AddDlcModel model)
        {
            DownloadGroup group = new DownloadGroup();

            group.Name     = model.Name;
            group.Password = model.Password;
            group.Type     = model.Type;
            group.Sort     = model.nameToSort;

            if (items.Count() < 1)
            {
                throw new Exception("No Items selected/found");
            }

            IDownloader down;

            foreach (string itemStr in items)
            {
                DownloadItem item = new DownloadItem()
                {
                    Url = itemStr
                };

                down         = DownloadHelper.GetDownloader(itemStr);
                item.Hoster  = down.Identifier;
                item.ShareId = down.GetItemId(itemStr);
                item         = await down.GetItemInfo(item);

                group.Items.Add(item);
            }

            group = DownloadHelper.SortGroups(group);
            _context.Groups.Add(group);
            _context.SaveChanges();


            foreach (DownloadItem item in group.Items)
            {
                item.DownloadGroupID = group.ID;
                _context.Items.Add(item);
            }
            _context.SaveChanges();


            return(RedirectToAction("Show", new { id = group.ID }));
        }
Exemplo n.º 3
0
        public async static Task <AddDlcModel> ParseDlc(Stream dlcStream)
        {
            StreamReader s       = new StreamReader(dlcStream);
            string       content = await s.ReadToEndAsync();

            s.Dispose();

            string dlc_key  = content.Substring(content.Length - 88);
            string dlc_data = content.Substring(0, content.Length - 88);

            HttpClient client = new HttpClient();
            string     resp   = "";

            try
            {
                resp = await client.GetStringAsync("http://service.jdownloader.org/dlcrypt/service.php?srcType=dlc&destType=pylo&data=" + dlc_key);
            } catch
            {
                return(null);
            }

            string dlc_enc_key = resp.Substring(4, resp.Length - 9);
            string dlc_dec_key = Decrypt(dlc_enc_key);

            string links_enc = Decrypt(dlc_data, dlc_dec_key).Replace("\0", "");
            string links_dec = UTF8Encoding.Default.GetString(Convert.FromBase64String(links_enc));

            XDocument     xml      = XDocument.Parse(links_dec);
            XElement      package  = xml.Element("dlc").Element("content").Element("package");
            UTF8Encoding  encoding = new UTF8Encoding();
            DownloadGroup group    = new DownloadGroup();
            IDownloader   downloader;

            foreach (XElement file in package.Elements("file"))
            {
                string fileUrl = encoding.GetString(Convert.FromBase64String(file.Element("url").Value));
                downloader = DownloadHelper.GetDownloader(fileUrl);

                if (downloader == null)
                {
                    continue;
                }

                DownloadItem item = new DownloadItem();
                item.Name    = encoding.GetString(Convert.FromBase64String(file.Element("filename").Value));
                item.ShareId = downloader.GetItemId(fileUrl);
                item.Hoster  = downloader.Identifier;
                item.Url     = fileUrl;

                item = await downloader.GetItemInfo(item);



                group.Items.Add(item);
            }

            group = DownloadHelper.SortGroups(group);

            AddDlcModel output = new AddDlcModel();

            output.Name = package.Attribute("name") != null?encoding.GetString(Convert.FromBase64String(package.Attribute("name").Value)).Trim() : "";

            output.Password = "";

            foreach (DownloadItem item in group.Items)
            {
                if (!output.Items.ContainsKey(item.GroupID))
                {
                    output.Items.Add(item.GroupID, new AddDlcGroupModel());
                }

                output.Items[item.GroupID].Items.Add(item);
            }


            return(output);
        }