Skip to content

Commit d5fab3d

Browse files
authored
Merge pull request #6 from nullable-eth/fix-tmdb-regex
feature: update regex to increase matching pattern
2 parents f4d0ed2 + 008dc8c commit d5fab3d

File tree

4 files changed

+438
-22
lines changed

4 files changed

+438
-22
lines changed

Makefile

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Makefile for labelarr
2+
3+
# Go parameters
4+
GOCMD=go
5+
GOBUILD=$(GOCMD) build
6+
GOCLEAN=$(GOCMD) clean
7+
GOTEST=$(GOCMD) test
8+
GOGET=$(GOCMD) get
9+
GOMOD=$(GOCMD) mod
10+
BINARY_NAME=labelarr
11+
BINARY_PATH=./cmd/labelarr
12+
13+
# Build the application
14+
.PHONY: build
15+
build:
16+
$(GOBUILD) -o $(BINARY_NAME) $(BINARY_PATH)
17+
18+
# Run tests
19+
.PHONY: test
20+
test:
21+
$(GOTEST) -v ./...
22+
23+
# Run tests with coverage
24+
.PHONY: test-coverage
25+
test-coverage:
26+
$(GOTEST) -v -cover ./...
27+
28+
# Run tests with coverage report
29+
.PHONY: test-coverage-html
30+
test-coverage-html:
31+
$(GOTEST) -v -coverprofile=coverage.out ./...
32+
$(GOCMD) tool cover -html=coverage.out -o coverage.html
33+
@echo "Coverage report generated: coverage.html"
34+
35+
# Run benchmarks
36+
.PHONY: benchmark
37+
benchmark:
38+
$(GOTEST) -bench=. -benchmem ./...
39+
40+
# Clean build artifacts
41+
.PHONY: clean
42+
clean:
43+
$(GOCLEAN)
44+
rm -f $(BINARY_NAME)
45+
rm -f coverage.out coverage.html
46+
47+
# Download dependencies
48+
.PHONY: deps
49+
deps:
50+
$(GOMOD) download
51+
$(GOMOD) tidy
52+
53+
# Run linter (requires golangci-lint to be installed)
54+
.PHONY: lint
55+
lint:
56+
golangci-lint run
57+
58+
# Run the application
59+
.PHONY: run
60+
run: build
61+
./$(BINARY_NAME)
62+
63+
# Build for multiple platforms
64+
.PHONY: build-all
65+
build-all:
66+
GOOS=linux GOARCH=amd64 $(GOBUILD) -o $(BINARY_NAME)-linux-amd64 $(BINARY_PATH)
67+
GOOS=windows GOARCH=amd64 $(GOBUILD) -o $(BINARY_NAME)-windows-amd64.exe $(BINARY_PATH)
68+
GOOS=darwin GOARCH=amd64 $(GOBUILD) -o $(BINARY_NAME)-darwin-amd64 $(BINARY_PATH)
69+
70+
# Help target
71+
.PHONY: help
72+
help:
73+
@echo "Available targets:"
74+
@echo " build - Build the application"
75+
@echo " test - Run all tests"
76+
@echo " test-coverage - Run tests with coverage"
77+
@echo " test-coverage-html - Generate HTML coverage report"
78+
@echo " benchmark - Run benchmark tests"
79+
@echo " clean - Clean build artifacts"
80+
@echo " deps - Download and tidy dependencies"
81+
@echo " lint - Run linter"
82+
@echo " run - Build and run the application"
83+
@echo " build-all - Build for multiple platforms"
84+
@echo " help - Show this help message"

README.md

Lines changed: 76 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -150,35 +150,59 @@ services:
150150
The application can find TMDb IDs from multiple sources and supports flexible formats:
151151

