/* Decoded by unphp.net */ $matches[1], 'total_pages' => $matches[2]]; } else { return ['error' => 'Page information not found']; } } function fetchHtmlContent($url, $customHeaders = []) { $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_MAXREDIRS, 5); curl_setopt($ch, CURLOPT_TIMEOUT, 30); curl_setopt($ch, CURLOPT_REFERER, 'https://bhojpuriplanet.net/'); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36'); if (!empty($customHeaders) && is_array($customHeaders)) { curl_setopt($ch, CURLOPT_HTTPHEADER, $customHeaders); } $html = curl_exec($ch); if (curl_errno($ch)) { echo "Error fetching content from $url: " . curl_error($ch); curl_close($ch); return false; } $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); if ($httpCode != 200) { echo "HTTP error: $httpCode"; curl_close($ch); return false; } curl_close($ch); return $html; } function getAllFiles($html, $dlMatch) { $pattern = '/href=[\'"](.*?' . preg_quote($dlMatch, '/') . '.*?)[\'"]/i'; if (preg_match_all($pattern, $html, $matches)) { $fileUrls = array_map(function($relativeUrl) { return resolveUrl($GLOBALS['baseUrl'], $relativeUrl); }, $matches[1]); return $fileUrls; } return false; } function resolveUrl($baseUrl, $relativeUrl) { $baseParts = parse_url($baseUrl); $baseUrlPath = isset($baseParts['path']) ? $baseParts['path'] : ''; if (strpos($relativeUrl, '://') !== false) { return $relativeUrl; } elseif (strpos($relativeUrl, '/') === 0) { return $baseParts['scheme'] . '://' . $baseParts['host'] . $relativeUrl; } else { $basePath = $baseParts['scheme'] . '://' . $baseParts['host'] . dirname($baseUrlPath); return rtrim($basePath, '/') . '/' . ltrim($relativeUrl, '/'); } } function getArtistAndThumb($html) { $doc = new DOMDocument(); libxml_use_internal_errors(true); $doc->loadHTML($html); libxml_clear_errors(); $xpath = new DOMXPath($doc); $artistNames = []; $thumbUrl = ''; $albumTitle = ''; $artistLabel = $xpath->query('//b[contains(text(), "Artist :")]')->item(0); if ($artistLabel) { $artistText = trim(str_replace('Artist :', '', $artistLabel->nodeValue), ", "); $artistNames = explode(', ', $artistText); } $thumbNode = $xpath->query('//img[contains(@src, "siteuploads/thumb/c/")]')->item(0); if ($thumbNode) { $thumbUrl = $thumbNode->getAttribute('src'); } $h1Node = $xpath->query('//h1[@class="heading"]')->item(0); //$h1Node = $xpath->query('//h2')->item(0); if ($h1Node) { $albumTitle = trim($h1Node->nodeValue); if (preg_match('/(.*?)(\([^)]+\))/', $albumTitle, $matches)) { $albumTitle = trim($matches[0]); } } return ['artist' => $artistNames, 'thumb' => $thumbUrl, 'albumTitle' => $albumTitle]; } function pagingAndCollectFiles($start, $limit, $dlMatch) { $allFileUrls = []; for ($currentPage = $start; $currentPage <= $limit; $currentPage++) { $pageUrl = $GLOBALS['baseUrl'] . $currentPage . '.html'; $html = fetchHtmlContent($pageUrl); if ($html !== false) { $pageFileUrls = getAllFiles($html, $dlMatch); if ($pageFileUrls !== false) { $pageFileUrls = array_filter($pageFileUrls, function($url) use ($dlMatch) { return strpos($url, $dlMatch) !== false; }); $allFileUrls = array_merge($allFileUrls, $pageFileUrls); } else { } } } return $allFileUrls; } function getAlbumId($baseUrl) { $pattern = '/\/(?:album|tracklist|fl|albumlist|filelist)\/(\d+)\//'; if (preg_match($pattern, $baseUrl, $matches)) { return $matches[1]; } else { return null; } } function getBaseUrl($url) { $parts = parse_url($url); return $parts['scheme'] . '://' . $parts['host']; } function OgImage($baseUrl, $url) { $url = preg_replace('/(_[1-5]\.)/', '_0.', $url); if (strpos($url, '/siteuploads/thumb/sft') !== false) { $url = str_replace(['/sft', '/thumb/'], ['/sfd', '/files/'], $url); $url = preg_replace('/_.*?\.(jpg|webp)$/', '', $url); $url .= '/thumb-' . basename($url) . '.jpg'; } elseif (strpos($url, '/siteuploads/thumb/c') !== false) { $url = preg_replace('/(_[1-5]\.)/', '_0.', $url); } elseif (strpos($url, '/thumb/sft') !== false) { $url = str_replace(['/sft', '/thumb/'], ['/sfd', '/files/'], $url); $url = preg_replace('/_.*?\.(jpg|webp)$/', '', $url); $url .= '/thumb-' . basename($url) . '.jpg'; } elseif (strpos($url, '/thumb/c') !== false) { $url = preg_replace('/(_[1-5]\.)/', '_0.', $url); } return $url; } function resolveDownloadLink($url) { $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_exec($ch); $resolvedUrl = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); curl_close($ch); return $resolvedUrl; } function extractTitleFromDownloadLink($downloadLink) { $title = preg_replace('/.*\//', '', $downloadLink); $title = urldecode($title); return $title; } function sitenameHide($rep, $str) { $str = str_replace('=', ' ', $str); preg_match_all('#[-a-zA-Z0-9@:%_\+.~\#?&//=]{2,256}\.[a-z]{2,4}(\/[-a-zA-Z0-9@:%_\+.~\#?&//=]*)?#si', $str, $result); $host = array_reverse($result[0])[0]; if ($host) { $repArr = ["-[$host]", "[$host]", "-($host)", "($host)", "-{".$host."}", "{".$host."}", "- $host", "-$host", " $host", "$host"]; $str = str_ireplace($repArr, '', $str); } $str = str_ireplace(explode(',', $rep), '', $str); $str = preg_replace('/^[^A-Za-z0-9]$/', '', $str); if (count(explode('-', $str)) > 2) $str = str_replace('-', ' ', $str); $str = str_replace('[128 Kbps]', ' ', $str); if (ctype_lower(preg_replace('/[^A-Za-z]/', '', $str))) $str = ucwords($str); $str = preg_replace('/\s+/', ' ', $str); $str = preg_replace('/\s+\./', '.', $str); $str = str_replace(' 128 Kbps', '', $str); $str = str_replace('"', '', $str); $str = str_replace('.mp3', '', $str); $str = trim($str); return $str; } function scrapeDataV($baseUrl) { //fileshow singer $html = file_get_contents($baseUrl); $dom = new DOMDocument(); libxml_use_internal_errors(true); $dom->loadHTML($html); libxml_clear_errors(); $artistMatches = array(); $labels = $dom->getElementsByTagName('font'); foreach ($labels as $label) { if ($label->textContent === 'Singer : ') { $singerParagraph = $label->parentNode; $singerLinks = $singerParagraph->getElementsByTagName('a'); foreach ($singerLinks as $singerLink) { $artistMatches[] = $singerLink->textContent; } } } return $artistMatches; } function scrapeData($baseUrl, $html) { //fileshow data //preg_match('/(?:Artist|Singer)\s*:\s*(.*?)<\/a>/', $html, $artistMatch); // $artist = isset($artistMatch[1]) ? $artistMatch[1] : null; if (preg_match('/(.*?) Mp3 Song Download/', $html, $titleMatch)) { $fileTitle = isset($titleMatch[1]) ? $titleMatch[1] : null; } else if (preg_match('/<title>(.*?) Download/', $html, $titleMatch)) { $fileTitle = isset($titleMatch[1]) ? $titleMatch[1] : null; } else { $fileTitle = null; } if (preg_match('/<meta property="og:image" content="([^"]+)"/', $html, $ogImageMatch)) { $ogImage = isset($ogImageMatch[1]) ? $ogImageMatch[1] : null; } else if (preg_match('/<meta name="og_image" property="og:image" content="([^"]+)"/', $html, $ogImageMatch)) { $ogImage = isset($ogImageMatch[1]) ? $ogImageMatch[1] : null; } else { $ogImage = null; } if (empty($ogImage)) { preg_match('/<img src="([^"]*\/siteuploads\/thumb\/[^"]+)"/', $html, $thumbnailMatch); $thumbnail = isset($thumbnailMatch[1]) ? $thumbnailMatch[1] : null; $imageUrl = $thumbnail; } else { $imageUrl = $ogImage; } if (preg_match('/<audio[^>]*>.*?<source\s+src="([^"]+)"\s+type="audio\/mpeg".*?<\/audio>/s', $html, $downloadLinkMatch)) { $downloadLink = $downloadLinkMatch[1]; } elseif (preg_match('/<video[^>]*>.*?<source\s+src="([^"]+)"\s+type="video\/mp4".*?<\/video>/s', $html, $videoLinkMatch)) { $downloadLink = $videoLinkMatch[1]; } else { $downloadLink = null; } preg_match('/(?:Lyrics|Lyric|Lyricist By)\s*:\s*(.*?)<\/a>/', $html, $lyricsMatch); $lyrics = isset($lyricsMatch[1]) ? $lyricsMatch[1] : null; preg_match('/(?:Music|Musics|Composed By)\s*:\s*(.*?)<\/a>/', $html, $musicMatch); $music = isset($musicMatch[1]) ? $musicMatch[1] : null; preg_match('/<div class="lyrics">(.*?)<\/div>/s', $html, $lyricsMatch); if (isset($lyricsMatch[1])) { preg_match('/<span id="more">(.*?)<\/span>/s', $lyricsMatch[1], $songlyricsMatch); $songlyrics = isset($songlyricsMatch[1]) ? $songlyricsMatch[1] : null; } else { $songlyrics = null; } if ($songlyrics !== null) { $allowed_tags = '<br></br>'; $songlyrics = strip_tags($songlyrics, $allowed_tags); $songlyrics = str_replace('<br>Read Full Lyrics', '', $songlyrics); $songlyrics = str_replace('Read Full Lyrics', '', $songlyrics); } return [$artist, $fileTitle, $imageUrl, $downloadLink, $lyrics, $music, $songlyrics]; } function extractIdFromUrl($url) { if (preg_match('/\/(?:download|tracklist)\/(\d+)\/[^\/]+\.html/', $url, $matches)) { return $matches[1]; } elseif (preg_match('/\/(?:download|tracklist)\/[^\/]+\/(\d+)\.html/', $url, $matches)) { return $matches[1]; } return false; } function curl_get($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); $output = curl_exec($ch); if ($output === false) { echo "cURL Error: " . curl_error($ch) . " "; curl_close($ch); return false; } curl_close($ch); return $output; } $startURL = isset($_REQUEST['cat']) ? $_REQUEST['cat'] : ""; $parsedURL = parse_url($startURL); $baseURL = $parsedURL['scheme'] . '://' . $parsedURL['host']; $fromPage = isset($_REQUEST['start']) ? $_REQUEST['start'] : 1; $toPage = isset($_REQUEST['end']) ? $_REQUEST['end'] : 1; $response = array(); if (empty($startURL)) { $response['status'] = "error"; $response['message'] = "Please provide a valid Cat URL."; } else { $allAlbums = array(); for ($page = $toPage; $page >= $fromPage; $page--) { $pageURL = $startURL . $page . ".html"; $html = curl_get($pageURL); if ($html === false) { echo "Failed to fetch page URL: $pageURL "; continue; } $albumPattern = '/<a\s+href="([^"]*\/(?:album|tracklist|fl|albumlist|filelist)\/[^"]*)"[^>]*>/i'; if (preg_match_all($albumPattern, $html, $albumMatches)) { foreach ($albumMatches[1] as $albumURL) { $filelist = strpos($albumURL, 'http') === 0 ? $albumURL : $baseURL . $albumURL; $baseUrl = $filelist; $baseUrl = str_replace('/1.html', '/', $baseUrl); $urls = $baseUrl; $SiteUrl = getBaseUrl($urls); $html = fetchHtmlContent($baseUrl . '1.html'); $albumData = array(); if ($html !== false) { $pageInfo = getPageInfo($html); if ($pageInfo) { $albumData['album_info'] = array( 'current_page' => $pageInfo['current_page'], 'total_pages' => $pageInfo['total_pages'] ); $AlbumId = getAlbumId($baseUrl); $AlbumartistAndThumb = getArtistAndThumb($html); $albumData['album_id'] = $AlbumId; $albumData['album_title'] = $AlbumartistAndThumb['albumTitle']; if (!empty($AlbumartistAndThumb['artist'])) { $albumData['album_artist'] = implode(', ', $AlbumartistAndThumb['artist']); } else { $albumData['album_artist'] = "Album Artist not found."; } if (!empty($AlbumartistAndThumb['thumb'])) { $songthumbs = strpos($AlbumartistAndThumb['thumb'], 'http') === 0 ? $AlbumartistAndThumb['thumb'] : $SiteUrl . $AlbumartistAndThumb['thumb']; $songthumbs = OgImage($SiteUrl, $songthumbs); $albumData['album_thumbnail_url'] = $songthumbs; } else { $albumData['album_thumbnail_url'] = "null"; } $startPage = $pageInfo['current_page']; $limitPages = $pageInfo['total_pages']; $dlMatch = $_REQUEST['dl']; $fileUrls = pagingAndCollectFiles($startPage, $limitPages, $dlMatch); $filesData = array(); if (!empty($fileUrls)) { foreach ($fileUrls as $fileUrl) { $url = $fileUrl; $html = fetchHtmlContent($url); $SiteUrl = getBaseUrl($url); [$artist, $fileTitle, $imageUrl, $downloadLink, $lyrics, $music, $songlyrics] = scrapeData($SiteUrl, $html); $artists = scrapeDataV($url); $songid = extractIdFromUrl($url); $songartist = implode(', ', $artists); $songmusic = strip_tags($music); $lyrics = strip_tags($lyrics); $songlyric = $songlyrics; $songthumbs = strpos($imageUrl, 'http') === 0 ? $imageUrl : $baseUrl . $imageUrl; $songthumb = OgImage($baseUrl, $songthumbs); $downloadLinks = strpos($downloadLink, 'http') === 0 ? $downloadLink : $SiteUrl . $downloadLink; $resolvedDownloadLink = resolveDownloadLink($downloadLinks); $file_title = $fileTitle; $file_title = sitenameHide('sitename', $file_title); $fileData = array( 'song_id' => $songid, 'song_title' => $file_title, 'song_artist' => $songartist, 'song_thumbnail_url' => $songthumb, 'download_link' => $resolvedDownloadLink, 'lyrics' => $lyrics, 'music' => $songmusic, 'song_lyrics' => $songlyric, ); $filesData[] = $fileData; } $albumData['files'] = $filesData; } else { $albumData['files'] = "No files found or other errors occurred."; } } else { $albumData['error'] = "Page info not found in the HTML content."; } } else { $albumData['error'] = "Error fetching HTML content from the base URL."; } $allAlbums[] = $albumData; } if (!empty($allAlbums)) { $response['status'] = "success"; $response['message'] = "Request Success"; $response['data'] = $allAlbums; } else { $response['status'] = "error"; $response['message'] = "No albums found."; } } else { echo "No albums found on page URL: $pageURL "; } } header('Access-Control-Allow-Origin: *'); header('Content-Type: application/json'); $jsonResponse = json_encode($response, JSON_UNESCAPED_UNICODE); echo $jsonResponse; } ?>