Spaces:
Paused
Paused
Update main.py
Browse files1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950import requestsfrom bs4 import BeautifulSoupimport jsonimport redef scrape_media_server(base_url):all_movies = []try:response = requests.get(base_url, timeout=10)# တကယ်လို့ 403 Forbidden ပြရင် ဒီနည်းလမ်းနဲ့ ယူလို့မရပါif response.status_code != 200:print(f"Access Denied (Status: {response.status_code}). Server directory is private.")return []soup = BeautifulSoup(response.text, 'html.parser')# Folder link တွေနဲ့ File link တွေကို ရှာမယ်links = soup.find_all('a')for link in links:href = link.get('href')# ဖိုင်နာမည်ထဲမှာ (2026) ပါတဲ့ mp4 တွေကိုပဲ စစ်ထုတ်မယ်if ".mp4" in href and "2026" in href:# URL ထဲကနေ နာမည်ကို ပြန်သန့်စင်မယ်raw_name = href.split('/')[-1].replace('%20', ' ').replace('.mp4', '')movie_data = {"movie_name": raw_name,"poster": f"https://stream.cmapp.tv/file/.../posters/default.jpg", # Poster ကို pattern အတိုင်း ချိန်ညှိရန်"year": 2026,"genre": "Action/Drama","stream_url": base_url + href}all_movies.append(movie_data)print(f"Found: {raw_name}")except Exception as e:print(f"Error: {e}")return all_moviesif __name__ == "__main__":# သင်ပေးထားတဲ့ လမ်းကြောင်းအတိုင်း စမ်းကြည့်ရန်target_url = "https://stream.cmreel.com/file/2025-step-190425/Movie-2025-Step/003/Tiff/"results = scrape_media_server(target_url)with open('movies_list.json', 'w', encoding='utf-8') as f:json.dump(results, f, indent=4, ensure_ascii=False)12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576import jsonimport asynciofrom playwright.async_api import async_playwrightasync def run_scraper():movies_list = []async with async_playwright() as p:# Browser ကို ဖွင့်မယ်browser = await p.chromium.launch(headless=True)# Bot မဟုတ်ကြောင်း ဟန်ဆောင်ရန် User Agent ထည့်မယ်context = await browser.new_context(user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36")page = await context.new_page()# Network ကနေလာတဲ့ JSON response တွေကို ဖမ်းမယ်async def handle_response(response):# API request တွေကို စစ်ထုတ်မယ် (Next.js data သို့မဟုတ် API endpoint)if "api" in response.url or "_next/data" in response.url:try:data = await response.json()# ရလာတဲ့ JSON ထဲမှာ movie list ပါမပါ စစ်မယ်if isinstance(data, dict):# ပုံမှန်အားဖြင့် data['results'] သို့မဟုတ် data['items'] ထဲမှာ ရှိတတ်တယ်print(f"Captured API data from: {response.url}")# ဒီနေရာမှာ data ထဲက movie တွေကို movies_list ထဲ ထည့်မယ်except:passpage.on("response", handle_response)# ၂၀၂၆ ရှာဖွေမှု စာမျက်နှာကို သွားမယ်url = "https://cinemm.com/?search=2026&type=movie"print(f"Navigating to {url}...")await page.goto(url, wait_until="domcontentloaded")# စာမျက်နှာ အောက်ခြေအထိ scroll ဆွဲချမယ် (ဒေတာတွေ အကုန်တက်လာအောင်)for _ in range(3):await page.mouse.wheel(0, 1000)await asyncio.sleep(2)# HTML ထဲကနေ တိုက်ရိုက်ဆွဲထုတ်ခြင်း (Fallback)elements = await page.query_selector_all('a[href*="id="]')for el in elements:title_el = await el.query_selector('h3, b, span')img_el = await el.query_selector('img')if title_el:title = await title_el.inner_text()link = await el.get_attribute('href')poster = await img_el.get_attribute('src') if img_el else ""movies_list.append({"movie_name": title.strip(),"poster": poster,"year": 2026,"id": link.split('id=')[-1] if 'id=' in link else ""})await browser.close()return movies_listif __name__ == "__main__":results = asyncio.run(run_scraper())# Duplicate တွေ ဖယ်မယ်unique_results = {m['id']: m for m in results if m['id']}.values()with open('movies_list.json', 'w', encoding='utf-8') as f:json.dump(list(unique_results), f, indent=4, ensure_ascii=False)print(f"Done! Captured {len(unique_results)} movies.")
main.py+62-36