152152
- **Plex Metadata**: Standard TMDb agent IDs
153-
- **File Paths**: `{tmdb-12345}` in filenames or directory names
154-
- **Flexible Formats**: The TMDb ID can be detected in a variety of patterns, not just `{tmdb-12345}`. Supported patterns include:
155-
- `{tmdb-12345}` (curly braces, anywhere in the folder or file name)
156-
- `[tmdb-12345]` (square brackets)
157-
- `(tmdb-12345)` (parentheses)
158-
- `tmdb-12345` (standalone, with or without delimiters)
159-
- Case-insensitive: `TMDB-12345`, `Tmdb-12345`, etc.
160-
- The TMDb ID can appear in either the directory or file name, and can be surrounded by spaces or other characters.
161-
- **Delimiters**: The TMDb ID pattern supports all common delimiters (such as `:`, `;`, `-`, `_`, etc.) between `tmdb` and the ID. For example:
162-
- `tmdb:15448`
163-
- `tmdb;15448`
164-
- `tmdb-15448`
165-
- `tmdb_15448`
166-
- `tmdb: 15448`, `tmdb- 15448`, etc.
167-
- These can appear in any of the supported bracket/brace/parenthesis formats or standalone.
168-
- The pattern will **not** match `tmdb15448` (no separator).
169-
170-
Example file paths:
153+
- **File Paths**: Flexible TMDb ID detection in filenames or directory names
154+
155+
### ✅ **Supported Patterns** (Case-Insensitive)
156+
157+
The TMDb ID detection is very flexible and supports various formats:
158+
159+
**Direct Concatenation:**
160+
161+
- `/movies/The Matrix (1999) tmdb603/file.mkv`
162+
- `/movies/Inception (2010) TMDB27205/file.mkv`
163+
- `/movies/Avatar (2009) Tmdb19995/file.mkv`
164+
165+
**With Separators:**
166+
167+
- `/movies/Interstellar (2014) tmdb:157336/file.mkv`
168+
- `/movies/The Dark Knight (2008) tmdb-155/file.mkv`
169+
- `/movies/Pulp Fiction (1994) tmdb_680/file.mkv`
170+
- `/movies/Fight Club (1999) tmdb=550/file.mkv`
171+
- `/movies/The Shawshank Redemption (1994) tmdb 278/file.mkv`
172+
173+
**With Brackets/Braces:**
174+
175+
- `/movies/Goodfellas (1990) {tmdb634}/file.mkv`
176+
- `/movies/Forrest Gump (1994) [tmdb-13]/file.mkv`
177+
- `/movies/The Godfather (1972) (tmdb:238)/file.mkv`
178+
- `/movies/Taxi Driver (1976) {tmdb=103}/file.mkv`
179+
- `/movies/Casablanca (1942) (tmdb 289)/file.mkv`
180+
181+
**Mixed Examples:**
182+
183+
- `/movies/Citizen Kane (1941) something tmdb: 15678 extra/file.mkv`
184+
- `/movies/Vertigo (1958) {tmdb=194884}/file.mkv`
185+
- `/movies/Psycho (1960) [ tmdb-539 ]/file.mkv`
186+
187+
### ❌ **Will NOT Match**
188+
189+
- `mytmdb12345` (preceded by alphanumeric characters)
190+
- `tmdb12345abc` (followed by alphanumeric characters)
191+
- `tmdb` (no digits following)
192+
193+
### 📁 **Example File Paths**
171194

172195
```
173196
/movies/The Matrix (1999) [tmdb-603]/The Matrix.mkv
174197
/movies/Inception (2010) (tmdb:27205)/Inception.mkv
175-
/movies/Avatar (2009) tmdb;19995/Avatar.mkv
198+
/movies/Avatar (2009) tmdb19995/Avatar.mkv
176199
/movies/Interstellar (2014) TMDB_157336/Interstellar.mkv
177-
/movies/Edge Case - {tmdb-12345}/file.mkv
200+
/movies/Edge Case - {tmdb=12345}/file.mkv
178201
/movies/Colon: [tmdb:54321]/file.mkv
179202
/movies/Semicolon; (tmdb;67890)/file.mkv
180203
/movies/Underscore_tmdb_11111/file.mkv
181204
/movies/ExtraSuffix tmdb-22222_extra/file.mkv
205+
/movies/Direct tmdb194884 format/file.mkv
182206
```
183207
184208
</details>
@@ -523,6 +547,38 @@ If you have an existing movie library without TMDb IDs in file paths:
523547

524548
**⚠️ Note**: Large libraries may take time to rename. Consider doing this in batches during low-usage periods.
525549

550+
### 📺 Sonarr Users: Renaming Existing Folders to Include TMDb ID
551+
552+
If you're using Sonarr to manage your TV show collection and want to apply new folder naming that includes TMDb IDs, here's how to rename existing folders:
553+
554+
#### **🔄 Apply the New Folder Names**
555+
556+
To actually rename existing folders:
557+
558+
1. **Go to the Series tab**
559+
560+
2. **Click the Mass Editor** (three sliders icon)
561+
562+
3. **Select the shows** you want to rename
563+
564+
4. **At the bottom, click "Edit"**
565+
566+
5. **In the popup:**
567+
- Set the **Root Folder** to the same one it's already using (e.g., `/mnt/user/TV`)
568+
- Click **"Save"**
569+
570+
6. **Sonarr will interpret this as a move** and apply the new folder naming format without physically moving the files—just renaming the folders.
571+
572+
#### **Example Result**
573+
574+
After applying the new naming format, your TV show folders will include TMDb IDs:
575+
576+
```
577+
/tv/Batman [tmdb-2287]/Season 3/Batman - S03E17 - The Joke's on Catwoman Bluray-1080p [tmdb-2287].mkv
578+
```
579+
580+
**💡 Pro Tip**: This method works for renaming folders without actually moving files, making it safe and efficient for large TV libraries.
581+
526582
</details>
527583

528584
<details id="local-development">

internal/media/processor.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -498,8 +498,10 @@ func (p *Processor) extractTVShowTMDbID(item MediaItem) string {
498498

499499
// ExtractTMDbIDFromPath extracts TMDb ID from file path using regex
500500
func ExtractTMDbIDFromPath(filePath string) string {
501-
// Updated regex pattern to match {tmdb-123456} anywhere in the path
502-
re := regexp.MustCompile(`\{tmdb-(\d+)\}`)
501+
// Flexible regex pattern to match tmdb followed by digits with separators around the whole pattern
502+
// Matches: tmdb123, tmdb:123, {tmdb-456}, [tmdb=789], tmdb_012, etc.
503+
// Requires word boundaries or separators around the tmdb+digits pattern
504+
re := regexp.MustCompile(`(?i)(?:^|[^a-zA-Z0-9])tmdb[^a-zA-Z0-9]*(\d+)(?:[^a-zA-Z0-9]|$)`)
503505
matches := re.FindStringSubmatch(filePath)
504506
if len(matches) > 1 {
505507
return matches[1]

0 commit comments

Comments
 (0)