{"id":19954043,"url":"https://github.com/mkht/magika-csharp","last_synced_at":"2025-05-03T19:32:01.126Z","repository":{"id":224374315,"uuid":"763081863","full_name":"mkht/Magika-CSharp","owner":"mkht","description":"C# implementation of the Magika","archived":false,"fork":false,"pushed_at":"2024-04-15T02:48:26.000Z","size":1022,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-05-09T22:33:38.059Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mkht.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2024-02-25T14:11:06.000Z","updated_at":"2024-03-20T14:19:02.000Z","dependencies_parsed_at":"2024-03-23T14:23:01.988Z","dependency_job_id":"90ebe85f-50de-4fc3-9a1e-42ae14da6b18","html_url":"https://github.com/mkht/Magika-CSharp","commit_stats":null,"previous_names":["mkht/magika-csharp"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkht%2FMagika-CSharp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkht%2FMagika-CSharp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkht%2FMagika-CSharp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkht%2FMagika-CSharp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mkht","download_url":"https://codeload.github.com/mkht/Magika-CSharp/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224370715,"owners_count":17300089,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-13T01:18:46.882Z","updated_at":"2024-11-13T01:18:47.528Z","avatar_url":"https://github.com/mkht.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Magika - CSharp\r\n\r\nThis is a C# implementation of the [Magika](https://github.com/google/magika). Includes a .NET class library and a single binary CLI tool.\r\n\r\nMagika is a novel AI powered file type detection tool that is developed by Google.  \r\nPlease refer to the original repository for more information.  \r\nhttps://github.com/google/magika\r\n\r\n\u003e [!IMPORTANT]  \r\n\u003e This is a **personal project for learning purpose**.  \r\n\u003e This is not an official implementation of Magika and is not supported by Google.  \r\n\u003e DO NOT use for production use.\r\n\r\n----\r\n## Prerequisites\r\n\r\nOn Windows, you need to install the Visual C++ Redistributable for Visual Studio 2015-2022 from the following link:\r\n - [Microsoft Visual C++ Redistributable latest supported downloads](https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist?view=msvc-170)\r\n\r\nIf you want to build from source, you need to install the following tools:\r\n - .NET 8.0 SDK\r\n\r\n----\r\n## Installation\r\n\r\nYou can download the pre-build binaries per platform from the [Releases](https://github.com/mkht/Magika-CSharp/releases) page.\r\n\r\n----\r\n## Usage\r\n\r\n### Command line\r\n\r\n```\r\nC:\\\u003emagika.exe -r .\\tests_data\\\r\n.\\tests_data\\basic\\code.asm: Assembly (code)\r\n.\\tests_data\\basic\\code.c: C source (code)\r\n.\\tests_data\\basic\\code.css: CSS source (code)\r\n.\\tests_data\\basic\\code.js: JavaScript source (code)\r\n...\r\n.\\tests_data\\mitra\\webp.webp: WebP data (image)\r\n.\\tests_data\\mitra\\webpl.webp: WebP data (image)\r\n.\\tests_data\\mitra\\xz.xz: XZ compressed data (archive)\r\n.\\tests_data\\mitra\\zip.zip: Zip archive data (archive)\r\n.\\tests_data\\README.md: Markdown document (text)\r\n```\r\n\r\n```\r\nC:\\\u003emagika.exe .\\tests_data\\basic\\code.py --json\r\n[\r\n  {\r\n    \"path\": \".\\\\tests_data\\\\basic\\\\code.py\",\r\n    \"dl\": {\r\n      \"ct_label\": \"python\",\r\n      \"score\": 0.9985216,\r\n      \"group\": \"code\",\r\n      \"mime_type\": \"text/x-python\",\r\n      \"magic\": \"Python script\",\r\n      \"description\": \"Python source\"\r\n    },\r\n    \"output\": {\r\n      \"ct_label\": \"python\",\r\n      \"score\": 0.9985216,\r\n      \"group\": \"code\",\r\n      \"mime_type\": \"text/x-python\",\r\n      \"magic\": \"Python script\",\r\n      \"description\": \"Python source\"\r\n    }\r\n  }\r\n]\r\n```\r\n\r\n```\r\n\u003e magika --help\r\nmagika 0.5.0-dev\r\n\r\n  -r, --recursive                When passing this option, magika scans every file within directories, instead of\r\n                                 outputting \"directory\"\r\n  --json                         Output in JSON format.\r\n  --jsonl                        Output in JSONL format.\r\n  -i, --mime-type                Output the MIME type instead of a verbose content type description.\r\n  -l, --label                    Output a simple label instead of a verbose content type description. Use\r\n                                 --list-output-content-types for the list of supported output.\r\n  -c, --compatibility-mode       Compatibility mode: output is as close as possible to `file` and colors are disabled.\r\n  -s, --output-score             Output the prediction's score in addition to the content type.\r\n  -m, --prediction-mode\r\n  --batch-size                   How many files to process in one batch.\r\n  --no-dereference               This option causes symlinks not to be followed. By default, symlinks are dereferenced.\r\n  --no-colors                    Enable/disable use of colors.\r\n  --colors                       Enable/disable use of colors.\r\n  -v, --verbose                  Enable more verbose output.\r\n  --debug                        Enable debug logging.\r\n  --list-output-content-types    Show a list of supported content types.\r\n  --help                         Display this help screen.\r\n  --version                      Display version information.\r\n\r\n  FILES (pos. 1)\r\n```\r\n\r\n### .NET API (C#)\r\n\r\n```csharp\r\nusing magika;\r\n\r\nusing var magika = new Magika();\r\n\r\nvar inputBytes = \"# Example\\nThis is an example of markdown!\"u8;\r\nvar res1 = magika.IdentifyBytes(inputBytes.ToArray());\r\nConsole.WriteLine(res1.output.ct_label);\r\n// \u003e markdown\r\n\r\nvar inputFile = \"path/to/sample.html\";\r\nvar res2 = magika.IdentifyPath(inputFile);\r\nConsole.WriteLine(res2.output.ct_label);\r\n// \u003e html\r\n```\r\n\r\n----\r\n## Build from source\r\n\r\n```cmd\r\ngit clone https://github.com/mkht/Magika-CSharp.git\r\ncd ./magika\r\n\r\n// Library\r\ndotnet restore\r\ndotnet build\r\n\r\n// CLI\r\ncd ./cli\r\ndotnet publish -f net8.0 -r win-x64\r\n```\r\n\r\n----\r\n## Tested Platforms\r\n\r\nWe have tested the following platforms:\r\n\r\n- Windows 10 Version 22H2 x64\r\n- Windows 11 Version 22H2 x64\r\n- Windows 11 Version 22H2 ARM64\r\n- Ubuntu 22.04 LTS x64 (WSL2)\r\n- Ubuntu 23.10 ARM64 (Raspberry Pi 5)\r\n\r\nWe plan to test on other platforms in the future.\r\n\r\n----\r\n## Important Notes\r\nThis project is based on the initial release of Magika [v0.5.0](https://github.com/google/magika/releases/tag/v0.5.0) , so it may not follow the changes in subsequent releases.\r\n\r\nAs this is not a complete port, it may behave differently from the original Magika.\r\n\r\nThis project is created for personal learning purpose. Therefore, there is no support at all. Continuous development and bug fixes are not guaranteed. It is undecided whether to follow the changes of the original project.\r\n\r\nIssue reports and pull requests are welcome, but we may not be able to respond.\r\n\r\n----\r\n## License\r\n\r\nLicensed under the Apache 2.0 - see the [LICENSE](LICENSE) file for details.  \r\nThe original Magika by Google is also licensed under the Apache 2.0.\r\n\r\nThis project includes the work that is distributed in the Apache 2.0 and MIT License.\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmkht%2Fmagika-csharp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmkht%2Fmagika-csharp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmkht%2Fmagika-csharp/lists"}