diff --git a/.gitea/workflows/sync-versions.yml b/.gitea/workflows/sync-versions.yml new file mode 100644 index 0000000..b36be0d --- /dev/null +++ b/.gitea/workflows/sync-versions.yml @@ -0,0 +1,106 @@ +name: Sync Versions to index.json + +on: + push: + branches: + - main + paths: + - '*/*.json' + - '!index.json' + workflow_dispatch: + +jobs: + sync-versions: + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: '18' + + - name: Sync versions from individual JSON files + run: | + node << 'EOF' + const fs = require('fs'); + const path = require('path'); + const { readdirSync } = require('fs'); + + // Read index.json + const indexPath = './index.json'; + const indexData = JSON.parse(fs.readFileSync(indexPath, 'utf8')); + + // Get all directories in current folder + const entries = readdirSync('.', { withFileTypes: true }); + const directoriesWithJsonFiles = entries + .filter(entry => entry.isDirectory() && !entry.name.startsWith('.')) + .map(entry => entry.name) + .filter(dirName => { + const jsonPath = path.join(dirName, `${dirName}.json`); + return fs.existsSync(jsonPath); + }); + + console.log(`Found ${directoriesWithJsonFiles.length} directories with matching JSON files\n`); + + directoriesWithJsonFiles.forEach(dir => { + const filePath = path.join(dir, `${dir}.json`); + try { + const sourceData = JSON.parse(fs.readFileSync(filePath, 'utf8')); + const indexKey = `${dir}/${dir}.json`; + + // Check if this entry exists in index.json + if (indexData[indexKey]) { + // Update version in index.json + if (sourceData.version) { + const oldVersion = indexData[indexKey].version; + indexData[indexKey].version = sourceData.version; + if (oldVersion !== sourceData.version) { + console.log(`✓ ${indexKey}: ${oldVersion} → ${sourceData.version}`); + } else { + console.log(`= ${indexKey}: ${sourceData.version} (no change)`); + } + } + } else { + console.log(`⚠ ${indexKey}: Not found in index.json`); + } + } catch (error) { + console.error(`✗ ${filePath}: ${error.message}`); + } + }); + + // Write updated index.json with pretty formatting + fs.writeFileSync(indexPath, JSON.stringify(indexData, null, 2) + '\n'); + console.log('\n✓ index.json updated successfully'); + EOF + + - name: Check for changes + id: verify + run: | + if git diff --quiet; then + echo "changed=false" >> $GITHUB_OUTPUT + else + echo "changed=true" >> $GITHUB_OUTPUT + git diff + fi + + - name: Configure Git + if: steps.verify.outputs.changed == 'true' + run: | + git config user.name "Gitea Actions Bot" + git config user.email "actions@gitea.local" + + - name: Commit and push changes + if: steps.verify.outputs.changed == 'true' + run: | + git add index.json + git commit -m "chore: sync version strings from individual JSON files" -m "Automatically updated version fields in index.json to match their respective source files" -m "Generated by sync-versions workflow" + git push origin main + env: + GIT_AUTHOR_NAME: Gitea Actions Bot + GIT_AUTHOR_EMAIL: actions@gitea.local + GIT_COMMITTER_NAME: Gitea Actions Bot + GIT_COMMITTER_EMAIL: actions@gitea.local diff --git a/123anime/123anime.js b/123anime/123anime.js new file mode 100644 index 0000000..3810a4c --- /dev/null +++ b/123anime/123anime.js @@ -0,0 +1,129 @@ +async function searchResults(keyword) { + const results = []; + try { + const response = await fetchv2("https://123animes.ru/search?keyword=" + encodeURIComponent(keyword)); + const html = await response.text(); + + const filmListMatch = html.match(/
([\s\S]*?)
<\/div>/); + if (!filmListMatch) { + return JSON.stringify(results); + } + + const filmList = filmListMatch[1]; + const itemRegex = /
[\s\S]*?]*class="poster"[\s\S]*?]*alt="([^"]+)"[^>]*src="([^"]+)"/g; + let match; + while ((match = itemRegex.exec(filmList)) !== null) { + results.push({ + title: match[2].trim(), + image: "https://123animes.ru" + match[3].trim(), + href: "https://123animes.ru" + match[1].trim() + }); + } + + return JSON.stringify(results); + } catch (err) { + return JSON.stringify([{ + title: "Error", + image: "Error", + href: "Error" + }]); + } +} + +async function extractDetails(url) { + try { + const response = await fetchv2(url); + const html = await response.text(); + + let description = "N/A"; + let aliases = "N/A"; + let airdate = "N/A"; + + const descMatch = html.match(/
([\s\S]*?)<\/div>/); + if (descMatch) { + description = descMatch[1].replace(/<[^>]*>/g, "").replace(/\s+/g, " ").trim(); + } + + const aliasMatch = html.match(/

([^<]*)<\/p>/); + if (aliasMatch) { + aliases = aliasMatch[1].trim(); + } + + const airdateMatch = html.match(/

Released:<\/dt>\s*
\s*]*>(\d+)<\/a>/); + if (airdateMatch) { + airdate = airdateMatch[1].trim(); + } + + return JSON.stringify([{ + description: description, + aliases: aliases, + airdate: airdate + }]); + } catch (err) { + return JSON.stringify([{ + description: "Error", + aliases: "Error", + airdate: "Error" + }]); + } +} + +async function extractEpisodes(url) { + const results = []; + try { + const animeId = url.split('/').pop(); + + const response = await fetchv2("https://123animes.ru/ajax/film/sv?id=" + animeId); + const jsonData = await response.json(); + const html = jsonData.html; + + const episodesMatch = html.match(/