A C# console application for displaying Text TV pages from the texttv.nu API with proper styling and formatting. Now supports converting web pages to TextTV format using OpenAI's GPT-4.1.
Note: This project, including this readme, was vibe coded with Windsurf / Sonnet 3.7 and GitHub Copilot Agent / GPT 4.1.
Recording of the TextTV viewer navigating pages.
Recording of the TextTV viewer navigating to a url.
This application offers two main modes of operation:
- TextTV Mode: Fetches TextTV content from the texttv.nu API
- URL Mode: Converts web page content to TextTV format using OpenAI's GPT-4.1
Both modes render the content with the classic TextTV styling:
- Yellow headlines
- Cyan secondary text
- White regular text
- Blue navigation bar at the bottom
The solution follows a clean architecture with separation of concerns:
TextTv.sln
├── TextTv.Cli (Main console application)
│ ├── Configuration/
│ │ ├── CommandLineOptions.cs (Command-line argument handling)
│ │ ├── PromptConstants.cs (OpenAI prompts for URL mode)
│ │ ├── Settings.cs (Application settings model)
│ │ └── SettingsProvider.cs (Settings file handling)
│ ├── Models/
│ │ └── TextTvPage.cs (Data model for API responses)
│ ├── Services/
│ │ ├── TextTvService.cs (TextTV API interaction)
│ │ ├── OpenAi/
│ │ │ └── OpenAiService.cs (OpenAI API integration)
│ │ └── Web/
│ │ └── WebContentService.cs (Web content fetching)
│ ├── Rendering/
│ │ └── TextTvRenderer.cs (Console output formatting)
│ └── Helpers/
│ ├── TextParsingHelper.cs (HTML parsing utilities)
│ └── Utils.cs (General utility methods)
└── TextTv.Cli.Tests (Unit tests)
├── HttpClientMock.cs (HTTP client mocking)
├── TextParsingHelperTests.cs
├── TextTvServiceTests.cs
└── UtilsTests.cs
-
Separation of Concerns:
- The code is organized into logical areas (Models, Services, Rendering, Helpers, Configuration) to improve maintainability and readability.
- Each class has a clear single responsibility.
-
Multi-Mode Operation:
- TextTV Mode: Original functionality to fetch content from the texttv.nu API.
- URL Mode: New functionality to convert web content to TextTV format using OpenAI.
- Consistent rendering interface for both modes.
-
Clean API Interaction:
- Abstracted API calls through dedicated service classes.
- Well-defined model with
TextTvPage
record shared across modes. - Consistent error handling for both API types.
-
HTML Parsing and Rendering:
- Using HtmlAgilityPack for robust HTML parsing.
- The
TextParsingHelper
handles all HTML parsing logic. - Mode-aware
TextTvRenderer
for different UI presentations.
-
AI Integration:
- Carefully designed prompts for optimal TextTV format conversion.
- Few-shot learning examples to ensure high-quality output.
- Content limitations to fit TextTV screen dimensions.
-
Error Handling:
- Robust error handling for API requests, JSON parsing, and rendering.
- Graceful fallbacks when parsing fails.
-
Testing:
- Comprehensive unit tests for all components.
- Mock HTTP client for testing API interactions without actual network calls.
- .NET 9.0
- HtmlAgilityPack (for HTML parsing)
- OpenAI (official .NET SDK for OpenAI integration)
- Microsoft.Extensions.Configuration.Json (for settings handling)
- Moq (for testing)
- MSTest framework
To build the application:
cd src/
dotnet build
The application can now automatically detect if the input is a URL or a page number:
cd src/texttv-csharp/TextTv.Cli
# For page numbers
dotnet run -- 100
# For URLs
dotnet run -- https://example.com
This simplifies usage by automatically determining the appropriate mode based on your input.
You can still explicitly specify TextTV mode using the --pagenumber
flag:
dotnet run -- --pagenumber 100
Replace 100
with any valid Text TV page number.
Similarly, you can explicitly use URL mode with the --url
flag:
dotnet run -- --url https://example.com
Replace https://example.com
with any valid URL you want to convert to TextTV format.
To use the URL mode, you need to configure your OpenAI API key:
-
Make sure you have an OpenAI API key. If you don't have one, you can create it in your OpenAI dashboard.
-
Create an
appsettings.json
file in theTextTv.Cli
directory with the following content:
{
"OpenAiApiKey": "your-api-key-here",
"OpenAiModel": "gpt-4.1"
}
- Replace
your-api-key-here
with your actual OpenAI API key.
Note: The appsettings.json
file is excluded from git via .gitignore
to prevent accidental exposure of your API key.
To publish the application as a self-contained, single-file executable for Linux:
dotnet publish src/TextTv.Cli/TextTv.Cli.csproj -c Release -r linux-x64 -p:PublishSingleFile=true -p:AssemblyName=texttv --self-contained -o publish
This creates a self-contained executable in the publish
folder that can run on any compatible Linux system without requiring .NET to be installed.
To run the published application:
cd publish
./TextTv.Cli 100
To run the unit tests:
cd src/TextTv.Cli.Tests
dotnet test
The application uses the texttv.nu API with the following format:
https://texttv.nu/api/get/{pageNumber}?includePlainTextContent=1
This returns a JSON array containing page content and navigation information.