Esempio n. 1
0
        public async Task <AccountProfile> GetProfile(AccountModel acc)
        {
            if (!_profiles.ContainsKey(acc.ID))
            {
                if (!_context.Accounts.Any(a => a.ID == acc.ID))
                {
                    return(null);
                }
                AccountProfile profile    = new AccountProfile(acc);
                IDownloader    downloader = DownloadHelper.GetDownloader(profile);
                if (downloader == null)
                {
                    return(null);
                }
                profile = await downloader.DoLogin(profile);

                _profiles.Add(acc.ID, profile);
            }

            return(_profiles[acc.ID]);
        }
Esempio n. 2
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);
        }