Update app.py
Browse files446 unmodified lines447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507764 unmodified lines1272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413 unmodified lines1398139914001401140214031404446 unmodified linesdef unlock_execute_internal(slug):"""统一解锁逻辑"""cached = get_cached_unlock(slug)if cached and cached.get('link'):link = cached['link']return {'success': True,'from_cache': True,'link': link,'pan_type': detect_pan_type(link)}unlock_url = "https://hdhive.com/api/open/resources/unlock"headers = {"X-API-Key": HDHIVE_API_KEY,"Content-Type": "application/json"}payload = {"slug": slug,"allow_points": True}resp = requests.post(unlock_url,headers=headers,json=payload,timeout=30)result = resp.json()data = result.get('data', {}) if isinstance(result, dict) else {}link = (data.get('full_url')or data.get('url')or result.get('url'))if not link:return {'success': False,'error': '未获取到资源链接'}save_cached_unlock(slug, link, result)return {'success': True,'from_cache': False,'link': link,'pan_type': detect_pan_type(link)}@app.route('/api/unlock/execute', methods=['POST'])764 unmodified lineslet link = data.link || '';let panType = data.pan_type || 'unknown';let poster = data.poster || '';let title = data.title || '未知资源';let desc = data.description || '';let panIcon = '';let panText = '';if (panType === '115') { panIcon = '☁️'; panText = '115网盘'; }else if (panType === 'baidu') { panIcon = '🐻'; panText = '百度网盘'; }else if (panType === 'magnet') { panIcon = '🧲'; panText = '磁力链接'; }else { panIcon = '📎'; panText = '其他网盘'; }let cacheBadge = fromCache? '<span style="background:#2ecc71;color:#000;padding:2px 8px;border-radius:12px;font-size:11px;margin-left:8px;">📦 缓存</span>': '';resultDiv.style.display = 'block';resultDiv.innerHTML = `<div style="background:#1e1e1e;border-radius:14px;overflow:hidden;border:1px solid #333;">${poster? `<div style="height:260px; overflow:hidden;"><imgsrc="${poster}"style="width:100%;height:100%;object-fit:cover;display:block;"></div>`: ''}<div style="padding:14px;"><div style="font-size:18px;font-weight:700;margin-bottom:8px;">${title} ${cacheBadge}</div>${desc? `<div style="color:#aaa;font-size:13px;line-height:1.6;margin-bottom:12px;">${desc}</div>`: ''}<div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:10px;flex-wrap:wrap;gap:8px;"><span>${panIcon} ${panText}</span><buttonclass="copy-unlock-link"data-link="${link.replace(/'/g, "\'")}"style="background:#555;border:none;border-radius:16px;padding:4px 12px;color:#fff;cursor:pointer;">📋 复制链接</button></div><div style="word-break:break-all;font-size:12px;"><a href="${link}" target="_blank" style="color:#e50914;">${link}</a></div></div></div>`;document.querySelector('.copy-unlock-link')?.addEventListener('click', function() {let link = this.getAttribute('data-link');navigator.clipboard.writeText(link).then(() => {13 unmodified lines});let data = await resp.json();if (data.success) {await showUnlockResult(data, data.from_cache);} else {let resultDiv = document.getElementById('unlock-result');resultDiv.style.display = 'block';446 unmodified lines447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591764 unmodified lines1356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713 unmodified lines1401140214031404140514061407446 unmodified linesdef unlock_execute_internal(slug):"""统一解锁逻辑(兼容免费/付费/115/详情页)"""cached = get_cached_unlock(slug)if cached and cached.get('link'):link = cached['link']unlock_data = cached.get('unlock_data', {}) or {}return {'success': True,'from_cache': True,'link': link,'pan_type': detect_pan_type(link),'title': unlock_data.get('title', 'HDHive 资源'),'description': unlock_data.get('description', ''),'poster': unlock_data.get('poster', ''),'backdrop': unlock_data.get('backdrop', ''),'unlock_points': unlock_data.get('unlock_points', 0)}unlock_url = "https://hdhive.com/api/resource/unlock"headers = {"Authorization": f"Bearer {HDHIVE_API_KEY}","Accept": "application/json","Content-Type": "application/json","User-Agent": ("Mozilla/5.0 (Windows NT 10.0; Win64; x64) ""AppleWebKit/537.36 Chrome/124.0 Safari/537.36")}payload = {"slug": slug}try:resp = requests.post(unlock_url,headers=headers,json=payload,timeout=30)print("HDHIVE STATUS:", resp.status_code)print("HDHIVE RESPONSE:", resp.text[:1000])if "Just a moment" in resp.text or "<html" in resp.text.lower():return {'success': False,'error': 'HDHive Cloudflare 拦截'}result = resp.json()except Exception as e:return {'success': False,'error': f'接口请求失败: {str(e)}'}data = result.get('data', {}) if isinstance(result, dict) else {}link = (data.get('full_url')or data.get('url')or data.get('link')or result.get('url'))if not link:links = data.get('links', [])if isinstance(links, list) and len(links) > 0:first = links[0]if isinstance(first, dict):link = (first.get('url')or first.get('link')or first.get('full_url'))elif isinstance(first, str):link = firstif not link:return {'success': False,'error': '未获取到资源链接'}title = (data.get('title')or data.get('name')or data.get('resource_title')or 'HDHive 资源')description = (data.get('description')or data.get('intro')or data.get('content')or '')poster = (data.get('poster')or data.get('cover')or data.get('image')or data.get('poster_url')or '')backdrop = (data.get('backdrop')or data.get('background')or '')enriched_result = {'title': title,'description': description,'poster': poster,'backdrop': backdrop,'unlock_points': data.get('unlock_points', 0)}save_cached_unlock(slug, link, enriched_result)return {'success': True,'from_cache': False,'link': link,'pan_type': detect_pan_type(link),'title': title,'description': description,'poster': poster,'backdrop': backdrop,'unlock_points': data.get('unlock_points', 0)}@app.route('/api/unlock/execute', methods=['POST'])764 unmodified lineslet link = data.link || '';let panType = data.pan_type || 'unknown';let poster = data.poster || '';let title = data.title || 'HDHive 资源';let desc = data.description || '';let resultDiv = document.getElementById('unlock-result');let panIcon = '';let panText = '';if (panType === '115') { panIcon = '☁️'; panText = '115网盘'; }else if (panType === 'baidu') { panIcon = '🐻'; panText = '百度网盘'; }else if (panType === 'magnet') { panIcon = '🧲'; panText = '磁力链接'; }else { panIcon = '📎'; panText = '其他网盘'; }let cacheBadge = fromCache ? '<span style="background:#2ecc71; color:#000; padding:2px 8px; border-radius:12px; font-size:11px; margin-left:8px;">📦 缓存</span>' : '';resultDiv.style.display = 'block';resultDiv.innerHTML = `<div style="background: #1e1e1e; border-radius: 12px; padding: 12px; border-left: 3px solid #2ecc71;"><div style="display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; margin-bottom: 8px;"><span style="font-weight: 600;">${panIcon} ${panText} ${cacheBadge}</span><button class="copy-unlock-link" data-link="${link.replace(/'/g, "\\'")}" style="background: #555; border: none; border-radius: 16px; padding: 4px 12px; color: #fff; cursor: pointer; font-size: 11px;">📋 复制链接</button></div><div style="word-break: break-all; font-size: 12px; color: #aaa;"><a href="${link}" target="_blank" style="color: #e50914;">${link}</a></div></div>`;document.querySelector('.copy-unlock-link')?.addEventListener('click', function() {let link = this.getAttribute('data-link');navigator.clipboard.writeText(link).then(() => {13 unmodified lines});let data = await resp.json();if (data.success) {await showUnlockResult(data.link, data.pan_type, data.from_cache);} else {let resultDiv = document.getElementById('unlock-result');resultDiv.style.display = 'block';
app.py+113-110