Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
RemoteFork.Plugins.Seasonvar
using RemoteFork.Network;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Globalization;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
namespace RemoteFork.Plugins {
[PluginAttribute(Id = "seasonvar", Version = "0.4.5", Author = "fd_crash&&forkplayer", Name = "Seasonvar",
Description = "Сериалы ТУТ! Сериалы онлайн смотреть бесплатно. Смотреть онлайн",
ImageLink = "http://cdn.seasonvar.ru/images/fav/apple-touch-icon-144x144.png")]
public class Seasonvar : IPlugin {
public static readonly Dictionary<string, List<Match>> SERIAL_MATCHES = new Dictionary<string, List<Match>>();
public static readonly Dictionary<string, Item> SERIAL_ITEMS = new Dictionary<string, Item>();
// SEPARATOR служит для разделения команд при парсинге
public const char SEPARATOR = ';';
public const string PLUGIN_PATH = "pluginPath";
public const string SITE_URL = "http://seasonvar.ru{0}";
public const string IMAGE_URL = "http://cdn.seasonvar.ru/oblojka/{0}.jpg";
public const string SMALL_IMAGE_URL = "http://cdn.seasonvar.ru/oblojka/small/{0}.jpg";
//public const string PAGE = "СТРАНИЦА {0}";
public static string NextPageUrl = string.Empty;
// Item представляет собой класс, содержащащий следующие поля:
//// Name - навзание
//// Link - ссылка (если директория, то ссылка передается на обработку плагину, если файл, то ссылка открывается в проигрывателе)
//// ImageLink - иконка
//// Description - описание, поддерживает HTML формат
//// Type - тип сущности: ItemType.FILE или ItemType.DIRECTORY (по умолчанию)
// Главный метод для обработки запросов
public Playlist GetList(IPluginContext context) {
string path = context.GetRequestParams().Get(PLUGIN_PATH);
path = path == null ? "plugin" : "plugin;" + path;
var arg = path.Split(SEPARATOR);
var items = new List<Item>();
ICommand command = null;
switch (arg.Length) {
case 0:
break;
case 1:
command = new GetRootListCommand();
break;
default:
switch (arg[1]) {
case "eng":
case "rus":
command = new GetFilteringListCommand();
break;
case "series":
command = new GetSeriesListCommand();
break;
case "list":
command = new GetSerialListCommand();
break;
case "voise":
command = new GetVoiseListCommand();
break;
case "search":
command = new SearchSearialsCommand();
break;
case "update":
ClearList();
break;
}
break;
}
NextPageUrl = null;
if (command != null) {
string[] data = new string[4];
for (int i = 0; i < arg.Length; i++) {
data[i] = arg[i];
}
items.AddRange(command.GetItems(context, data));
}
return CreatePlaylist(items, context);
}
private static Playlist CreatePlaylist(List<Item> items, IPluginContext context) {
var playlist = new Playlist();
if (!string.IsNullOrEmpty(NextPageUrl)) {
var pluginParams = new NameValueCollection { [PLUGIN_PATH] = NextPageUrl };
playlist.NextPageUrl = context.CreatePluginUrl(pluginParams);
} else {
playlist.NextPageUrl = null;
}
foreach (var item in items) {
if (ItemType.DIRECTORY == item.Type) {
var pluginParams = new NameValueCollection {
[PLUGIN_PATH] = item.Link
};
item.Link = context.CreatePluginUrl(pluginParams);
}
}
playlist.Items = items.ToArray();
return playlist;
}
private static void ClearList() {
SERIAL_MATCHES.Clear();
}
}
public interface ICommand {
List<Item> GetItems(IPluginContext context = null, params string[] data);
}
public class GetRootListCommand : ICommand {
public List<Item> GetItems(IPluginContext context = null, params string[] data) {
List<Item> items = new List<Item>();
var item = new Item() {
Name = "Поиск",
Link = "search",
SearchOn = "Поиск",
ImageLink = "http://icons.iconarchive.com/icons/graphicloads/colorful-long-shadow/256/Search-icon.png"
};
items.Add(item);
item = new Item() {
Name = "Зарубежные",
Link = "eng"
};
items.Add(item);
item = new Item() {
Name = "Отечественные",
Link = "rus"
};
items.Add(item);
item = new Item() {
Name = "Обновить список",
Link = "update"
};
items.Add(item);
return items;
}
}
class FirstSymbolGroupCommand : ICommand {
public List<Item> GetItems(IPluginContext context = null, params string[] data) {
List<Item> items = new List<Item>();
string lang = data.Length > 1 ? data[1] : string.Empty;
string page = data.Length > 2 ? data[2] : string.Empty;
var tempSerials = Seasonvar.SERIAL_MATCHES[lang + "name"];
var group = tempSerials.GroupBy(i => i.Groups[3].Value.Trim().Replace("\"", "#").First());
if (string.IsNullOrEmpty(page)) {
foreach (var g in group) {
var item = new Item() {
Name = g.Key.ToString().Trim(),
Link = string.Format("{1}{0}{2}{0}{3}", Seasonvar.SEPARATOR, lang, "first", g.Key)
};
items.Add(item);
}
items.Sort((a, b) => string.Compare(a.Name, b.Name, StringComparison.Ordinal));
} else {
var g = group.FirstOrDefault(i => i.Key == page.First());
if (g != null) {
foreach (var gg in g) {
var item = new GetSerialInfoCommand().GetItem(context, gg.Groups[1].Value);
item.Name = gg.Groups[3].Value.Trim();
item.Link = string.Format("{1}{0}{2}", Seasonvar.SEPARATOR, "list", gg.Groups[2]);
items.Add(item);
}
}
}
return items;
}
}
class GetFilteringListCommand : ICommand {
public List<Item> GetItems(IPluginContext context = null, params string[] data) {
List<Item> items = new List<Item>();
string lang = data.Length > 1 ? data[1] : string.Empty;
string sort = data.Length > 2 ? data[2] : string.Empty;
string page = data.Length > 3 ? data[3] : string.Empty;
if (sort == "first") {
if (!Seasonvar.SERIAL_MATCHES.ContainsKey(lang + "name")) {
data[2] = "name";
new GetFilteringListCommand().GetItems(context, data);
}
if (Seasonvar.SERIAL_MATCHES.ContainsKey(lang + "name")) {
items.AddRange(new FirstSymbolGroupCommand().GetItems(context, data));
return items;
} else {
sort = "name";
}
} else if (!string.IsNullOrEmpty(page)) {
if (Seasonvar.SERIAL_MATCHES.ContainsKey(lang + sort)) {
items.AddRange(new NextPageCommand().GetItems(context, data));
return items;
}
}
if (string.IsNullOrEmpty(sort)) {
sort = "view";
var item = new Item() {
Name = "По популярности",
Link = string.Format("{1}{0}{2}", Seasonvar.SEPARATOR, lang, "view")
};
items.Add(item);
item = new Item() {
Name = "По названию",
Link = string.Format("{1}{0}{2}", Seasonvar.SEPARATOR, lang, "name")
};
items.Add(item);
item = new Item() {
Name = "По году",
Link = string.Format("{1}{0}{2}", Seasonvar.SEPARATOR, lang, "god")
};
items.Add(item);
item = new Item() {
Name = "По добавлению",
Link = string.Format("{1}{0}{2}", Seasonvar.SEPARATOR, lang, "newest")
};
items.Add(item);
item = new Item() {
Name = "По первому символу",
Link = string.Format("{1}{0}{2}", Seasonvar.SEPARATOR, lang, "first")
};
items.Add(item);
}
List<Match> tempSerials;
if (Seasonvar.SERIAL_MATCHES.ContainsKey(lang + sort)) {
tempSerials = Seasonvar.SERIAL_MATCHES[lang + sort];
} else {
var dataRequest = new Dictionary<string, string>() {
{"filter[only]", lang},
{"filter[rait]", "kp"},
{"filter[sortTo][]", sort},
{"filter[block]", "yes"},
};
var header = new Dictionary<string, string>() {
{"Accept-Encoding", "gzip, deflate, lzma"},
{"Content-Type", "text/html; charset=UTF-8"}
};
var datastring = new StringBuilder();
foreach (var k in dataRequest) {
if (datastring.Length > 0) {
datastring.Append("&");
}
datastring.Append(WebUtility.UrlEncode(k.Key)).Append("=").Append(WebUtility.UrlEncode(k.Value));
}
string response = HTTPUtility
.PostRequest(string.Format(Seasonvar.SITE_URL, "/index.php"), datastring.ToString(), header)
.Replace("\n", " ");
//context.ConsoleLog(string.Format(Seasonvar.SITE_URL, "/index.php") + " datastring=" + datastring);
tempSerials = Regex.Matches(response,
"<a data-id=\"(.*?)\".*?href=\"(.*?)\".*?>(.*?)<",
RegexOptions.Multiline)
.ToList();
//context.ConsoleLog("tempSerials.Count=" + tempSerials.Count);
//
if (tempSerials.Count > 0) {
Seasonvar.SERIAL_MATCHES.Add((lang + sort), tempSerials);
}
}
if (tempSerials != null) {
for (int i = 0; i < Math.Min(50, tempSerials.Count); i++) {
var item = new GetSerialInfoCommand().GetItem(context, tempSerials[i].Groups[1].Value);
item.Name = tempSerials[i].Groups[3].Value.Trim();
item.Link = string.Format("{1}{0}{2}", Seasonvar.SEPARATOR, "list", tempSerials[i].Groups[2]);
items.Add(item);
}
if (tempSerials.Count > 50) {
Seasonvar.NextPageUrl = string.Format("{1}{0}{2}{0}{3}", Seasonvar.SEPARATOR, lang, sort, 50);
//var item = new Item() {
// Name = string.Format(Seasonvar.PAGE, 2),
// Link = string.Format("{1}{0}{2}{0}{3}", Seasonvar.SEPARATOR, lang, sort, 50),
// ImageLink = Seasonvar.NEXT_PAGE_IMAGE_URL
//};
//items.Add(item);
}
}
return items;
}
}
public class GetSerialInfoCommand {
public Item GetItem(IPluginContext context = null, params string[] data) {
Item item;
string id = data[0];
string text = data.Length > 1 ? data[1] : string.Empty;
if (string.IsNullOrEmpty(text)) {
if (Seasonvar.SERIAL_ITEMS.ContainsKey(id)) {
item = Seasonvar.SERIAL_ITEMS[id];
} else {
item = new Item() {
ImageLink = string.Format(Seasonvar.SMALL_IMAGE_URL, id)
};
Seasonvar.SERIAL_ITEMS.Add(id, item);
}
} else {
if (Seasonvar.SERIAL_ITEMS.ContainsKey(id)) {
item = Seasonvar.SERIAL_ITEMS[id];
} else {
item = new Item() {
ImageLink = string.Format(Seasonvar.SMALL_IMAGE_URL, id)
};
Seasonvar.SERIAL_ITEMS.Add(id, item);
}
if (string.IsNullOrEmpty(item.Description)) {
var match = Regex.Match(text, "(data-id-season=\")(\\d+?)(\")");
if (match.Success) {
string seasonId = match.Groups[2].Value;
match = Regex.Match(text, "(<p\\s+itemprop=\"description\">\\s*)(.*?)(\\s*<\\/p>)");
if (match.Success) {
string descText = match.Groups[2].Value;
match = Regex.Match(text, "(itemprop=\"name\">\\s*)(.*?)(\\s*<\\/h1>)");
if (match.Success) {
string name = match.Groups[2].Value;
item.Description =
string.Format(
"<img src=\"{0}\" alt=\"\" align=\"left\"/><h3>{1}</h3>{2}",
string.Format(Seasonvar.IMAGE_URL, seasonId), name.Trim(), descText);
}
}
}
}
}
return item;
}
}
internal class GetSerialListCommand : ICommand {
public List<Item> GetItems(IPluginContext context, params string[] data) {
List<Item> items = new List<Item>();
string url = data.Length > 2 ? data[2] : string.Empty;
var header = new Dictionary<string, string>() {
{"Accept-Encoding", "gzip, deflate, lzma"},
{"Content-Type", "text/html; charset=UTF-8"}
};
string response = HTTPUtility.GetRequest(string.Format(Seasonvar.SITE_URL, url), header);
var matches = Regex.Matches(response,
"(<h2>[.\\s^&]*?<a href=\")((\\S*?)(\\/serial-(\\d+))(\\S*?))(\">[\\s>]*?Сериал)(.+?)(\\s*?(<span>|<\\/a>))",
RegexOptions.Multiline);
if (matches.Count == 1) {
return new GetVoiseListCommand().GetItems(context, data);
} else {
for (int i = 0; i < matches.Count; i++) {
Item item = new GetSerialInfoCommand().GetItem(context, matches[i].Groups[5].Value);
item.Name = matches[i].Groups[8].Value.Trim();
item.Link = string.Format("{1}{0}{2}", Seasonvar.SEPARATOR, "voise", matches[i].Groups[2].Value);
items.Add(item);
}
}
return items;
}
}
public class GetSeriesListCommand : ICommand {
public List<Item> GetItems(IPluginContext context = null, params string[] data) {
List<Item> items = new List<Item>();
string url = data.Length > 2 ? data[2] : string.Empty;
var header = new Dictionary<string, string>() {
{"Accept-Encoding", "gzip, deflate, lzma"},
{"Content-Type", "text/html; charset=UTF-8"}
};
//context.ConsoleLog("url=" + string.Format(Seasonvar.SITE_URL,
// url.Replace("transСтандартный", "trans")));
string response =
HTTPUtility.GetRequest(string.Format(Seasonvar.SITE_URL,
url.Replace("transСтандартный", "trans")), header);
var matches = Regex.Matches(response,
"({)(\"title\"\\s*:\\s*\")(\\d+)(\\s+?)(.+?)(\")(.*?)(\"file\"\\s*:\\s*\")(.+?)(\")(.+?)(\"galabel\"\\s*:\\s*\")(.+?)(\")(.+?)(})",
RegexOptions.Multiline);
var match = Regex.Match(url, "(\\/)(\\d+)(\\/)");
Item item = new GetSerialInfoCommand().GetItem(context, match.Groups[2].Value);
for (int i = 0; i < matches.Count; i++) {
var itemR = new Item() {
Name = string.Format("{0} Серия", matches[i].Groups[3].Value, matches[i].Groups[19].Value),
Link = matches[i].Groups[9].Value,
Type = ItemType.FILE,
ImageLink = item.ImageLink,
Description = item.Description
};
items.Add(itemR);
}
return items;
}
}
public class GetVoiseListCommand : ICommand {
public List<Item> GetItems(IPluginContext context, params string[] data) {
List<Item> items = new List<Item>();
string url = data.Length > 2 ? data[2] : string.Empty;
var header = new Dictionary<string, string>() {
{"Accept-Encoding", "gzip, deflate, lzma"},
{"Content-Type", "text/html; charset=UTF-8"}
};
//context.ConsoleLog("url=" + string.Format(Seasonvar.SITE_URL, url));
string response = HTTPUtility.GetRequest(string.Format(Seasonvar.SITE_URL, url), header)
.Replace("\n", " ");
var match = Regex.Match(response, "'(secureMark)': '(.*?)'.*?'time': (\\d+)");
if (match.Success) {
string secure = match.Groups[2].Value;
string time = match.Groups[3].Value;
//context.ConsoleLog("secure=" + secure);
//context.ConsoleLog("time=" + time);
match = Regex.Match(response, "data-id-serial=\"(.*?)\"");
if (match.Success) {
string serialId = match.Groups[1].Value;
//context.ConsoleLog("serialId=" + serialId);
match = Regex.Match(response, "data-id-season=\"(.*?)\"");
if (match.Success) {
string seasonId = match.Groups[1].Value;
//context.ConsoleLog("seasonId=" + seasonId);
Item item = new GetSerialInfoCommand().GetItem(context, seasonId, response);
var dataRequest = new Dictionary<string, string>() {
{"type", "html5"},
{"id", seasonId},
{"serial", serialId},
{"secure", secure},
{"time", time}
};
header = new Dictionary<string, string>() {
{"X-Requested-With", "XMLHttpRequest"},
{"Accept-Encoding", "gzip, deflate, lzma"},
{"Content-Type", "text/html; charset=UTF-8"}
};
string datastring = "";
foreach (var k in dataRequest) {
if (datastring != "")
datastring += "&";
datastring += WebUtility.UrlEncode(k.Key) + "=" +
WebUtility.UrlEncode(k.Value);
}
//context.ConsoleLog(string.Format(Seasonvar.SITE_URL, "/player.php") + " datastring=" +
// datastring);
response = HTTPUtility
.PostRequest(string.Format(Seasonvar.SITE_URL, "/player.php"), datastring, header)
.Replace("\n", "");
//context.ConsoleLog("response=" + response.Substring(0, 1000));
var matches0 = Regex.Matches(response, " pl = {'0': \"(.*?)\"");
var matches = Regex.Matches(response,
"data-translate=\"([^0].*?)\">(.*?)</li.{1,30}>pl\\[.*?\"(.*?)\"");
//context.ConsoleLog("matches0=" + matches0.Count);
//context.ConsoleLog("matches=" + matches.Count);
if (matches0.Count == 1 && matches.Count < 2) {
data[2] = matches0[0].Groups[1].Value;
return new GetSeriesListCommand().GetItems(context, data);
} else {
if (matches0.Count > 0) {
var itemM = new Item() {
Name = "Стандартный",
Link =
string.Format("{1}{0}{2}", Seasonvar.SEPARATOR, "series",
HttpUtility.UrlDecode(matches0[0].Groups[1].Value)),
ImageLink = item.ImageLink,
Description = item.Description
};
items.Add(itemM);
}
for (int i = 0; i < matches.Count; i++) {
var itemM = new Item() {
Name = matches[i].Groups[2].Value.Trim(),
Link =
string.Format("{1}{0}{2}", Seasonvar.SEPARATOR, "series",
HttpUtility.UrlDecode(matches[i].Groups[3].Value)),
ImageLink = item.ImageLink,
Description = item.Description
};
items.Add(itemM);
}
}
}
}
}
return items;
}
}
class NextPageCommand : ICommand {
public List<Item> GetItems(IPluginContext context = null, params string[] data) {
List<Item> items = new List<Item>();
string lang = data.Length > 1 ? data[1] : string.Empty;
string sort = data.Length > 2 ? data[2] : string.Empty;
string page = data.Length > 3 ? data[3] : string.Empty;
var tempSerials = Seasonvar.SERIAL_MATCHES[lang + sort];
int id;
if (int.TryParse(page, out id)) {
for (int i = id; i < Math.Min(50 + id, Math.Min(tempSerials.Count, tempSerials.Count + id)); i++) {
var item = new GetSerialInfoCommand().GetItem(context, tempSerials[i].Groups[1].Value);
item.Name = tempSerials[i].Groups[3].Value.Trim();
item.Link = string.Format("{1}{0}{2}", Seasonvar.SEPARATOR, "list", tempSerials[i].Groups[2]);
items.Add(item);
}
if (tempSerials.Count - id > 50) {
Seasonvar.NextPageUrl = string.Format("{1}{0}{2}{0}{3}", Seasonvar.SEPARATOR, lang, sort, id + 50);
}
}
return items;
}
}
public class SearchSearialsCommand : ICommand {
public List<Item> GetItems(IPluginContext context, params string[] data) {
List<Item> items = new List<Item>();
string searchText = context.GetRequestParams()["search"];
var header = new Dictionary<string, string>() {
{"Accept-Encoding", "gzip, deflate, lzma"},
{"Content-Type", "text/html; charset=windows-1251"}
};
string response = HTTPUtility.GetRequest(string.Format(Seasonvar.SITE_URL, "/autocomplete.php?query=" + searchText), header);
response = DecodeEncodedNonAsciiCharacters(response);
var matchesIds = Regex.Matches(Regex.Match(response, "(\"id\":\\[)(\"(.*?),*\")+?\\]").Groups[2].Value,
"(\"(\\d+?)\")\\,?");
var matchesValues =
Regex.Matches(Regex.Match(response, "(\"valu\":\\[)(\".*?\",?)\\]").Groups[2].Value,
"(\"(.+?)\"\\,?)");
var matchesDatas =
Regex.Matches(Regex.Match(response, "(\"data\":\\[)(\".*?\",?)\\]").Groups[2].Value,
"(\"(.+?\\.html)\"\\,?)");
for (int i = 0; i < matchesDatas.Count; i++) {
Item item = new GetSerialInfoCommand().GetItem(context, matchesIds[i].Groups[2].Value);
item.Name = matchesValues[i].Groups[2].Value.Trim();
item.Link = string.Format("{1}{0}/{2}", Seasonvar.SEPARATOR, "voise", matchesDatas[i].Groups[2].Value);
items.Add(item);
}
return items;
}
private static string DecodeEncodedNonAsciiCharacters(string value) {
return Regex.Replace(
value,
@"\\u(?<Value>[a-zA-Z0-9]{4})",
m => {
return ((char)int.Parse(m.Groups["Value"].Value, NumberStyles.HexNumber)).ToString();
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.