Spaces:
Paused
Paused
Update app.py
Browse files3 unmodified lines4567789109101112131415151617183 unmodified lines2223242526272526272829303132333435343637383940414243444546474849505152365354383940414243444555565747485859606162505152535463646566676869707172737475767778798081825657585960616263646566676869707172737475767778798081828384858687838485868789909192939495969798991001011021031041051061071081091101111121131141158889909192939495969798991001011021031041051061071081091101111121131141151161171181191191201211221231241251251261271281291291301301311321321331341351361371371381391391401411421433 unmodified linesimport refrom playwright.sync_api import sync_playwright
st.set_page_config(page_title="CineMM Scraper Master", page_icon="🎬")st.set_page_config(page_title="CineMM Scraper Bulletproof", page_icon="🎬")
st.title("🎬 CineMM Movie Scraper Master")st.write("Final refined version for direct MP4 links and full poster URLs.")st.title("🎬 CineMM Movie Scraper Bulletproof")st.write("Most stable version using direct navigation and robust link extraction.")
query = st.text_input("Enter Search Query (e.g., 2026):", "2026")num_movies = st.slider("Number of movies to scrape:", 1, 20, 5)
def scrape_cinemm_master(search_query, limit):def scrape_cinemm_bulletproof(search_query, limit): movies_data = [] base_storage_url = "https://stream.cmapp.tv/file/" 3 unmodified lines page = context.new_page() try: url = f"https://cinemm.com/?search={search_query}&type=movie" st.info(f"Searching CineMM...") page.goto(url, timeout=60000, wait_until="networkidle") search_url = f"https://cinemm.com/?search={search_query}&type=movie" st.info(f"🔍 Searching: {search_query}") page.goto(search_url, timeout=60000, wait_until="networkidle") # Wait for results page.wait_for_selector("h3", timeout=30000) time.sleep(3) # Extract movie links first to avoid stale elements movie_links = [] cards = page.query_selector_all("div.cursor-pointer") st.info(f"Found {len(cards)} movies. Processing top {limit}...") for card in cards: title_el = card.query_selector("h3") img_el = card.query_selector("img") title = title_el.inner_text().strip() if title_el else "Unknown" poster_path = img_el.get_attribute("src") if img_el else "" # We need to get the ID or slug to build the direct URL # Since we can't easily get the href from the div, we'll use the click-and-capture-URL method # but we'll do it more carefully. movie_links.append({ "title": title, "poster": poster_path }) st.info(f"✅ Found {len(movie_links)} movies. Processing...") for i in range(min(len(cards), limit)): for i in range(min(len(movie_links), limit)): try: # Re-fetch cards cards = page.query_selector_all("div.cursor-pointer") if i >= len(cards): break card = cards[i] # Extract basic info from card title_el = card.query_selector("h3") title = title_el.inner_text().strip() if title_el else "Unknown" movie = movie_links[i] st.write(f"⏳ Processing ({i+1}/{limit}): **{movie['title']}**") img_el = card.query_selector("img") poster_path = img_el.get_attribute("src") if img_el else "" # Go back to search page to click the next movie page.goto(search_url, wait_until="networkidle") page.wait_for_selector("h3", timeout=30000) time.sleep(2) # Fix poster URL if it's relative if poster_path and not poster_path.startswith("http"): # If it starts with /file/, prepend the base storage URL if poster_path.startswith("/file/"): poster_url = "https://stream.cmapp.tv" + poster_path # Click the i-th card current_cards = page.query_selector_all("div.cursor-pointer") if i < len(current_cards): current_cards[i].click() page.wait_for_selector("h1", timeout=30000) time.sleep(3) detail_url = page.url body_text = page.inner_text("body") # Extract Direct Link direct_url = detail_url # Default # Look for any link that looks like a stream or download # We can also look for the specific pattern in the HTML html_content = page.content() # Try to find links in the HTML that contain .mp4 or .mkv mp4_links = re.findall(r'https?://[^\s<>"]+\.(?:mp4|mkv)[^\s<>"]*', html_content) if mp4_links: direct_url = mp4_links[0] else: poster_url = base_storage_url + poster_path else: poster_url = poster_path # Click to get direct links card.click() page.wait_for_selector("h1", timeout=20000) time.sleep(3) # Wait for download buttons to load # Extract direct MP4 link from buttons direct_url = "N/A" buttons = page.query_selector_all("button") for btn in buttons: btn_text = btn.inner_text() # Look for buttons that look like download links (contain size info) if "GB" in btn_text or "MB" in btn_text: # We try to capture the link by clicking or looking at the button's behavior # In this specific site, clicking often opens the direct link with page.expect_navigation(timeout=10000) as nav: btn.click() try: nav_info = nav.value if nav_info and (".mp4" in nav_info.url or ".mkv" in nav_info.url or "stream" in nav_info.url): direct_url = nav_info.url break except: # If navigation doesn't happen, the link might be in a different way pass # If still N/A, use the current page URL as fallback if direct_url == "N/A": direct_url = page.url # Try to find stream links stream_links = re.findall(r'https?://stream\.[^\s<>"]+', html_content) if stream_links: direct_url = stream_links[0].split('"')[0].split("'")[0]
# Extract genre and year from detail page body_text = page.inner_text("body") genre = "N/A" if "Genre…." in body_text: genre = body_text.split("Genre….")[1].split("Duration")[0].strip() year = "N/A" year_match = re.search(r"\b(20\d{2}|19\d{2})\b", body_text) if year_match: year = year_match.group(1) movies_data.append({ "logo": poster_url, "url": direct_url, "name": title, "year": year, "genre": genre }) # Go back to search results page.goto(url, wait_until="networkidle") page.wait_for_selector("h3", timeout=20000) time.sleep(1) except Exception as e: st.warning(f"Error processing movie {i+1}: {e}") page.goto(url) # Fix Poster URL poster_path = movie['poster'] if poster_path and not poster_path.startswith("http"): if poster_path.startswith("/file/"): poster_url = "https://stream.cmapp.tv" + poster_path else: poster_url = base_storage_url + poster_path else: poster_url = poster_path
# Extract Genre & Year genre = "N/A" if "Genre…." in body_text: genre = body_text.split("Genre….")[1].split("Duration")[0].strip() year = "N/A" year_match = re.search(r"\b(20\d{2}|19\d{2})\b", body_text) if year_match: year = year_match.group(1) movies_data.append({ "logo": poster_url, "url": direct_url, "name": movie['title'], "year": year, "genre": genre }) except Exception as inner_e: st.warning(f"⚠️ Error on movie {i+1}: {inner_e}") continue except Exception as e: st.error(f"Scraping failed: {e}") st.error(f"❌ Scraping failed: {e}") finally: browser.close() return movies_data
if st.button("Start Master Scraping"):if st.button("Start Bulletproof Scraping"): if not query: st.error("Please enter a search query.") else: with st.spinner("Scraping... This will take a few minutes as it fetches direct links."): data = scrape_cinemm_master(query, num_movies) with st.spinner("🚀 Scraping in progress..."): data = scrape_cinemm_bulletproof(query, num_movies) if data: st.success(f"Successfully scraped {len(data)} movies!") st.success(f"🎉 Successfully scraped {len(data)} movies!") st.json(data) json_str = json.dumps(data, ensure_ascii=False, indent=4) st.download_button( label="Download JSON", label="📥 Download JSON", data=json_str, file_name=f"cinemm_master_{query}.json", file_name=f"cinemm_stable_{query}.json", mime="application/json" ) else:app.py+91-90