xkhalid

Ultimate Movies - Khalid

Nov 22nd, 2025
1,217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.57 KB | None | 0 0
  1. /* * 🎬 Movies Ultimate
  2. ------------------
  3. * Design & Dev: Khal * ------------------
  4. -id @ REMiX_KSA
  5. * -------------------------------------
  6. */
  7.  
  8. // --- Configuration ---
  9. acheFileName: "fconst CONFIG = {
  10. baseURL: "https://www.faselhds.xyz",
  11. timeoutSeconds: 20,
  12.  
  13. caselhd_remix_cache.json",
  14. accentColor: new Color("#2c3e50"), // Dark Blue
  15. highlightColor: new Color("#e74c3c"), // Red
  16. lback-url/play?url={url}",
  17. "Infu textColor: new Color("#ffffff"),
  18. bgColor: new Color("#1c1c1e")
  19. };
  20.  
  21. const PLAYERS = {
  22. "SenPlayer": "senplayer://x-ca
  23. lse": "infuse://x-callback-url/play?url={url}",
  24. "VLC": "vlc-x-callback://x-callback-url/stream?url={url}",
  25. "Outplayer": "outplayer://{url}",
  26. "nPlayer": "nplayer-https://{encoded}",
  27. ctions (UITable) ---
  28. "Safari": "{url}",
  29. "نسخ الرابط": "copy"
  30. };
  31.  
  32. // --- Main Execution ---
  33. await run();
  34.  
  35. async function run() {
  36. const state = loadState();
  37. await showMainMenu(state);
  38. }
  39.  
  40. // --- UI Fu
  41. nasync function showMainMenu(state) {
  42. let table = new UITable();
  43. table.showSeparators = true;
  44.  
  45. // Header
  46. addHeader(table, "Movies Ultimate", "By: Jad7 & Edit: Khalid | x: REMiX_KSA");
  47.  
  48. // Menu Items
  49. handleSearch(state);
  50. });
  51.  
  52. addMenuItem(table, "❤️ المفضلة (Favorites)", " addMenuItem(table, "🔥 الأكثر مشاهدة (Trending)", "star.fill", async () => {
  53. await showTrending(state);
  54. });
  55.  
  56. addMenuItem(table, "🔍 بحث جديد (Search)", "magnifyingglass", async () => {
  57. await
  58. heart.fill", async () => {
  59. await showFavorites(state);
  60. });
  61.  
  62. addMenuItem(table, "🕒 سجل البحث (History)", "clock", async () => {
  63. await showHistory(state);
  64. });
  65.  
  66. addMenuItem(table, "⚙️ الإعدادات (Settings)", "gear", async () => {
  67. await handleSettings(state);
  68. });
  69.  
  70. await table.present();
  71. }
  72.  
  73. async function showTrending(state) {
  74. await showNotification("جاري التحميل...", "يتم جلب القائمة...");
  75. // FaselHD doesn't have a simple JSON API, so we scrape the home page or a specific category
  76. // Let's scrape the "Movies" or "Series" page for now, or just the
  77. home page recent additions
  78. let results = await searchFasel("", true); // Empty query with isTrending flag
  79.  
  80. if (results.length === 0) {
  81. await showAlert("تنبيه", "لم يتم العثور على محتوى.");
  82. return;
  83. }
  84.  
  85. await showResultsTable(state, "🔥 الأكثر مشاهدة", results);
  86. }
  87.  
  88. async function showFavorites(state) {
  89. showAlert("السجل", "سجل البحث فارغ.") let favs = state.favorites || [];
  90. if (favs.length === 0) {
  91. await showAlert("المفضلة", "قائمة المفضلة فارغة.");
  92. return;
  93. }
  94. await showResultsTable(state, "❤️ المفضلة", favs, true);
  95. }
  96.  
  97. async function showHistory(state) {
  98. let history = state.history || [];
  99. if (history.length === 0) {
  100. await
  101. ;
  102. return;
  103. }
  104.  
  105. let table = new UITable();
  106. addHeader(table, "سجل البحث");
  107.  
  108. history.forEach(q => {
  109. let row = new UITableRow();
  110. row.dismissOnSelect = true;
  111. row.onSelect = async () => {
  112. await handleSearch(state, q);
  113. };
  114. let cell = row.addText(q);
  115. table.addRow(row);
  116. });
  117.  
  118. // Clear History Option
  119.  
  120.  
  121. await table.present();
  122. }
  123.  
  124. asyn let clearRow = new UITableRow();
  125. clearRow.dismissOnSelect = false; // Don't close, just refresh or alert
  126. let clearCell = clearRow.addText("🗑️ مسح السجل");
  127. clearCell.titleColor = Color.red();
  128. clearRow.onSelect = async () => {
  129. state.history = [];
  130. saveState(state);
  131. await showAlert("تم", "تم مسح السجل");
  132. };
  133. table.addRow(clearRow)
  134. ;c function handleSearch(state, initialQuery = null) {
  135. let query = initialQuery;
  136. if (!query) {
  137. query = await presentPrompt("بحث جديد", "اكتب اسم الفيلم أو المسلسل:");
  138. }
  139.  
  140. if (!query) return;
  141.  
  142. addToHistory(state, query);
  143. await showNotification("جاري البحث...", query);
  144.  
  145. let results = await searchFasel(query);
  146. if (results.length === 0) {
  147. await showAlert("عذراً", "لم يتم العثور على نتائج.");
  148. aceholder.com/1 return;
  149. }
  150.  
  151. await showResultsTable(state, `نتائج: ${query}`, results);
  152. }
  153.  
  154. async function showResultsTable(state, title, items, isFavorites = false) {
  155. let table = new UITable();
  156. addHeader(table, title);
  157.  
  158. for (let item of items) {
  159. let row = new UITableRow();
  160. row.height = 80;
  161. row.dismissOnSelect = true;
  162.  
  163. // Image
  164. let imgCell = row.addImageAtURL(item.img || "https://via.p
  165. l00");
  166. imgCell.widthWeight = 20;
  167.  
  168. // Title & Rating
  169. let textCell = row.addText(item.title, item.rating ? `⭐ ${item.rating}` : "");
  170. textCell.widthWeight = 70;
  171. textCell.subtitleColor = Color.gray();
  172.  
  173. row.onSelect = async () => {
  174. await processItem(state, item);
  175. };
  176.  
  177. table.addRow(row);
  178. }
  179.  
  180. await table.present();
  181. }
  182.  
  183. async function processItem(state, item, isSeason = false) {
  184. details.seasons.length > 0) {
  185. // Auto-detect season from title
  186. if (item.title.includes("الموسم") || item.title.includes("Season")) {
  187. isSeason = true;
  188. }
  189.  
  190. await showNotification("جاري المعالجة...", item.title);
  191. let details = await getDetails(item.href);
  192.  
  193. // Case 1: It has seasons AND we are not already in a season view
  194. // This must come BEFORE episodes check to avoid showing random episodes on a series page
  195. if (!isSeason && details.seasons &&
  196. let table = new UITable();
  197. addHeader(table, `مواسم: ${item.title}`);
  198.  
  199. details.seasons.forEach(s => {
  200. let row = new UITableRow();
  201. row.addText(s.title);
  202. row.dismissOnSelect = true;
  203. row.onSelect = async () => {
  204. // Explicitly pass true for isSeason
  205. await processItem(state, s, true);
  206. };
  207. table.addRow(row);
  208. });
  209. await table.present();
  210. return;
  211. }
  212.  
  213. // Case 2: It has episodes
  214. favRow.addText("❤️ إضافة للمفضلة");
  215. if (details.episodes && details.episodes.length > 0) {
  216. // If single episode/movie, play directly or show options
  217. if (details.episodes.length === 1) {
  218. await showEpisodeOptions(state, item, details.episodes[0].href);
  219. } else {
  220. // Show Episodes List
  221. let table = new UITable();
  222. addHeader(table, item.title);
  223.  
  224. // Add "Add to Favorites" row
  225. if (!isFavorite(state, item)) {
  226. let favRow = new UITableRow();
  227.  
  228. favRow.onSelect = () => {
  229. addToFavorites(state, item);
  230. showNotification("تم", "تمت الإضافة للمفضلة");
  231. };
  232. table.addRow(favRow);
  233. }
  234.  
  235. details.episodes.forEach(ep => {
  236. let row = new UITableRow();
  237. row.addText(ep.title);
  238. row.dismissOnSelect = true;
  239. row.onSelect = async () => {
  240. await showEpisodeOptions(state, item, ep.href);
  241. };
  242. table.addRow(row);
  243. });
  244. await table.present();
  245. رابط", "ي }
  246. } else {
  247. await showAlert("خطأ", "لم يتم العثور على محتوى.");
  248. }
  249. }
  250.  
  251. async function showEpisodeOptions(state, item, url) {
  252. // If default player is set, we might want to just play?
  253. // But user wants to Copy Link or Favorite too.
  254. // Let's keep the menu but make it smarter.
  255.  
  256. let options = ["تشغيل", "نسخ الرابط", "إضافة للمفضلة"];
  257. if (isFavorite(state, item)) options = ["تشغيل", "نسخ الرابط", "إزالة من المفضلة"];
  258.  
  259. let idx = await presentMenu(item.title, options);
  260. if (idx === -1) return;
  261.  
  262. if (idx === 0) {
  263. await showNotification("🚀 استخراج ا
  264. لرجى الانتظار...");
  265. let streamUrl = await extractStreamWithWebView(url);
  266. if (streamUrl) {
  267. await playStream(state, streamUrl);
  268. } else {
  269. await showAlert("فشل", "لم يتم العثور على رابط.");
  270. }
  271. } else if (idx === 1) {
  272. await showNotification("🚀 استخراج الرابط", "يرجى الانتظار...");
  273. let streamUrl = await extractStreamWithWebView(url);
  274. if (streamUrl) {
  275. Pasteboard.copy(streamUrl);
  276. await showNotification("تم", "تم نسخ الرابط");
  277. }
  278. } else if (idx === 2) {
  279. if (isFavorite(state, item)) {
  280. removeFromFavorites(state, item);
  281. ;
  282. row.height = 60;
  283. row.dismissOnSelect = true;
  284.  
  285. // Icon await showNotification("تم", "تمت الإزالة من المفضلة");
  286. } else {
  287. addToFavorites(state, item);
  288. await showNotification("تم", "تمت الإضافة للمفضلة");
  289. }
  290. }
  291. }
  292.  
  293. // --- Helper UI Components ---
  294.  
  295. function addHeader(table, title, subtitle = null) {
  296. let row = new UITableRow();
  297. row.isHeader = true;
  298. let cell = row.addText(title, subtitle || "");
  299. cell.titleFont = Font.boldSystemFont(24);
  300. cell.subtitleFont = Font.systemFont(12);
  301. cell.subtitleColor = CONFIG.highlightColor;
  302. table.addRow(row);
  303. }
  304.  
  305. function addMenuItem(table, title, iconName, action) {
  306. let row = new UITableRow(
  307. )
  308. let icon = SFSymbol.named(iconName);
  309. let imgCell = row.addImage(icon.image);
  310. imgCell.widthWeight = 15;
  311. imgCell.tintColor = CONFIG.highlightColor;
  312.  
  313. // Title
  314. let textCell = row.addText(title);
  315. textCell.widthWeight = 85;
  316. textCell.titleFont = Font.systemFont(18);
  317.  
  318. row.onSelect = action;
  319. table.addRow(row);
  320. }
  321.  
  322. // --- Logic & Scraper ---
  323.  
  324. async function searchFasel(query, isTrending = false) {
  325. let url = isTrending ? CONFIG.baseURL : `${CONFIG.baseURL}/?s=${encodeURIComponent(query)}`;
  326. let req = new Request(url);
  327. let html = await req.loadString();
  328.  
  329. // Regex to extract: Link, Title, Image, Rating (optional)
  330. // <div class="postDiv ..."> ... <a href="..."> ... <img ... data-src="..."> ... <div class="h1">...</div> ... </div>
  331.  
  332. let res = [];
  333. // Adjusted Regex to capture Image
  334. let regex = /<div class="postDiv[^"]*">[\s\S]*?<a href="([^"]+)">[\s\S]*?<img[^>]+data-src="([^"]+)"[^>]*>[\s\S]*?<div class="h1">([\s\S]*?)<\/div>/g;
  335.  
  336. if (isTrending) {
  337. // Trending might have different structure or just use the same postDivs on home page
  338. // Usually home page has "postDiv" for recent items.
  339. // Let's try the same regex first.
  340. }
  341.  
  342. let m;
  343. while ((m = regex.exec(html)) !== null) {
  344. let link = m[1].trim();
  345. let img = m[2].trim();
  346. let title = m[3].trim().replace(/<[^>]*>/g, "");
  347. title = title.replace(/&#(\d+);/g, (match, dec) => String.fromCharCode(dec));
  348.  
  349. res.push({ href: link, title: title, img: img });
  350. }
  351. return res;
  352. }
  353.  
  354. async function getDetails(url) {
  355. let req = new Request(url);
  356. let html = await req.loadString();
  357.  
  358. // Seasons
  359. let seasons = [];
  360. // Updated regex for onclick seasons
  361. let seasonRegex = /<div[^>]+class="seasonDiv[^"]*"[^>]*onclick="window\.location\.href\s*=\s*['"]([^'"]+)['"][^>]*>[\s\S]*?<div class="title">([\s\S]*?)<\/div>/g;
  362.  
  363. // Also capture image for seasons if possible? The regex above doesn't capture img.
  364. // Let's try to capture img inside seasonDiv if we want to show it.
  365. // For now, title is enough for the table.
  366.  
  367. let sm;
  368. while ((sm = seasonRegex.exec(html)) !== null) {
  369. let sUrl = sm[1];
  370. if (sUrl.startsWith("/")) sUrl = CONFIG.baseURL + sUrl;
  371. seasons.push({ href: sUrl, title: sm[2].trim(), img: null }); /
  372. / Placeholder img
  373. }
  374.  
  375. // Episodes
  376. let eps = [];
  377. let regex = /<a href="([^"]+)"[^>]*>\s*(?:<[^>]+>)*\s*(?:الحلقة|Episode)\s*(\d+)/gi;
  378. let m;
  379. while ((m = regex.exec(html)) !== null) {
  380. eps.push({ href: m[1], title: `الحلقة ${m[2]}` });
  381. }
  382.  
  383. if (eps.length === 0) {
  384. eps.push({ title: "فيلم كامل / الحلقة", href: url });
  385. }
  386.  
  387. // Sort episodes
  388. if (eps.length > 1 && eps[0].title.includes("الحلقة")) {
  389. let firstNum = parseInt(eps[0].title.match(/\d+/)[0]);
  390. let lastNum = parseInt(eps[eps.length - 1].title.match(/\d+/)[0]);
  391. if (firstNum > lastNum) eps.reverse();
  392. }
  393.  
  394. return { seasons: seasons, episodes: eps };
  395. }
  396.  
  397. async function extractStreamWithWebView(pageUrl) {
  398. // Same extraction logic as before
  399. let html = await new Request(pageUrl).loadString();
  400. if (window.jwplayer){
  401. let playerUrl = null;
  402.  
  403. let m = html.match(/<iframe[^>]+name="player_iframe"[^>]+src="([^"]+)"/i) ||
  404. html.match(/player_iframe\.location\.href\s*=\s*['"]([^'"]+)['"]/);
  405. if (m) playerUrl = m[1];
  406. if (!playerUrl) {
  407. let m2 = html.match(/<iframe[^>]+src="([^"]+master\.m3u8[^"]+)"/);
  408. if (m2) return m2[1];
  409. }
  410. if (!playerUrl) return null;
  411. if (playerUrl.startsWith("//")) playerUrl = "https:" + playerUrl;
  412.  
  413. let wv = new WebView();
  414. await wv.loadURL(playerUrl);
  415.  
  416. let maxRetries = CONFIG.timeoutSeconds;
  417. for (let i = 0; i < maxRetries; i++) {
  418. let jsResult = await wv.evaluateJavaScript(`
  419. (function(){
  420. try{
  421. let v = document.querySelector('video');
  422. if (v && v.src && (v.src.includes('.m3u8') || v.src.includes('.mp4'))) return v.src;
  423.  
  424. try{
  425. let p = window.jwplayer();
  426. if (p && p.getPlaylist){
  427. let list = p.getPlaylist();
  428. if (list && list.length > 0 && list[0].file) return list[0].file;
  429. }
  430. }catch(e){}
  431. }
  432. let html = document.body.innerHTML;
  433. let match = html.match(/(https?:\\/\\/[^"']+\\.m3u8)/);
  434. if (match) return match[1];
  435. }catch(e){}
  436. return null;
  437. })()
  438. `);
  439. if (jsResult) return jsResult;
  440. await new Promise(r => Timer.schedule(1000, false, r));
  441. }
  442. return null;
  443. }
  444.  
  445. async function playStream(state, streamUrl) {
  446. let player = state.defaultPlayer;
  447. if (!player) {
  448. let options = Object.keys(PLAYERS);
  449. let idx = await presentMenu("اختر المشغل", options);
  450. if (idx === -1) return;
  451. player = options[idx];
  452. rn;
  453. }
  454.  
  455. let schemeTemplate = PLAYERS[player];
  456. if (schemeTemplate === "copy") {
  457. Pasteboard.copy(streamUrl);
  458. await showNotification("تم", "تم النسخ");
  459. return;
  460. }
  461.  
  462. let finalUrl;
  463. if (schemeTemplate.includes("{url}")) {
  464. finalUrl = schemeTemplate.replace("{url}", streamUrl);
  465. } else if (schemeTemplate.includes("{encoded}")) {
  466. finalUrl = schemeTemplate.replace("{encoded}", encodeURIComponent(streamUrl));
  467. } else {
  468. finalUrl = schemeTemplate + encodeURIComponent(streamUrl);
  469. }
  470. Safari.open(finalUrl);
  471. }
  472.  
  473. // --- State & Settings ---
  474.  
  475. async function handleSettings(state) {
  476. let players = Object.keys(PLAYERS);
  477. let menu = [
  478. `المشغل الافتراضي: ${state.defaultPlayer || "غير محدد"}`,
  479. "مسح البيانات المؤقتة"
  480. ];
  481.  
  482. let idx = await presentMenu("الإعدادات", menu);
  483. if (idx === -1) ret
  484. u if (idx === 0) {
  485. let pIdx = await presentMenu("اختر المشغل الافتراضي", ["سؤالي كل مرة", ...players]);
  486. if (pIdx === -1) return;
  487. if (pIdx === 0) state.defaultPlayer = null;
  488. else state.defaultPlayer = players[pIdx - 1];
  489. saveState(state);
  490. await showAlert("تم", "تم حفظ الإعدادات");
  491. } else if (idx === 1) {
  492. // Clear cache logic
  493. let fm = FileManager.local();
  494. let path = getCachePath(fm);
  495. if (fm.fileExists(path)) fm.remove(path);
  496. await showAlert("تم", "تم مسح البيانات");
  497. }
  498. }
  499.  
  500. function getCachePath(fm) {
  501. return fm.joinPath(fm.documentsDirectory(), CONFIG.cacheFileName);
  502. }
  503.  
  504. function loadState() {
  505. let fm = FileManager.local();
  506. let path = getCachePath(fm);
  507. if (fm.fileExists(path)) {
  508. try {
  509. return JSON.parse(fm.readString(path));
  510. } catch (e) { return { history: [], favorites: [], defaultPlayer: null }; }
  511. .some }
  512. return { history: [], favorites: [], defaultPlayer: null };
  513. }
  514.  
  515. function saveState(state) {
  516. let fm = FileManager.local();
  517. let path = getCachePath(fm);
  518. fm.writeString(path, JSON.stringify(state));
  519. }
  520.  
  521. function addToHistory(state, query) {
  522. state.history = state.history || [];
  523. state.history = state.history.filter(h => h !== query);
  524. state.history.unshift(query);
  525. if (state.history.length > 10) state.history.pop();
  526. saveState(state);
  527. }
  528.  
  529. function addToFavorites(state, item) {
  530. state.favorites = state.favorites || [];
  531. if (!state.favorites.find(f => f.href === item.href)) {
  532. state.favorites.push(item);
  533. saveState(state);
  534. }
  535. }
  536.  
  537. function removeFromFavorites(state, item) {
  538. state.favorites = state.favorites || [];
  539. state.favorites = state.favorites.filter(f => f.href !== item.href);
  540. saveState(state);
  541. }
  542.  
  543. function isFavorite(state, item) {
  544. return (state.favorites || []
  545. )(f => f.href === item.href);
  546. }
  547.  
  548. // --- Standard UI Helpers ---
  549. async function presentPrompt(title, msg) {
  550. let a = new Alert();
  551. a.title = title;
  552. a.message = msg;
  553. a.addTextField("اكتب هنا...", "");
  554. a.addAction("بحث");
  555. a.addCancelAction("إلغاء");
  556. return (await a.present()) === -1 ? null : a.textFieldValue(0);
  557. }
  558.  
  559. async function presentMenu(title, items) {
  560. let a = new Alert();
  561. a.title = title;
  562. items.forEach(i => a.addAction(i));
  563. a.addCancelAction("إلغاء");
  564. return await a.presentSheet();
  565. }
  566.  
  567. async function showAlert(title, msg) {
  568. let a = new Alert();
  569. a.title = title;
  570. a.message = msg;
  571. a.addAction("موافق");
  572. await a.present();
  573. }
  574.  
  575. async function showNotification(title, body) {
  576. let n = new Notification();
  577. n.title = title;
  578. n.body = body;
  579. n.schedule();
  580. }
Advertisement
Add Comment
Please, Sign In to add comment