public static string FilenameFromEpisode(Episode ep, Quality q, string template) { List<object> vars=new List<object>(); MatchCollection m = _varRegex.Matches(template); int cnt = 0; foreach (Match match in m) { if (match.Success) { string t = match.Groups["variable"].Value.ToLower(); int idx = t.IndexOf(":", StringComparison.InvariantCulture); if (idx > 0) t = t.Substring(0, idx); if (Variables.Contains(t)) { TemplateVariables tv = (TemplateVariables) Enum.Parse(typeof (TemplateVariables), t); switch (tv) { case TemplateVariables.show: vars.Add(ep.ShowName); break; case TemplateVariables.episodealpha: vars.Add(ep.EpisodeAlpha ?? string.Empty); break; case TemplateVariables.episodenumeric: vars.Add(ep.EpisodeNumeric); break; case TemplateVariables.seasonalpha: vars.Add(ep.SeasonAlpha ?? string.Empty); break; case TemplateVariables.seasonalphaorshow: if (string.IsNullOrEmpty(ep.SeasonAlpha)) vars.Add(ep.ShowName ?? string.Empty); else vars.Add(ep.SeasonAlpha); break; case TemplateVariables.seasonnumeric: vars.Add(ep.SeasonNumeric); break; case TemplateVariables.index: vars.Add(ep.Index); break; case TemplateVariables.plugin: vars.Add(ep.PluginName); break; case TemplateVariables.resolution: vars.Add(q.ToText()); break; } template = template.Replace("{" + t, "{" + cnt); cnt++; } } } string fname= string.Format(template, vars.ToArray()); foreach (char c in System.IO.Path.GetInvalidFileNameChars()) fname = fname.Replace(c.ToString(), string.Empty); return fname; }
public static EpisodeWithDownloadSettings FromEpisode(Episode ep, Quality q, Format f) { EpisodeWithDownloadSettings e=new EpisodeWithDownloadSettings(); ep.CopyTo(e); e.Quality = q; e.Format = f; return e; }
public void AddDownloadEpisode(Episode ep,Quality quality, ADBaseLibrary.Format format, bool logerror=true) { if (IsInDownloadList(ep.Id, quality)) { if (logerror) { Log(LogType.Info, TemplateParser.FilenameFromEpisode(ep, quality, Settings.Instance.DownloadTemplate) + " was already added"); } } else { DownloadItem dinfo = _manager.Add(EpisodeWithDownloadSettings.FromEpisode(ep,quality,format), Settings.Instance.DownloadTemplate, Settings.Instance.DownloadPath); Log(LogType.Info, "Adding " + dinfo.DownloadInfo.FileName + " to downloads"); objDownloads.AddObject(dinfo); if (objDownloads.Items.Count == 1) objDownloads.SelectedObject = dinfo; RefreshInfo(); } }
private void DownloadEpisodeWithRequest(Episode ep) { Format f = new Format(TemplateParser.FilenameFromEpisode(ep, Settings.Instance.DefaultQuality, Settings.Instance.DownloadTemplate), true); f.FileFormats = Settings.Instance.DefaultFormat; f.FileQuality = Settings.Instance.DefaultQuality; f.Filename = TemplateParser.FilenameFromEpisode(ep, Settings.Instance.DefaultQuality, Settings.Instance.DownloadTemplate); DialogResult d = f.ShowDialog(); if (d == DialogResult.OK) { AddDownloadEpisode(ep, f.FileQuality, f.FileFormats); } }
private void AddEpisodes(Episodes ret, Show show, string data, string seasoname, int seasonnum, bool firstone = false) { MatchCollection col = epsregex.Matches(data); foreach (Match m in col) { if (m.Success) { Episode e = new Episode(); e.Id = int.Parse(m.Groups["id"].Value).ToString(); e.PluginMetadata["Url"]=new Uri("http://www.crunchyroll.com" + m.Groups["url"].Value).ToString(); e.Name = WebUtility.HtmlDecode(m.Groups["title"].Value).Trim(); e.EpisodeAlpha = WebUtility.HtmlDecode(m.Groups["episode"].Value).Trim(); e.SeasonNumeric = seasonnum; e.SeasonAlpha = seasoname; e.ShowName = show.Name; e.ShowId = show.Id; e.Type = show.Type; e.PluginName = show.PluginName; string number = Regex.Replace(e.EpisodeAlpha, "[^0-9]", string.Empty).Trim(); int n = 0; if (int.TryParse(number, out n)) e.EpisodeNumeric = n; else e.EpisodeNumeric = 0; string desc1 = m.Groups["description"].Value; e.ImageUri = new Uri(m.Groups["image"].Value); e.Description = Regex.Unescape(desc1.Substring(1, desc1.Length - 2)); if (!m.Groups["image"].Value.Contains("coming_soon")) ret.Items.Add(e); if (ret.Items.Count > 0 && firstone) return; } } }
private KeyValuePair<string, string> AudioLanguageFromEpisode(Episode ep) { string s1 = ep.ShowName.Replace("(", string.Empty).Replace(")", string.Empty).Trim().ToLower(CultureInfo.InvariantCulture); string s2 = string.IsNullOrEmpty(ep.SeasonAlpha) ? string.Empty : ep.SeasonAlpha.Replace("(", string.Empty).Replace(")", string.Empty).Trim().ToLower(CultureInfo.InvariantCulture); string s3 = string.IsNullOrEmpty(ep.Name) ? string.Empty : ep.Name.Replace("(", string.Empty).Replace(")", string.Empty).Trim().ToLower(CultureInfo.InvariantCulture); foreach (string s in LibSet[DubbedAnimeS].Split('|')) { if (s1.Contains(s) || s2.Contains(s) || s3.Contains(s)) { return new KeyValuePair<string, string>("eng","English"); } } return new KeyValuePair<string, string>("jpn", "日本語"); }
private async Task<Episode> GetEpisodeUpdate(CrunchySession s, Episode placeholder, string datetime) { try { WebStream ws = await WebStream.Get(placeholder.PluginMetadata["Url"], null, LibSet[UserAgentS], null, s.cookies.ToCookieCollection(), SocketTimeout,true,null,_info.ProxyFromGlobalRequirements(_global)); if (ws != null && ws.StatusCode == HttpStatusCode.OK) { if (!VerifyLogin(ws.Cookies)) { ws?.Dispose(); return null; } StreamReader rd = new StreamReader(ws); string dta = rd.ReadToEnd(); rd.Dispose(); Episodes eps = new Episodes(); eps.Items = new List<Episode>(); Show show = new Show(); show.PluginName = placeholder.PluginName; show.Id = placeholder.ShowId; MatchCollection scol = seasonregex.Matches(dta); int seasonnum = scol.Count; if (scol.Count == 0) { AddEpisodes(eps, show, dta, String.Empty, 1, true); } else { Match sma = scol[0]; if (sma.Success) { string data = sma.Value; string seasoname = sma.Groups["season"].Value; AddEpisodes(eps, show, data, seasoname, seasonnum, true); } } if (eps.Items.Count == 0) { ws?.Dispose(); return null; } Episode ep = eps.Items[0]; placeholder.PluginMetadata["Url"] = ep.PluginMetadata["Url"]; placeholder.ImageUri = ep.ImageUri; placeholder.Description = ep.Description; placeholder.EpisodeAlpha = ep.EpisodeAlpha; placeholder.EpisodeNumeric = ep.EpisodeNumeric; placeholder.Id = ep.Id; placeholder.SeasonAlpha = ep.SeasonAlpha; placeholder.SeasonNumeric = ep.SeasonNumeric; placeholder.Name = ep.Name; placeholder.DateTime = datetime; UpdateHistory.Add(placeholder.UniqueTag, JsonConvert.SerializeObject(placeholder)); ws?.Dispose(); return placeholder; } } catch (Exception ) { return null; } return null; }
private async Task<UpdateResponse> Updates(CrunchySession s, ShowType t) { int startpage = 0; UpdateResponse ret = new UpdateResponse(); bool end = false; do { string url = string.Format(LibSet[UpdateUrlS], ShowFromType(t), startpage); WebStream ws = await WebStream.Get(url, null,LibSet[UserAgentS], null, s.cookies.ToCookieCollection(),SocketTimeout,true,null,_info.ProxyFromGlobalRequirements(_global)); if (ws != null && ws.StatusCode == HttpStatusCode.OK) { if (!VerifyLogin(ws.Cookies)) { ws.Dispose(); SetLoginError(ret); return ret; } StreamReader rd = new StreamReader(ws); string dta = rd.ReadToEnd(); rd.Dispose(); MatchCollection scol = updregex.Matches(dta); if (scol.Count == 0) end = true; foreach (Match m in scol) { string show = m.Groups["show"].Value; string image = m.Groups["image"].Value; string title = WebUtility.HtmlDecode(m.Groups["title"].Value); string ep = m.Groups["ep"].Value; Uri ur = new Uri("http://www.crunchyroll.com" + m.Groups["url"].Value); int a = ep.IndexOf("–", StringComparison.InvariantCulture); if (a >= 0) { ep = ep.Substring(0, a).Trim(); string tag = CrunchyPluginInfo.PluginName + "|" + show + "|" + ep; if (UpdateHistory.Exists(tag)) { Episode c = JsonConvert.DeserializeObject<Episode>(UpdateHistory.Get(tag)); ret.Found.Add(c); } else { Episode p = new Episode(); p.PluginMetadata.Add("Url",ur.ToString()); p.ShowName = title; p.ShowId = show; p.PluginName = CrunchyPluginInfo.PluginName; p.UniqueTag = tag; p.ImageUri = new Uri(image); p.Type = t; ret.NotFound.Add(p); } } } } else { ws?.Dispose(); SetWebError(ret); return ret; } ws?.Dispose(); startpage++; } while (!end); return ret; }
public async Task<Response> Download(ISession session, Episode episode, string template, string downloadpath, Quality quality, Format formats, CancellationToken token, IProgress<DownloadInfo> progress) { try { KeyValuePair<string, string> defl = AudioLanguageFromEpisode(episode); CrunchySession sess = session as CrunchySession; if (sess == null) return new Response { ErrorMessage = "Invalid Session", Status = ResponseStatus.InvalidArgument }; if (!episode.PluginMetadata.ContainsKey("Url")) return new Response { ErrorMessage = "Invalid Episode", Status = ResponseStatus.InvalidArgument }; DownloadInfo dp = new DownloadInfo { FileName = TemplateParser.FilenameFromEpisode(episode, quality, template), Format = formats, Percent = 0, Quality = quality }; token.ThrowIfCancellationRequested(); dp.Languages = new List<string>(); dp.Percent = 1; dp.Status = "Getting Metadata"; progress.Report(dp); Config c = await GetStandardConfig(sess, episode.Id, quality); if (c == null) return new Response { ErrorMessage = "Unable to retrieve metadata", Status = ResponseStatus.WebError }; if (!string.IsNullOrEmpty(c.Stream_info.Error)) return new Response { ErrorMessage = "Login Required", Status = ResponseStatus.LoginRequired }; List<Task<CrunchySubtitleInfo>> subTasks = new List<Task<CrunchySubtitleInfo>>(); token.ThrowIfCancellationRequested(); if ((c.Subtitles != null && c.Subtitles.Subtitle != null && c.Subtitles.Subtitle.Count > 0)) { foreach (Subtitle s in c.Subtitles.Subtitle) { subTasks.Add(GetSubtitle(sess, int.Parse(s.Id))); } dp.Percent = 2; dp.Status = "Gettings subtitles"; progress.Report(dp); await Task.WhenAll(subTasks); foreach (CrunchySubtitleInfo s in subTasks.Select(a => a.Result)) dp.Languages.Add(s.Title); } else { dp.Languages.Add("Hardcoded"); } dp.Quality = c.Stream_info.Metadata.Height.ToQuality(); dp.FileName = TemplateParser.FilenameFromEpisode(episode, dp.Quality, template); dp.FullPath = Path.Combine(downloadpath, dp.FileName); string intermediatefile = Path.Combine(downloadpath, dp.FileName + ".tm1"); KeyValuePair<string, string> hh = ParseHost(c.Stream_info.Host); string args = string.Format(LibSet[RTMPDumpArgsS], hh.Key, hh.Value, c.Stream_info.File, intermediatefile); List<string> todeleteFiles = new List<string>(); todeleteFiles.Add(intermediatefile); dp.Percent = 3; dp.Status = "Downloading video"; progress.Report(dp); RTMPDumpParser rtmp = new RTMPDumpParser(); double dbl = 92; double final = 0; rtmp.OnProgress += (val) => { final = val; dp.Percent = (val * dbl / 100) + 3; progress.Report(dp); }; await rtmp.Start(LibSet[RTMPDumpEXES], args, token); if (final < 100) return new Response { ErrorMessage = "Error downloading video", Status = ResponseStatus.TransferError }; List<CrunchySubtitleInfo> sis = subTasks.Select(a => a.Result).ToList(); string inputs = string.Empty; string maps = String.Empty; int pp = 0; foreach (CrunchySubtitleInfo k in sis) { string pth = Path.GetTempFileName() + ".ass"; todeleteFiles.Add(pth); File.WriteAllText(pth, k.Ass); inputs += "-i \"" + pth + "\" "; maps += GetFFMPEGSubtitleArguments(pp + 1, pp, k.Language, k.Title); pp++; } dp.Size = await ReMux(intermediatefile, inputs, maps, formats, defl.Key, defl.Value, 96, 4, dp, progress, token); dp.Percent = 100; dp.Status = "Finished"; progress.Report(dp); foreach (string s in todeleteFiles) { try { File.Delete(s); } catch (Exception) { // ignored } } return new Response { Status = ResponseStatus.Ok, ErrorMessage = "OK" }; } catch (Exception e) { if (e is OperationCanceledException) return new Response {ErrorMessage = "Canceled", Status = ResponseStatus.Canceled}; return new Response {ErrorMessage = e.ToString(), Status = ResponseStatus.SystemError}; } }
public void AddDownloadEpisode(Episode ep) { AddDownloadEpisode(ep,Settings.Instance.DefaultQuality,Settings.Instance.DefaultFormat); }
public async Task<Response> Download(ISession session, Episode episode, string template, string downloadpath, Quality quality, Format formats, CancellationToken token, IProgress<DownloadInfo> progress) { try { string deflangcode = "jpn"; string deflang = "日本語"; Response ret = new Response(); DaiSukiSession s = session as DaiSukiSession; if (s == null) return new Response { ErrorMessage = "Invalid Session", Status = ResponseStatus.InvalidArgument }; if (!episode.PluginMetadata.ContainsKey("Url")) return new Response { ErrorMessage = "Invalid Episode", Status = ResponseStatus.InvalidArgument }; DownloadInfo dp = new DownloadInfo { FileName = TemplateParser.FilenameFromEpisode(episode, quality, template), Format = formats, Percent = 0, Quality = quality }; token.ThrowIfCancellationRequested(); dp.Languages = new List<string>(); dp.Percent = 1; dp.Status = "Getting Metadata"; progress.Report(dp); List<string> todeleteFiles = new List<string>(); WebStream ws = await WebStream.Get(episode.PluginMetadata["Url"], null, LibSet[UserAgentS], null, s.cookies.ToCookieCollection(), SocketTimeout, true, null, _info.ProxyFromGlobalRequirements(_global)); if (ws != null && ws.StatusCode == HttpStatusCode.OK) { if (!VerifyLogin(ws.Cookies)) SetLoginError(ret); else { StreamReader rd = new StreamReader(ws); string dta = rd.ReadToEnd(); rd.Dispose(); ws.Dispose(); Match bgn = bgnWrapper.Match(dta); if (!bgn.Success) { ret.ErrorMessage = "Unable to find Daisuki public key"; ret.Status=ResponseStatus.WebError; return ret; } Match flash = flashVars.Match(dta); if (!flash.Success) { ret.ErrorMessage = "Seems this Episode is a YouTube video, unable to download"; ret.Status = ResponseStatus.WebError; return ret; } MatchCollection col = flash2Vars.Matches(flash.Groups["vars"].Value); Dictionary<string,string> vars=new Dictionary<string, string>(); foreach (Match m in col) { if (m.Success) { vars.Add(m.Groups["name"].Value, m.Groups["value"].Value); } } if (!vars.ContainsKey("s") || !vars.ContainsKey("country") || !vars.ContainsKey("init")) { ret.ErrorMessage = "Some of Daisuki startup variables are missing"; ret.Status = ResponseStatus.WebError; return ret; } token.ThrowIfCancellationRequested(); ws = await WebStream.Get(LibSet[BaseHostS]+bgn.Groups["wrapper"].Value, null, LibSet[UserAgentS], null, s.cookies.ToCookieCollection(), SocketTimeout, true,null, _info.ProxyFromGlobalRequirements(_global)); if (ws == null || ws.StatusCode != HttpStatusCode.OK) { ret.ErrorMessage = "Unable to find Daisuki public key"; ret.Status = ResponseStatus.WebError; ws?.Dispose(); return ret; } rd = new StreamReader(ws); dta = rd.ReadToEnd(); rd.Dispose(); ws.Dispose(); Match mm = publicKey.Match(dta); if (!mm.Success) { ret.ErrorMessage = "Unable to find Daisuki public key"; ret.Status = ResponseStatus.WebError; return ret; } string bld = mm.Groups["key"].Value.Replace("\\n", ""); token.ThrowIfCancellationRequested(); dp.Percent = 2; progress.Report(dp); ws = await WebStream.Get(LibSet[BaseHostS] + vars["country"]+"?cashPath="+ (long)((DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalMilliseconds), null, LibSet[UserAgentS], null, s.cookies.ToCookieCollection(), SocketTimeout, true, episode.PluginMetadata["Url"], _info.ProxyFromGlobalRequirements(_global)); Country c; if (ws == null || ws.StatusCode != HttpStatusCode.OK) { ret.ErrorMessage = "Unable to find Daisuki Country Code"; ret.Status = ResponseStatus.WebError; ws?.Dispose(); return ret; } try { XmlSerializer ser = new XmlSerializer(typeof(Country)); c = (Country)ser.Deserialize(ws); ws.Dispose(); } catch (Exception) { ret.ErrorMessage = "Unable to find Daisuki Country Code"; ret.Status = ResponseStatus.WebError; ws.Dispose(); return ret; } Dictionary<string, string> form = new Dictionary<string, string>(); Api api=new Api(); if (vars.ContainsKey("ss_id")) api.SS_Id = vars["ss_id"]; if (vars.ContainsKey("mv_id")) api.MV_Id = vars["mv_id"]; if (vars.ContainsKey("device_cd")) api.Device_CD = vars["device_cd"]; if (vars.ContainsKey("ss1_prm")) api.SS1_PRM = vars["ss1_prm"]; if (vars.ContainsKey("ss2_prm")) api.SS2_PRM = vars["ss2_prm"]; if (vars.ContainsKey("ss3_prm")) api.SS3_PRM = vars["ss3_prm"]; RSACryptoServiceProvider prov = ProviderFromPEM(bld); AesManaged aes = new AesManaged(); aes.GenerateKey(); aes.Mode=CipherMode.CBC; int blocksize = aes.BlockSize/8; aes.IV=new byte[blocksize]; aes.KeySize=256; aes.Padding=PaddingMode.Zeros; aes.GenerateKey(); byte[] apidata = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(api)); int nsize = ((apidata.Length + (blocksize - 1))/blocksize)*blocksize; if (nsize!=apidata.Length) Array.Resize(ref apidata,nsize); ICryptoTransform t=aes.CreateEncryptor(); byte[] enc=t.TransformFinalBlock(apidata, 0, nsize); byte[] key = prov.Encrypt(aes.Key,false); form.Add("s", vars["s"]); form.Add("c", c.CountryCode); form.Add("e", episode.PluginMetadata["Url"]); form.Add("d", Convert.ToBase64String(enc)); form.Add("a", Convert.ToBase64String(key)); token.ThrowIfCancellationRequested(); string n = form.PostFromDictionary(); ws = await WebStream.Get(LibSet[BaseHostS]+vars["init"]+"?"+n, null, LibSet[UserAgentS], null, s.cookies.ToCookieCollection(), SocketTimeout, true, episode.PluginMetadata["Url"], _info.ProxyFromGlobalRequirements(_global)); if (ws == null || ws.StatusCode != HttpStatusCode.OK) { ret.ErrorMessage = "Unable to retrieve metadata"; ret.Status = ResponseStatus.WebError; ws?.Dispose(); return ret; } rd = new StreamReader(ws); dta = rd.ReadToEnd(); rd.Dispose(); ws.Dispose(); MetaEncrypt menc = JsonConvert.DeserializeObject<MetaEncrypt>(dta); if (menc == null || menc.Status != "00") { ret.ErrorMessage = "Unable to retrieve metadata"; ret.Status = ResponseStatus.WebError; return ret; } t = aes.CreateDecryptor(); byte[] indata = Convert.FromBase64String(menc.EncryptedData); nsize = ((indata.Length + (blocksize - 1)) / blocksize) * blocksize; if (nsize != indata.Length) Array.Resize(ref indata, nsize); byte[] outdata=t.TransformFinalBlock(indata, 0, indata.Length); int start = outdata.Length; while (outdata[start - 1] == 0) start--; if (start!=outdata.Length) Array.Resize(ref outdata,start); string final = Encoding.UTF8.GetString(outdata); Data ldta = JsonConvert.DeserializeObject<Data>(final); NameValueCollection headers = new NameValueCollection(); headers.Add("Accept", "*/*"); headers.Add("Accept-Language", "en-US"); headers.Add("x-flash-version", "18,0,0,232"); string guid = GenGUID(12); string playurl = ldta.play_url + "&g=" + guid + "&hdcore=3.2.0"; token.ThrowIfCancellationRequested(); dp.Percent = 3; dp.Status = "Gettings subtitles"; progress.Report(dp); dp.Languages = new List<string>(); Dictionary<string, string> subtitles = new Dictionary<string, string>(); if (string.IsNullOrEmpty(ldta.caption_url)) dp.Languages.Add("Hardcoded"); else { ws = await WebStream.Get(ldta.caption_url + "?cashPath=" + (long)((DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalMilliseconds), null, LibSet[UserAgentS], headers, null, SocketTimeout, true, "http://img.daisuki.net/common2/pages/anime/swf/bngn_player_001.swf", _info.ProxyFromGlobalRequirements(_global)); if (ws == null || ws.StatusCode != HttpStatusCode.OK) { ret.ErrorMessage = "Unable to retrieve subtitles"; ret.Status = ResponseStatus.WebError; ws?.Dispose(); return ret; } TTML subs = new TTML(ws); subtitles = subs.ToAss(); ws.Dispose(); } dp.Percent = 4; dp.Status = "Downloading video"; progress.Report(dp); token.ThrowIfCancellationRequested(); ws = await WebStream.Get(playurl, null, LibSet[UserAgentS], headers, null, SocketTimeout, true, "http://img.daisuki.net/common2/pages/anime/swf/bngn_player_001.swf", _info.ProxyFromGlobalRequirements(_global)); int idx = playurl.LastIndexOf(".smil/", StringComparison.InvariantCulture); string baseurl = string.Empty; if (idx > 0) baseurl = playurl.Substring(0, idx + 6); if (ws == null || ws.StatusCode != HttpStatusCode.OK) { ret.ErrorMessage = "Unable to retrieve metadata"; ret.Status = ResponseStatus.WebError; ws?.Dispose(); return ret; } XmlSerializer serm = new XmlSerializer(typeof(Manifest)); //Stream ms = File.OpenRead(@"C:\users\mpiva\Downloads\s.manifest"); //Manifest manifest = (Manifest)serm.Deserialize(ms); Manifest manifest = (Manifest)serm.Deserialize(ws); rd.Dispose(); ws.Dispose(); manifest.Init(); KeyValuePair<Media, Quality>? kv = BestMediaFromManifest(manifest, quality); if (kv == null) { ret.ErrorMessage = "Unable to find the best media"; ret.Status = ResponseStatus.WebError; return ret; } dp.Quality = kv.Value.Value; Media media = kv.Value.Key; string inputs = string.Empty; string maps = String.Empty; int pp = 0; foreach (string k in subtitles.Keys) { string pth = Path.GetTempFileName() + ".ass"; todeleteFiles.Add(pth); File.WriteAllText(pth, subtitles[k]); inputs += "-i \"" + pth + "\" "; dp.Languages.Add(Languages.TranslateToOriginalLanguage(k)); maps += GetFFMPEGSubtitleArguments(pp + 1, pp, Languages.CodeFromLanguage(k), Languages.TranslateToOriginalLanguage(k)); pp++; } dp.Percent = 4; dp.FileName = TemplateParser.FilenameFromEpisode(episode, dp.Quality, template); dp.FullPath = Path.Combine(downloadpath, dp.FileName); token.ThrowIfCancellationRequested(); progress.Report(dp); string intermediatefile = dp.FullPath + ".tm1"; /* http://www.daisuki.net/etc/designs/daisuki/swf/bngn_player_002.swf*/ headers["X-Requested-With"] = "ShockwaveFlash/20.0.0.267"; FragmentProcessor frag =new FragmentProcessor(ws.Cookies,headers, LibSet[UserAgentS], SocketTimeout, episode.PluginMetadata["Url"], _info.ProxyFromGlobalRequirements(_global), 2,5,intermediatefile); double dbl = 91; IProgress<double> d = new Progress<double>((val) => { dp.Percent = (val * dbl / 100) + 4; progress.Report(dp); }); todeleteFiles.Add(intermediatefile); await frag.Start(baseurl, guid, manifest, media, token, d); dp.Size = await ReMux(intermediatefile, inputs, maps, formats, deflangcode, deflang, 96, 4, dp, progress, token); dp.Percent = 100; dp.Status = "Finished"; progress.Report(dp); foreach (string del in todeleteFiles) { try { File.Delete(del); } catch (Exception) { } } ret.Status = ResponseStatus.Ok; } } else { SetWebError(ret); } ws?.Dispose(); return ret; } catch (Exception e) { if (e is OperationCanceledException) return new Response { ErrorMessage = "Canceled", Status = ResponseStatus.Canceled }; return new Shows { ErrorMessage = e.ToString(), Status = ResponseStatus.SystemError }; } }
private Episode GetEpisode(Show s, Match m) { var ep=new Episode(); string imgurl = "http://www.daisuki.net/"+m.Groups["image"].Value; ep.ImageUri=new Uri(imgurl); int r = imgurl.LastIndexOf("/"); if (r >= 0) { int n = imgurl.LastIndexOf("/", r - 1); if (n >= 0) { ep.Id = imgurl.Substring(n + 1, r - n - 1); } } ep.EpisodeAlpha = m.Groups["episode"].Value; ep.SeasonNumeric = 0; ep.SeasonAlpha = string.Empty; ep.EpisodeNumeric = 0; int val = 0; if (int.TryParse(ep.EpisodeAlpha,out val)) ep.EpisodeNumeric = val; ep.Name = "Episode " + ep.EpisodeAlpha; ep.PluginName = DaiSukiPluginInfo.PluginName; string nam = s.PluginMetadata["Url"]; r = nam.LastIndexOf("/"); nam = nam.Substring(r + 1); string url = string.Format("http://www.daisuki.net/us/en/anime/watch.{0}.{1}.html",nam,ep.Id); ep.PluginMetadata.Add("Url", url); ep.ShowId = s.Id; ep.ShowName = s.Name; ep.Type = s.Type; return ep; }
public async Task <Response> Download(string plugin, Episode ep, string template, string downloadpath, Quality quality, Format format, CancellationToken token, IProgress <DownloadInfo> progress) { return(await AuthWrapper(plugin, async (plg, session) => await plg.Download(session, ep, template, downloadpath, quality, format, token, progress))); }
public static string FilenameFromEpisode(Episode ep, Quality q, string template) { List <object> vars = new List <object>(); MatchCollection m = _varRegex.Matches(template); int cnt = 0; foreach (Match match in m) { if (match.Success) { string t = match.Groups["variable"].Value.ToLower(); int idx = t.IndexOf(":", StringComparison.InvariantCulture); if (idx > 0) { t = t.Substring(0, idx); } if (Variables.Contains(t)) { TemplateVariables tv = (TemplateVariables)Enum.Parse(typeof(TemplateVariables), t); switch (tv) { case TemplateVariables.show: vars.Add(ep.ShowName); break; case TemplateVariables.episodealpha: vars.Add(ep.EpisodeAlpha ?? string.Empty); break; case TemplateVariables.episodenumeric: vars.Add(ep.EpisodeNumeric); break; case TemplateVariables.seasonalpha: vars.Add(ep.SeasonAlpha ?? string.Empty); break; case TemplateVariables.seasonalphaorshow: if (string.IsNullOrEmpty(ep.SeasonAlpha)) { vars.Add(ep.ShowName ?? string.Empty); } else { vars.Add(ep.SeasonAlpha); } break; case TemplateVariables.seasonnumeric: vars.Add(ep.SeasonNumeric); break; case TemplateVariables.index: vars.Add(ep.Index); break; case TemplateVariables.plugin: vars.Add(ep.PluginName); break; case TemplateVariables.resolution: vars.Add(q.ToText()); break; } template = template.Replace("{" + t, "{" + cnt); cnt++; } } } string fname = string.Format(template, vars.ToArray()); foreach (char c in System.IO.Path.GetInvalidFileNameChars()) { fname = fname.Replace(c.ToString(), string.Empty); } return(fname); }