PNRxA commited on
Commit
3476d00
·
1 Parent(s): 158dffd

add ratings badges section to homepage, mal example poster, simpleicons

Browse files
README.md CHANGED
@@ -485,6 +485,7 @@ OpenPosterDB is made possible by these third-party services and projects:
485
  - **[OMDb (Open Movie Database)](https://www.omdbapi.com/)** ([get API key](https://www.omdbapi.com/apikey.aspx)) — Alternative ratings source for IMDb, Rotten Tomatoes, and Metacritic
486
  - **[Fanart.tv](https://fanart.tv/)** ([get API key](https://fanart.tv/get-an-api-key/)) — High-quality fan art, logos, and backdrops with language and textless support
487
  - **[RPDB (Rating Poster Database)](https://ratingposterdb.com/)** — The original project that inspired OpenPosterDB's API design
 
488
 
489
  ### Rating Sources
490
 
 
485
  - **[OMDb (Open Movie Database)](https://www.omdbapi.com/)** ([get API key](https://www.omdbapi.com/apikey.aspx)) — Alternative ratings source for IMDb, Rotten Tomatoes, and Metacritic
486
  - **[Fanart.tv](https://fanart.tv/)** ([get API key](https://fanart.tv/get-an-api-key/)) — High-quality fan art, logos, and backdrops with language and textless support
487
  - **[RPDB (Rating Poster Database)](https://ratingposterdb.com/)** — The original project that inspired OpenPosterDB's API design
488
+ - **[Simple Icons](https://simpleicons.org/)** — SVG icons for popular brands
489
 
490
  ### Rating Sources
491
 
scripts/regenerate-examples.sh CHANGED
@@ -6,6 +6,7 @@ KEY="t0-free-rpdb"
6
  OUT="$(dirname "$0")/../web/public/examples"
7
 
8
  declare -A POSTERS=(
 
9
  [nosferatu]=tt0013442
10
  [metropolis]=tt0017136
11
  [caligari]=tt0010323
 
6
  OUT="$(dirname "$0")/../web/public/examples"
7
 
8
  declare -A POSTERS=(
9
+ [namakura-gatana]=tt0438075
10
  [nosferatu]=tt0013442
11
  [metropolis]=tt0017136
12
  [caligari]=tt0010323
web/public/icons/imdb.png ADDED
web/public/icons/lb.png ADDED
web/public/icons/mal.png ADDED
web/public/icons/mc.png ADDED
web/public/icons/rt.png ADDED
web/public/icons/rta.png ADDED
web/public/icons/tmdb.png ADDED
web/public/icons/trakt.png ADDED
web/src/views/LandingView.vue CHANGED
@@ -32,6 +32,7 @@ const features = [
32
  const posters = [
33
  { src: "/examples/nosferatu.webp", label: "Nosferatu (1922)" },
34
  { src: "/examples/metropolis.webp", label: "Metropolis (1927)" },
 
35
  {
36
  src: "/examples/caligari.webp",
37
  alt: "The Cabinet of Dr. Caligari (1920)",
@@ -78,10 +79,12 @@ const dataProviders = [
78
  { name: "OMDb", url: "https://www.omdbapi.com/", keyUrl: "https://www.omdbapi.com/apikey.aspx", desc: "Alternative ratings source" },
79
  { name: "Fanart.tv", url: "https://fanart.tv/", keyUrl: "https://fanart.tv/get-an-api-key/", desc: "Fan art, logos, and backdrops" },
80
  { name: "RPDB", url: "https://ratingposterdb.com/", desc: "The original inspiration for this project" },
 
81
  ];
82
 
83
  const ratingSources = [
84
  { name: "IMDb", url: "https://www.imdb.com/" },
 
85
  { name: "Rotten Tomatoes", url: "https://www.rottentomatoes.com/" },
86
  { name: "Metacritic", url: "https://www.metacritic.com/" },
87
  { name: "Trakt", url: "https://trakt.tv/" },
@@ -89,6 +92,17 @@ const ratingSources = [
89
  { name: "MyAnimeList", url: "https://myanimelist.net/" },
90
  ];
91
 
 
 
 
 
 
 
 
 
 
 
 
92
  const logos = [
93
  { src: "/examples/logo-nosferatu.webp", label: "Nosferatu (1922)" },
94
  { src: "/examples/logo-metropolis.webp", label: "Metropolis (1927)" },
@@ -167,8 +181,33 @@ const backdropSizes = [
167
  <div class="space-y-4 text-center">
168
  <h2 class="text-2xl font-semibold">Rating Badges</h2>
169
  <p class="text-sm text-muted-foreground max-w-lg mx-auto">
170
- Rating badges from IMDb, Letterboxd, Rotten Tomatoes, and more are overlaid directly
171
- onto your media posters.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
172
  </p>
173
  <div class="flex flex-wrap justify-center gap-4">
174
  <div v-for="p in posters" :key="p.src" class="space-y-1">
 
32
  const posters = [
33
  { src: "/examples/nosferatu.webp", label: "Nosferatu (1922)" },
34
  { src: "/examples/metropolis.webp", label: "Metropolis (1927)" },
35
+ { src: "/examples/namakura-gatana.webp", alt: "Namakura Gatana (1917)", label: "Namakura Gatana (1917)" },
36
  {
37
  src: "/examples/caligari.webp",
38
  alt: "The Cabinet of Dr. Caligari (1920)",
 
79
  { name: "OMDb", url: "https://www.omdbapi.com/", keyUrl: "https://www.omdbapi.com/apikey.aspx", desc: "Alternative ratings source" },
80
  { name: "Fanart.tv", url: "https://fanart.tv/", keyUrl: "https://fanart.tv/get-an-api-key/", desc: "Fan art, logos, and backdrops" },
81
  { name: "RPDB", url: "https://ratingposterdb.com/", desc: "The original inspiration for this project" },
82
+ { name: "Simple Icons", url: "https://simpleicons.org/", desc: "SVG icons for popular brands" },
83
  ];
84
 
85
  const ratingSources = [
86
  { name: "IMDb", url: "https://www.imdb.com/" },
87
+ { name: "TMDB", url: "https://www.themoviedb.org/" },
88
  { name: "Rotten Tomatoes", url: "https://www.rottentomatoes.com/" },
89
  { name: "Metacritic", url: "https://www.metacritic.com/" },
90
  { name: "Trakt", url: "https://trakt.tv/" },
 
92
  { name: "MyAnimeList", url: "https://myanimelist.net/" },
93
  ];
94
 
95
+ const ratingIcons = [
96
+ { src: "/icons/imdb.webp", label: "IMDb", color: "rgb(180, 145, 15)" },
97
+ { src: "/icons/tmdb.webp", label: "TMDB", color: "rgb(1, 155, 88)" },
98
+ { src: "/icons/rt.webp", label: "Rotten Tomatoes", color: "rgb(185, 35, 8)" },
99
+ { src: "/icons/rta.webp", label: "RT Audience", color: "rgb(185, 35, 8)" },
100
+ { src: "/icons/mc.webp", label: "Metacritic", color: "rgb(75, 150, 38)" },
101
+ { src: "/icons/trakt.webp", label: "Trakt", color: "rgb(175, 15, 45)" },
102
+ { src: "/icons/lb.webp", label: "Letterboxd", color: "rgb(0, 155, 88)" },
103
+ { src: "/icons/mal.webp", label: "MyAnimeList", color: "rgb(34, 60, 120)" },
104
+ ];
105
+
106
  const logos = [
107
  { src: "/examples/logo-nosferatu.webp", label: "Nosferatu (1922)" },
108
  { src: "/examples/logo-metropolis.webp", label: "Metropolis (1927)" },
 
181
  <div class="space-y-4 text-center">
182
  <h2 class="text-2xl font-semibold">Rating Badges</h2>
183
  <p class="text-sm text-muted-foreground max-w-lg mx-auto">
184
+ Aggregate ratings from IMDb, TMDB, Rotten Tomatoes, Metacritic, Trakt, Letterboxd, and
185
+ MyAnimeList.
186
+ </p>
187
+ <div class="flex flex-wrap justify-center items-center gap-4" role="list" aria-label="Supported rating sources">
188
+ <div v-for="icon in ratingIcons" :key="icon.src" role="listitem" class="flex flex-col items-center">
189
+ <div
190
+ class="h-10 w-10 rounded-lg p-1.5"
191
+ :style="{ backgroundColor: icon.color }"
192
+ :title="icon.label"
193
+ >
194
+ <BlurImage
195
+ :src="icon.src"
196
+ :alt="icon.label"
197
+ :width="28"
198
+ :height="28"
199
+ fit="contain"
200
+ />
201
+ </div>
202
+ </div>
203
+ </div>
204
+ </div>
205
+
206
+ <!-- Posters -->
207
+ <div class="space-y-4 text-center">
208
+ <h2 class="text-2xl font-semibold">Posters</h2>
209
+ <p class="text-sm text-muted-foreground max-w-lg mx-auto">
210
+ Rating badges are overlaid directly onto your movie and TV posters.
211
  </p>
212
  <div class="flex flex-wrap justify-center gap-4">
213
  <div v-for="p in posters" :key="p.src" class="space-y-1">
web/vite-plugin-optimize-examples.ts CHANGED
@@ -5,6 +5,9 @@ import type { Plugin } from 'vite'
5
  const IMAGE_EXTS = new Set(['.jpg', '.jpeg', '.png'])
6
  const WEBP_QUALITY = 80
7
 
 
 
 
8
  /** Max widths at 2× retina for each image category on the landing page. */
9
  const MAX_WIDTHS: Record<string, number> = {
10
  'size-backdrop-': 720, // displayed at 360px
@@ -69,12 +72,13 @@ export default function optimizeExamplesPlugin(): Plugin {
69
  const cache = new Map<string, { mtime: number; buf: Buffer }>()
70
 
71
  server.middlewares.use(async (req, res, next) => {
72
- if (!req.url?.startsWith('/examples/') || !req.url.endsWith('.webp')) {
73
- return next()
74
- }
 
75
 
76
- const webpName = req.url.slice('/examples/'.length)
77
- const source = findSource(join(publicDir, 'examples'), webpName)
78
  if (!source) return next()
79
 
80
  try {
@@ -98,38 +102,41 @@ export default function optimizeExamplesPlugin(): Plugin {
98
  })
99
  },
100
 
101
- // Build: convert all example images to WebP, resize, and remove originals
102
  async closeBundle() {
103
- const examplesOut = join(outDir, 'examples')
104
- if (!existsSync(examplesOut)) return
105
- const files = readdirSync(examplesOut).filter(f =>
106
- IMAGE_EXTS.has(extname(f).toLowerCase())
107
- )
108
-
109
- let totalBefore = 0
110
- let totalAfter = 0
111
-
112
- await Promise.all(files.map(async (file) => {
113
- const filePath = join(examplesOut, file)
114
- const origSize = statSync(filePath).size
115
-
116
- const webpName = basename(file, extname(file)) + '.webp'
117
- const webpPath = join(examplesOut, webpName)
118
-
119
- const buf = await toWebP(filePath)
120
-
121
- writeFileSync(webpPath, buf)
122
- unlinkSync(filePath)
123
-
124
- totalBefore += origSize
125
- totalAfter += buf.length
126
- const pct = ((1 - buf.length / origSize) * 100).toFixed(0)
127
- console.log(` ${file} → ${webpName}: ${formatBytes(origSize)} → ${formatBytes(buf.length)} (−${pct}%)`)
128
- }))
129
-
130
- if (totalBefore > 0) {
131
- const pct = ((1 - totalAfter / totalBefore) * 100).toFixed(0)
132
- console.log(` examples total: ${formatBytes(totalBefore)} → ${formatBytes(totalAfter)} (−${pct}%)`)
 
 
 
133
  }
134
  },
135
  }
 
5
  const IMAGE_EXTS = new Set(['.jpg', '.jpeg', '.png'])
6
  const WEBP_QUALITY = 80
7
 
8
+ /** Directories to process. */
9
+ const IMAGE_DIRS = ['examples', 'icons'] as const
10
+
11
  /** Max widths at 2× retina for each image category on the landing page. */
12
  const MAX_WIDTHS: Record<string, number> = {
13
  'size-backdrop-': 720, // displayed at 360px
 
72
  const cache = new Map<string, { mtime: number; buf: Buffer }>()
73
 
74
  server.middlewares.use(async (req, res, next) => {
75
+ if (!req.url?.endsWith('.webp')) return next()
76
+
77
+ const dir = IMAGE_DIRS.find(d => req.url!.startsWith(`/${d}/`))
78
+ if (!dir) return next()
79
 
80
+ const webpName = req.url!.slice(`/${dir}/`.length)
81
+ const source = findSource(join(publicDir, dir), webpName)
82
  if (!source) return next()
83
 
84
  try {
 
102
  })
103
  },
104
 
105
+ // Build: convert all images to WebP, resize, and remove originals
106
  async closeBundle() {
107
+ for (const dir of IMAGE_DIRS) {
108
+ const dirOut = join(outDir, dir)
109
+ if (!existsSync(dirOut)) continue
110
+ const files = readdirSync(dirOut).filter(f =>
111
+ IMAGE_EXTS.has(extname(f).toLowerCase())
112
+ )
113
+ if (files.length === 0) continue
114
+
115
+ let totalBefore = 0
116
+ let totalAfter = 0
117
+
118
+ await Promise.all(files.map(async (file) => {
119
+ const filePath = join(dirOut, file)
120
+ const origSize = statSync(filePath).size
121
+
122
+ const webpName = basename(file, extname(file)) + '.webp'
123
+ const webpPath = join(dirOut, webpName)
124
+
125
+ const buf = await toWebP(filePath)
126
+
127
+ writeFileSync(webpPath, buf)
128
+ unlinkSync(filePath)
129
+
130
+ totalBefore += origSize
131
+ totalAfter += buf.length
132
+ const pct = ((1 - buf.length / origSize) * 100).toFixed(0)
133
+ console.log(` ${file} → ${webpName}: ${formatBytes(origSize)} → ${formatBytes(buf.length)} (−${pct}%)`)
134
+ }))
135
+
136
+ if (totalBefore > 0) {
137
+ const pct = ((1 - totalAfter / totalBefore) * 100).toFixed(0)
138
+ console.log(` ${dir} total: ${formatBytes(totalBefore)} → ${formatBytes(totalAfter)} (−${pct}%)`)
139
+ }
140
  }
141
  },
142
  }
web/vite-plugin-placeholders.ts CHANGED
@@ -5,6 +5,7 @@ import type { Plugin } from 'vite'
5
  const VIRTUAL_ID = 'virtual:placeholders'
6
  const RESOLVED_ID = '\0' + VIRTUAL_ID
7
  const IMAGE_EXTS = new Set(['.jpg', '.jpeg', '.png'])
 
8
 
9
  export default function placeholdersPlugin(): Plugin {
10
  let publicDir: string
@@ -23,49 +24,51 @@ export default function placeholdersPlugin(): Plugin {
23
  async load(id) {
24
  if (id !== RESOLVED_ID) return
25
 
26
- const examplesDir = join(publicDir, 'examples')
27
- if (!existsSync(examplesDir)) {
28
- return `export const placeholders = {};\n`
29
- }
30
- const files = readdirSync(examplesDir).filter(f =>
31
- IMAGE_EXTS.has(extname(f).toLowerCase())
32
- )
33
-
34
  const sharp = (await import('sharp')).default
35
-
36
  const entries: string[] = []
37
- for (const file of files) {
38
- const filePath = join(examplesDir, file)
39
- const ext = extname(file).toLowerCase()
40
- const mime = ext === '.png' ? 'image/png' : 'image/jpeg'
41
- const format = ext === '.png' ? 'png' : 'jpeg'
42
 
43
- const buf = await sharp(filePath)
44
- .resize({ width: 20 })
45
- .toFormat(format, format === 'jpeg' ? { quality: 20 } : {})
46
- .toBuffer()
 
 
 
 
 
 
 
 
47
 
48
- const b64 = `data:${mime};base64,${buf.toString('base64')}`
49
- // Key by .webp extension to match the paths used in components
50
- const webpKey = file.replace(/\.(jpe?g|png)$/i, '.webp')
51
- entries.push(` ${JSON.stringify('/examples/' + webpKey)}: ${JSON.stringify(b64)}`)
 
 
 
 
 
 
52
  }
53
 
54
  return `export const placeholders = {\n${entries.join(',\n')}\n};\n`
55
  },
56
 
57
  configureServer(server) {
58
- const examplesDir = join(publicDir, 'examples')
59
- server.watcher.add(examplesDir)
60
- server.watcher.on('all', (event, path) => {
61
- if (path.startsWith(examplesDir) && IMAGE_EXTS.has(extname(path).toLowerCase())) {
62
- const mod = server.moduleGraph.getModuleById(RESOLVED_ID)
63
- if (mod) {
64
- server.moduleGraph.invalidateModule(mod)
65
- server.hot.send({ type: 'full-reload' })
 
 
66
  }
67
- }
68
- })
69
  },
70
  }
71
  }
 
5
  const VIRTUAL_ID = 'virtual:placeholders'
6
  const RESOLVED_ID = '\0' + VIRTUAL_ID
7
  const IMAGE_EXTS = new Set(['.jpg', '.jpeg', '.png'])
8
+ const IMAGE_DIRS = ['examples', 'icons'] as const
9
 
10
  export default function placeholdersPlugin(): Plugin {
11
  let publicDir: string
 
24
  async load(id) {
25
  if (id !== RESOLVED_ID) return
26
 
 
 
 
 
 
 
 
 
27
  const sharp = (await import('sharp')).default
 
28
  const entries: string[] = []
 
 
 
 
 
29
 
30
+ for (const dir of IMAGE_DIRS) {
31
+ const dirPath = join(publicDir, dir)
32
+ if (!existsSync(dirPath)) continue
33
+ const files = readdirSync(dirPath).filter(f =>
34
+ IMAGE_EXTS.has(extname(f).toLowerCase())
35
+ )
36
+
37
+ for (const file of files) {
38
+ const filePath = join(dirPath, file)
39
+ const ext = extname(file).toLowerCase()
40
+ const mime = ext === '.png' ? 'image/png' : 'image/jpeg'
41
+ const format = ext === '.png' ? 'png' : 'jpeg'
42
 
43
+ const buf = await sharp(filePath)
44
+ .resize({ width: 20 })
45
+ .toFormat(format, format === 'jpeg' ? { quality: 20 } : {})
46
+ .toBuffer()
47
+
48
+ const b64 = `data:${mime};base64,${buf.toString('base64')}`
49
+ // Key by .webp extension to match the paths used in components
50
+ const webpKey = file.replace(/\.(jpe?g|png)$/i, '.webp')
51
+ entries.push(` ${JSON.stringify('/' + dir + '/' + webpKey)}: ${JSON.stringify(b64)}`)
52
+ }
53
  }
54
 
55
  return `export const placeholders = {\n${entries.join(',\n')}\n};\n`
56
  },
57
 
58
  configureServer(server) {
59
+ for (const dir of IMAGE_DIRS) {
60
+ const dirPath = join(publicDir, dir)
61
+ server.watcher.add(dirPath)
62
+ server.watcher.on('all', (event, path) => {
63
+ if (path.startsWith(dirPath) && IMAGE_EXTS.has(extname(path).toLowerCase())) {
64
+ const mod = server.moduleGraph.getModuleById(RESOLVED_ID)
65
+ if (mod) {
66
+ server.moduleGraph.invalidateModule(mod)
67
+ server.hot.send({ type: 'full-reload' })
68
+ }
69
  }
70
+ })
71
+ }
72
  },
73
  }
74
  }