Created
July 2, 2026 11:57
-
-
Save aozen/194648eef14a3d0f183aba53fe1ff043 to your computer and use it in GitHub Desktop.
Sinefil Export
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 'use strict'; | |
| const path = require('path'); | |
| const os = require('os'); | |
| const fs = require('fs'); | |
| const depsDir = path.join(os.homedir(), '.sinefil', 'node_modules'); | |
| let puppeteer; | |
| try { | |
| puppeteer = require(path.join(depsDir, 'puppeteer-extra')); | |
| puppeteer.use(require(path.join(depsDir, 'puppeteer-extra-plugin-stealth'))()); | |
| } catch { | |
| console.error('[sinefil] Dependencies missing. Run: mkdir -p ~/.sinefil && cd ~/.sinefil && npm install puppeteer@21 puppeteer-extra puppeteer-extra-plugin-stealth'); | |
| process.exit(1); | |
| } | |
| const [username, type] = process.argv.slice(2); | |
| if (!username || !['watched', 'watchlist'].includes(type)) { | |
| console.error('Usage: node sinefil.js <username> <watched|watchlist>'); | |
| process.exit(1); | |
| } | |
| function csvRow(fields) { | |
| return fields.map(f => `"${String(f ?? '').replace(/"/g, '""')}"`).join(',') + '\n'; | |
| } | |
| async function gotoWithRetry(page, url, retries = 3) { | |
| for (let attempt = 1; attempt <= retries; attempt++) { | |
| try { | |
| await page.goto(url, { waitUntil: 'networkidle2', timeout: 30000 }); | |
| return; | |
| } catch (e) { | |
| if (attempt === retries) throw e; | |
| process.stderr.write(` Timeout on attempt ${attempt}, retrying...\n`); | |
| await new Promise(r => setTimeout(r, 5000 * attempt)); | |
| } | |
| } | |
| } | |
| (async () => { | |
| const browser = await puppeteer.launch({ | |
| headless: 'new', | |
| args: ['--no-sandbox', '--disable-setuid-sandbox'], | |
| }); | |
| const page = await browser.newPage(); | |
| const isWatched = type === 'watched'; | |
| const exportsDir = path.join(os.homedir(), '.sinefil', 'exports'); | |
| fs.mkdirSync(exportsDir, { recursive: true }); | |
| const now = new Date(); | |
| const dd = String(now.getDate()).padStart(2, '0'); | |
| const mm = String(now.getMonth() + 1).padStart(2, '0'); | |
| const yyyy = now.getFullYear(); | |
| const hh = String(now.getHours()).padStart(2, '0'); | |
| const min = String(now.getMinutes()).padStart(2, '0'); | |
| const out = path.join(exportsDir, `${username}_${type}_${dd}-${mm}-${yyyy}_${hh}:${min}.csv`); | |
| const fd = fs.openSync(out, 'w'); | |
| const headers = ['Turkish Name', 'Original Name', 'Year', 'IMDB Rating']; | |
| if (isWatched) headers.push('Watch Date'); | |
| fs.writeSync(fd, csvRow(headers)); | |
| let total = 0; | |
| for (let p = 1; ; p++) { | |
| const url = `https://www.sinefil.com/${username}/all/${type}/${p}`; | |
| process.stderr.write(`Page ${p}...\n`); | |
| try { | |
| await gotoWithRetry(page, url); | |
| } catch (e) { | |
| process.stderr.write(` Failed after retries: ${e.message}\n Saving progress and stopping.\n`); | |
| break; | |
| } | |
| if (!page.url().includes(`/${type}/${p}`)) { | |
| process.stderr.write(`Redirected away from page ${p} — done.\n`); | |
| break; | |
| } | |
| let moviesExist = true; | |
| try { | |
| await page.waitForSelector('.movie-container .movie', { timeout: 15000 }); | |
| } catch { | |
| moviesExist = false; | |
| } | |
| if (!moviesExist) { | |
| process.stderr.write(`No movies on page ${p} — done.\n`); | |
| break; | |
| } | |
| const movies = await page.evaluate(() => | |
| Array.from(document.querySelectorAll('.movie-container .movie')).map(card => { | |
| const turkish = card.querySelector('h3.hero a')?.textContent?.trim() ?? ''; | |
| const originalRaw = card.querySelector('.mini-hero')?.textContent?.trim() ?? ''; | |
| const original = originalRaw || turkish; | |
| const year = (card.querySelector('h3.hero .year')?.textContent ?? '').replace(/[()]/g, '').trim(); | |
| const imdbLi = Array.from(card.querySelectorAll('.points .left li')).find(li => | |
| li.textContent.includes('IMDB') | |
| ); | |
| const imdb = imdbLi?.querySelector('.count')?.textContent?.trim() ?? ''; | |
| const watchDateRaw = card.querySelector('.line-number strong')?.textContent?.trim() ?? ''; | |
| return { turkish, original, year, imdb, watchDateRaw }; | |
| }) | |
| ); | |
| for (const m of movies) { | |
| const fields = [m.turkish, m.original, m.year, m.imdb]; | |
| if (isWatched) fields.push(m.watchDateRaw); | |
| fs.writeSync(fd, csvRow(fields)); | |
| } | |
| total += movies.length; | |
| process.stderr.write(` → ${movies.length} movies (total: ${total})\n`); | |
| await new Promise(r => setTimeout(r, 1000)); | |
| } | |
| fs.closeSync(fd); | |
| await browser.close(); | |
| process.stderr.write(`\nDone! ${total} movies saved to ${out}\n`); | |
| })().catch(e => { | |
| process.stderr.write(e.stack + '\n'); | |
| process.exit(1); | |
| }); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Setup (one-time):
Run:
node sinefil.js <watched|watchlist>
Or as a shell alias:
sinefil() { curl -s https://gist.githubusercontent.com/aozen/194648eef14a3d0f183aba53fe1ff043/raw | node - "$@"; }Output CSV lands in ~/.sinefil/exports/.
Note: 7 years ago, I wrote same script with php in 40 line. GG Javascript