Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,7 @@ media
static

.idea/

# Ignore VS Code related files and folders
.vscode
*.code-workspace
54 changes: 37 additions & 17 deletions puremagic/magic_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
["38535658", 8, ".iff", "audio/x-8svx", "IFF 8-Bit Sampled Voice"],
["4143424d", 8, ".iff", "application/x-iff", "Amiga Contiguous Bitmap"],
["414e424d", 8, ".iff", "application/x-iff", "IFF Animated Bitmap"],
["414e494d", 8, ".iff", "application/x-iff", " IFF CEL Animation"],
["414e494d", 8, ".iff", "application/x-iff", "IFF CEL Animation"],
["46415858", 8, ".iff", "application/x-iff", "IFF Facsimile Image"],
["46545854", 8, ".iff", "application/x-iff", "IFF Formatted Text"],
["534d5553", 8, ".iff", "application/x-iff", "IFF Facsimile Image"],
Expand Down Expand Up @@ -192,7 +192,7 @@
["54414C", 10, ".mp3", "audio/mpeg", "MPEG-1 Audio Layer 3 (MP3) ID3v2.2.0 audio file"],
["544250", 10, ".mp3", "audio/mpeg", "MPEG-1 Audio Layer 3 (MP3) ID3v2.2.0 audio file"],
["54434D", 10, ".mp3", "audio/mpeg", "MPEG-1 Audio Layer 3 (MP3) ID3v2.2.0 audio file"],
["54434F", 10, ".mp3", "audio/mpeg", "MPEG-1 Audio Layer 3 (MP3) ID3v2.2.0 audio file"],
["54434F", 10, ".mp3", "audio/mpeg", "MPEG-1 Audio Layer 3 (MP3) ID3v2.2.0 audio file"],
["544352", 10, ".mp3", "audio/mpeg", "MPEG-1 Audio Layer 3 (MP3) ID3v2.2.0 audio file"],
["544441", 10, ".mp3", "audio/mpeg", "MPEG-1 Audio Layer 3 (MP3) ID3v2.2.0 audio file"],
["544459", 10, ".mp3", "audio/mpeg", "MPEG-1 Audio Layer 3 (MP3) ID3v2.2.0 audio file"],
Expand All @@ -202,33 +202,33 @@
["544B45", 10, ".mp3", "audio/mpeg", "MPEG-1 Audio Layer 3 (MP3) ID3v2.2.0 audio file"],
["544C41", 10, ".mp3", "audio/mpeg", "MPEG-1 Audio Layer 3 (MP3) ID3v2.2.0 audio file"],
["544C45", 10, ".mp3", "audio/mpeg", "MPEG-1 Audio Layer 3 (MP3) ID3v2.2.0 audio file"],
["544D54", 10, ".mp3", "audio/mpeg", "MPEG-1 Audio Layer 3 (MP3) ID3v2.2.0 audio file"],
["544D54", 10, ".mp3", "audio/mpeg", "MPEG-1 Audio Layer 3 (MP3) ID3v2.2.0 audio file"],
["544F41", 10, ".mp3", "audio/mpeg", "MPEG-1 Audio Layer 3 (MP3) ID3v2.2.0 audio file"],
["544F46", 10, ".mp3", "audio/mpeg", "MPEG-1 Audio Layer 3 (MP3) ID3v2.2.0 audio file"],
["544F4C", 10, ".mp3", "audio/mpeg", "MPEG-1 Audio Layer 3 (MP3) ID3v2.2.0 audio file"],
["544F52", 10, ".mp3", "audio/mpeg", "MPEG-1 Audio Layer 3 (MP3) ID3v2.2.0 audio file"],
["544F54", 10, ".mp3", "audio/mpeg", "MPEG-1 Audio Layer 3 (MP3) ID3v2.2.0 audio file"],
["545031", 10, ".mp3", "audio/mpeg", "MPEG-1 Audio Layer 3 (MP3) ID3v2.2.0 audio file"],
["545031", 10, ".mp3", "audio/mpeg", "MPEG-1 Audio Layer 3 (MP3) ID3v2.2.0 audio file"],
["545032", 10, ".mp3", "audio/mpeg", "MPEG-1 Audio Layer 3 (MP3) ID3v2.2.0 audio file"],
["545033", 10, ".mp3", "audio/mpeg", "MPEG-1 Audio Layer 3 (MP3) ID3v2.2.0 audio file"],
["545034", 10, ".mp3", "audio/mpeg", "MPEG-1 Audio Layer 3 (MP3) ID3v2.2.0 audio file"],
["545041", 10, ".mp3", "audio/mpeg", "MPEG-1 Audio Layer 3 (MP3) ID3v2.2.0 audio file"],
["545042", 10, ".mp3", "audio/mpeg", "MPEG-1 Audio Layer 3 (MP3) ID3v2.2.0 audio file"],
["545033", 10, ".mp3", "audio/mpeg", "MPEG-1 Audio Layer 3 (MP3) ID3v2.2.0 audio file"],
["545034", 10, ".mp3", "audio/mpeg", "MPEG-1 Audio Layer 3 (MP3) ID3v2.2.0 audio file"],
["545041", 10, ".mp3", "audio/mpeg", "MPEG-1 Audio Layer 3 (MP3) ID3v2.2.0 audio file"],
["545042", 10, ".mp3", "audio/mpeg", "MPEG-1 Audio Layer 3 (MP3) ID3v2.2.0 audio file"],
["545243", 10, ".mp3", "audio/mpeg", "MPEG-1 Audio Layer 3 (MP3) ID3v2.2.0 audio file"],
["545244", 10, ".mp3", "audio/mpeg", "MPEG-1 Audio Layer 3 (MP3) ID3v2.2.0 audio file"],
["54524B", 10, ".mp3", "audio/mpeg", "MPEG-1 Audio Layer 3 (MP3) ID3v2.2.0 audio file"],
["545349", 10, ".mp3", "audio/mpeg", "MPEG-1 Audio Layer 3 (MP3) ID3v2.2.0 audio file"],
["545353", 10, ".mp3", "audio/mpeg", "MPEG-1 Audio Layer 3 (MP3) ID3v2.2.0 audio file"],
["54524B", 10, ".mp3", "audio/mpeg", "MPEG-1 Audio Layer 3 (MP3) ID3v2.2.0 audio file"],
["545349", 10, ".mp3", "audio/mpeg", "MPEG-1 Audio Layer 3 (MP3) ID3v2.2.0 audio file"],
["545353", 10, ".mp3", "audio/mpeg", "MPEG-1 Audio Layer 3 (MP3) ID3v2.2.0 audio file"],
["545431", 10, ".mp3", "audio/mpeg", "MPEG-1 Audio Layer 3 (MP3) ID3v2.2.0 audio file"],
["545432", 10, ".mp3", "audio/mpeg", "MPEG-1 Audio Layer 3 (MP3) ID3v2.2.0 audio file"],
["545433", 10, ".mp3", "audio/mpeg", "MPEG-1 Audio Layer 3 (MP3) ID3v2.2.0 audio file"],
["545432", 10, ".mp3", "audio/mpeg", "MPEG-1 Audio Layer 3 (MP3) ID3v2.2.0 audio file"],
["545433", 10, ".mp3", "audio/mpeg", "MPEG-1 Audio Layer 3 (MP3) ID3v2.2.0 audio file"],
["545854", 10, ".mp3", "audio/mpeg", "MPEG-1 Audio Layer 3 (MP3) ID3v2.2.0 audio file"],
["545858", 10, ".mp3", "audio/mpeg", "MPEG-1 Audio Layer 3 (MP3) ID3v2.2.0 audio file"],
["545945", 10, ".mp3", "audio/mpeg", "MPEG-1 Audio Layer 3 (MP3) ID3v2.2.0 audio file"],
["554649", 10, ".mp3", "audio/mpeg", "MPEG-1 Audio Layer 3 (MP3) ID3v2.2.0 audio file"],
["554C54", 10, ".mp3", "audio/mpeg", "MPEG-1 Audio Layer 3 (MP3) ID3v2.2.0 audio file"],
["554C54", 10, ".mp3", "audio/mpeg", "MPEG-1 Audio Layer 3 (MP3) ID3v2.2.0 audio file"],
["574146", 10, ".mp3", "audio/mpeg", "MPEG-1 Audio Layer 3 (MP3) ID3v2.2.0 audio file"],
["574152", 10, ".mp3", "audio/mpeg", "MPEG-1 Audio Layer 3 (MP3) ID3v2.2.0 audio file"],
["574152", 10, ".mp3", "audio/mpeg", "MPEG-1 Audio Layer 3 (MP3) ID3v2.2.0 audio file"],
["574153", 10, ".mp3", "audio/mpeg", "MPEG-1 Audio Layer 3 (MP3) ID3v2.2.0 audio file"],
["57434D", 10, ".mp3", "audio/mpeg", "MPEG-1 Audio Layer 3 (MP3) ID3v2.2.0 audio file"],
["574350", 10, ".mp3", "audio/mpeg", "MPEG-1 Audio Layer 3 (MP3) ID3v2.2.0 audio file"],
Expand Down Expand Up @@ -537,7 +537,7 @@
["435202", 8, ".cr2", "", "Canon Camera RAW 2 image"]
],
"424f4f4b4d4f4249" : [
["e98e0d0a", -4, ".mobi", "application/x-mobipocket-ebook", "Mobipocket eBook file"],
["e98e0d0a", -4, ".mobi", "application/x-mobipocket-ebook", "Mobipocket eBook file"],
["e98e0d0a", -4, ".azw", "application/vnd.amazon.mobi8-ebook", "Amazon Kindle eBook file"],
["434f4e54424f554e44415259e98e0d0a", -16, ".azw3", "application/vnd.amazon.mobi8-ebook", "Amazon Kindle Format 8 eBook file (KF8 Dual MOBI/EPUB Format)"]
],
Expand Down Expand Up @@ -585,6 +585,9 @@
["05", 3, ".adf", "application/x-amiga-disk-format", "Amiga disk image (FFS International and Directory Cache)"],
["06", 3, ".adf", "application/x-amiga-disk-format", "Amiga disk image (OFS Long Filename)"],
["07", 3, ".adf", "application/x-amiga-disk-format", "Amiga disk image (FFS Long Filename)"]
],
"fffb" :[
["544147", -128, ".mp3", "audio/mpeg", "MPEG-1 Audio Layer 3 (MP3) audio file"]
]
},
"footers": [
Expand Down Expand Up @@ -752,7 +755,24 @@
["4d4d4d44", 0, ".smaf", "application/x-smaf", "SMAF audio"],
["50534944", 0, ".psid", "audio/prs.sid", "Commodore 64 audio"],
["664c6143", 0, ".flac", "audio/flac", "FLAC audio"],
["fffb", 0, ".mpga", "audio/mpeg", "MP3 audio"],
["fffe", 0, ".mp1", "audio/mpeg", "MPEG-1 Audio Layer I (MP1) audio file"],
["ffff", 0, ".mp1", "audio/mpeg", "MPEG-1 Audio Layer I (MP1) audio file"],
["fffc", 0, ".mp2", "audio/mpeg", "MPEG-1 Audio Layer II (MP2) audio file"],
["fffd", 0, ".mp2", "audio/mpeg", "MPEG-1 Audio Layer II (MP2) audio file"],
["fffa", 0, ".mp3", "audio/mpeg", "MPEG-1 Audio Layer III (MP3) audio file"],
["fffb", 0, ".mp3", "audio/mpeg", "MPEG-1 Audio Layer III (MP3) audio file"],
["fff6", 0, ".mp1", "audio/mpeg", "MPEG-2 Audio Layer I (MP1) audio file"],
["fff7", 0, ".mp1", "audio/mpeg", "MPEG-2 Audio Layer I (MP1) audio file"],
["fff4", 0, ".mp2", "audio/mpeg", "MPEG-2 Audio Layer II (MP2) audio file"],
["fff5", 0, ".mp2", "audio/mpeg", "MPEG-2 Audio Layer II (MP2) audio file"],
["fff2", 0, ".mp3", "audio/mpeg", "MPEG-2 Audio Layer III (MP3) audio file"],
["fff3", 0, ".mp3", "audio/mpeg", "MPEG-2 Audio Layer III (MP3) audio file"],
["ffe6", 0, ".mp1", "audio/mpeg", "MPEG-2.5 Audio Layer I (MP1) audio file"],
["ffe7", 0, ".mp1", "audio/mpeg", "MPEG-2.5 Audio Layer I (MP1) audio file"],
["ffe4", 0, ".mp2", "audio/mpeg", "MPEG-2.5 Audio Layer II (MP2) audio file"],
["ffe5", 0, ".mp2", "audio/mpeg", "MPEG-2.5 Audio Layer II (MP2) audio file"],
["ffe2", 0, ".mp3", "audio/mpeg", "MPEG-2.5 Audio Layer III (MP3) audio file"],
["ffe3", 0, ".mp3", "audio/mpeg", "MPEG-2.5 Audio Layer III (MP3) audio file"],
["234558544d3355", 0, ".m3u8", "application/vnd.apple.mpegurl", "HTTP Live Streaming playlist"],
["2521", 0, ".epsf", "image/x-eps", "EPS image"],
["5c3030342521", 0, ".epsf", "image/x-eps", "EPS image"],
Expand Down
38 changes: 35 additions & 3 deletions puremagic/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,15 @@
import puremagic

if os.getenv("PUREMAGIC_DEEPSCAN") != "0":
from puremagic.scanners import zip_scanner, pdf_scanner, text_scanner, json_scanner, python_scanner, sndhdr_scanner
from puremagic.scanners import (
zip_scanner,
pdf_scanner,
text_scanner,
json_scanner,
python_scanner,
sndhdr_scanner,
mpeg_audio_scanner,
)

__author__ = "Chris Griffith"
__version__ = "2.0.0b5"
Expand Down Expand Up @@ -398,10 +406,34 @@ def single_deep_scan(
result = sndhdr_scanner.main(filename, head, foot)
if result and result.confidence > confidence:
return result
case (
mpeg_audio_scanner.mp3_id3_match_bytes
| mpeg_audio_scanner.raw_mp3_match_bytes
| mpeg_audio_scanner.fffe_match_bytes
| mpeg_audio_scanner.ffff_match_bytes
| mpeg_audio_scanner.fffc_match_bytes
| mpeg_audio_scanner.fffd_match_bytes
| mpeg_audio_scanner.fffa_match_bytes
| mpeg_audio_scanner.fff6_match_bytes
| mpeg_audio_scanner.fff7_match_bytes
| mpeg_audio_scanner.fff4_match_bytes
| mpeg_audio_scanner.fff5_match_bytes
| mpeg_audio_scanner.fff2_match_bytes
| mpeg_audio_scanner.fff3_match_bytes
| mpeg_audio_scanner.ffe6_match_bytes
| mpeg_audio_scanner.ffe7_match_bytes
| mpeg_audio_scanner.ffe4_match_bytes
| mpeg_audio_scanner.ffe5_match_bytes
| mpeg_audio_scanner.ffe2_match_bytes
| mpeg_audio_scanner.ffe3_match_bytes
):
Comment on lines +409 to +429
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
case (
mpeg_audio_scanner.mp3_id3_match_bytes
| mpeg_audio_scanner.raw_mp3_match_bytes
| mpeg_audio_scanner.fffe_match_bytes
| mpeg_audio_scanner.ffff_match_bytes
| mpeg_audio_scanner.fffc_match_bytes
| mpeg_audio_scanner.fffd_match_bytes
| mpeg_audio_scanner.fffa_match_bytes
| mpeg_audio_scanner.fff6_match_bytes
| mpeg_audio_scanner.fff7_match_bytes
| mpeg_audio_scanner.fff4_match_bytes
| mpeg_audio_scanner.fff5_match_bytes
| mpeg_audio_scanner.fff2_match_bytes
| mpeg_audio_scanner.fff3_match_bytes
| mpeg_audio_scanner.ffe6_match_bytes
| mpeg_audio_scanner.ffe7_match_bytes
| mpeg_audio_scanner.ffe4_match_bytes
| mpeg_audio_scanner.ffe5_match_bytes
| mpeg_audio_scanner.ffe2_match_bytes
| mpeg_audio_scanner.ffe3_match_bytes
):
case mpeg_bytes if mpeg_bytes in mpeg_audio_scanner.mpeg_audio_signatures
):

Would just put those all in a single array

result = mpeg_audio_scanner.main(filename, head)
if result and result.confidence > confidence:
return result

# The first match wins
for scanner in (pdf_scanner, python_scanner, json_scanner):
result = scanner.main(filename, head, foot)
result = scanner.main(filename, head)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
result = scanner.main(filename, head)
result = scanner.main(filename, head, foot)

Need to pass in all three of these. Some other scanners may use foot or expect exactly 3 inputs

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NebularNerd this may be testing issue

if result:
return result
return None
Expand Down Expand Up @@ -519,7 +551,7 @@ def command_line_entry(*args):
print(f"Total Possible Matches: {len(matches)}")
for i, result in enumerate(matches):
if i == 0:
print("\n\tBest Match")
print("\n\tDeepscan Match" if int(result.confidence == 1) else "\n\tBest Match")
else:
print(f"\tAlternative Match #{i}")
print(f"\tName: {result.name}")
Expand Down
Loading
Loading