Initial import

This commit is contained in:
Damiano Galassi committed 2013-11-18 13:28:07 +01:00
commit fcc318e844
135 files changed
+38844

No files matched your search

BIN
View File
Binary file not shown.
+15
View File
@@ -0,0 +1,15 @@
//
// AppDelegate.h
// MP4Dump
//
// Created by Damiano Galassi on 17/03/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import <Cocoa/Cocoa.h>
@interface AppDelegate : NSObject {
}
@end
+53
View File
@@ -0,0 +1,53 @@
//
// AppDelegate.m
// MP4Dump
//
// Created by Damiano Galassi on 17/03/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import "AppDelegate.h"
#include "mp4v2.h"
NSString *libraryPath = nil;
void logCallback(MP4LogLevel loglevel, const char* fmt, va_list ap)
{
if (!libraryPath) {
NSString * libraryDir = [NSSearchPathForDirectoriesInDomains( NSLibraryDirectory,
NSUserDomainMask,
YES ) objectAtIndex:0];
NSString * AppSupportDirectory = [[libraryDir stringByAppendingPathComponent:@"Application Support"]
stringByAppendingPathComponent:@"MP4Dump"];
if( ![[NSFileManager defaultManager] fileExistsAtPath:AppSupportDirectory] )
{
[[NSFileManager defaultManager] createDirectoryAtPath:AppSupportDirectory
attributes:nil];
}
libraryPath = [[AppSupportDirectory stringByAppendingPathComponent:@"temp.txt"] retain];
}
FILE * file = fopen([libraryPath UTF8String], "a");
vfprintf(file, fmt, ap);
fprintf(file, "\n");
fclose(file);
}
@implementation AppDelegate
- (void)applicationWillFinishLaunching:(NSNotification *)aNotification
{
MP4LogSetLevel(MP4_LOG_INFO);
MP4SetLogCallback(logCallback);
}
- (BOOL)applicationShouldOpenUntitledFile:(NSApplication *)sender
{
return NO;
}
@end
+24
View File
@@ -0,0 +1,24 @@
{\rtf1\ansi\ansicpg1252\cocoartf1038\cocoasubrtf350
{\fonttbl\f0\fswiss\fcharset0 Helvetica;}
{\colortbl;\red255\green255\blue255;}
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural
\f0\b\fs24 \cf0 Engineering:
\b0 \
Damiano Galassi\
\
\b Human Interface Design:
\b0 \
Damiano Galassi\
\
\b Testing:
\b0 \
Hopefully not nobody\
\
\b With special thanks to:
\b0 \
mp4v2\
{\field{\*\fldinst{HYPERLINK "http://code.google.com/p/mp4v2"}}{\fldrslt http://code.google.com/p/mp4v2}}}
+2
View File
@@ -0,0 +1,2 @@
/* Localized versions of Info.plist keys */
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
+111
View File
@@ -0,0 +1,111 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>m4v</string>
</array>
<key>CFBundleTypeMIMETypes</key>
<array>
<string>video/x-m4v</string>
</array>
<key>CFBundleTypeName</key>
<string>Video-MPEG4</string>
<key>CFBundleTypeOSTypes</key>
<array>
<string>M4V</string>
</array>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>LSTypeIsPackage</key>
<false/>
<key>NSDocumentClass</key>
<string>MyDocument</string>
<key>NSPersistentStoreTypeKey</key>
<string>Binary</string>
</dict>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>mp4</string>
<string>mpg4</string>
<string>mqv</string>
</array>
<key>CFBundleTypeMIMETypes</key>
<array>
<string>audio/mp4</string>
<string>video/mp4</string>
</array>
<key>CFBundleTypeName</key>
<string>Movie-MPEG4</string>
<key>CFBundleTypeOSTypes</key>
<array>
<string>mpg4</string>
</array>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>LSTypeIsPackage</key>
<false/>
<key>NSDocumentClass</key>
<string>MyDocument</string>
<key>NSPersistentStoreTypeKey</key>
<string>Binary</string>
</dict>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>m4a</string>
</array>
<key>CFBundleTypeMIMETypes</key>
<array>
<string>audio/x-m4a</string>
<string>audio/x-m4v</string>
</array>
<key>CFBundleTypeName</key>
<string>Audio-MPEG4</string>
<key>CFBundleTypeOSTypes</key>
<array>
<string>M4A</string>
</array>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>LSTypeIsPackage</key>
<false/>
<key>NSDocumentClass</key>
<string>MyDocument</string>
<key>NSPersistentStoreTypeKey</key>
<string>Binary</string>
</dict>
</array>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundleIdentifier</key>
<string>org.galad.${PRODUCT_NAME:rfc1034identifier}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.1</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSMinimumSystemVersion</key>
<string>${MACOSX_DEPLOYMENT_TARGET}</string>
<key>NSMainNibFile</key>
<string>MainMenu</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
</dict>
</plist>
+378
View File
@@ -0,0 +1,378 @@
// !$*UTF8*$!
{
archiveVersion = 1;
classes = {
};
objectVersion = 45;
objects = {
/* Begin PBXBuildFile section */
1DDD582C0DA1D0D100B32029 /* MyDocument.xib in Resources */ = {isa = PBXBuildFile; fileRef = 1DDD58280DA1D0D100B32029 /* MyDocument.xib */; };
1DDD582D0DA1D0D100B32029 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 1DDD582A0DA1D0D100B32029 /* MainMenu.xib */; };
8D15AC2C0486D014006FF6A4 /* Credits.rtf in Resources */ = {isa = PBXBuildFile; fileRef = 2A37F4B9FDCFA73011CA2CEA /* Credits.rtf */; };
8D15AC2F0486D014006FF6A4 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C165FFE840EACC02AAC07 /* InfoPlist.strings */; };
8D15AC310486D014006FF6A4 /* MyDocument.m in Sources */ = {isa = PBXBuildFile; fileRef = 2A37F4ACFDCFA73011CA2CEA /* MyDocument.m */; settings = {ATTRIBUTES = (); }; };
8D15AC320486D014006FF6A4 /* main.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2A37F4B0FDCFA73011CA2CEA /* main.mm */; settings = {ATTRIBUTES = (); }; };
8D15AC340486D014006FF6A4 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A7FEA54F5311CA2CBB /* Cocoa.framework */; };
A9DAC2FD133204BD007CA155 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = A9DAC2FC133204BD007CA155 /* AppDelegate.m */; };
A9DC819C115DF59900FCD230 /* libmp4v2.a in Frameworks */ = {isa = PBXBuildFile; fileRef = A9DC818C115DF59900FCD230 /* libmp4v2.a */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
089C1660FE840EACC02AAC07 /* English */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/InfoPlist.strings; sourceTree = "<group>"; };
1058C7A7FEA54F5311CA2CBB /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = "<absolute>"; };
13E42FBA07B3F13500E4EEF1 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = /System/Library/Frameworks/CoreData.framework; sourceTree = "<absolute>"; };
1DDD58290DA1D0D100B32029 /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/MyDocument.xib; sourceTree = "<group>"; };
1DDD582B0DA1D0D100B32029 /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/MainMenu.xib; sourceTree = "<group>"; };
2564AD2C0F5327BB00F57823 /* MP4Dump_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MP4Dump_Prefix.pch; sourceTree = "<group>"; };
2A37F4ACFDCFA73011CA2CEA /* MyDocument.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MyDocument.m; sourceTree = "<group>"; };
2A37F4AEFDCFA73011CA2CEA /* MyDocument.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MyDocument.h; sourceTree = "<group>"; };
2A37F4B0FDCFA73011CA2CEA /* main.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = main.mm; sourceTree = "<group>"; };
2A37F4BAFDCFA73011CA2CEA /* English */ = {isa = PBXFileReference; lastKnownFileType = text.rtf; name = English; path = English.lproj/Credits.rtf; sourceTree = "<group>"; };
2A37F4C4FDCFA73011CA2CEA /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = /System/Library/Frameworks/AppKit.framework; sourceTree = "<absolute>"; };
2A37F4C5FDCFA73011CA2CEA /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = "<absolute>"; };
8D15AC360486D014006FF6A4 /* MP4Dump-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "MP4Dump-Info.plist"; sourceTree = "<group>"; };
8D15AC370486D014006FF6A4 /* MP4Dump.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MP4Dump.app; sourceTree = BUILT_PRODUCTS_DIR; };
A9DAC2FB133204BD007CA155 /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
A9DAC2FC133204BD007CA155 /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
A9DC818C115DF59900FCD230 /* libmp4v2.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libmp4v2.a; sourceTree = "<group>"; };
A9DC818E115DF59900FCD230 /* chapter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = chapter.h; sourceTree = "<group>"; };
A9DC818F115DF59900FCD230 /* file.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = file.h; sourceTree = "<group>"; };
A9DC8190115DF59900FCD230 /* file_prop.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = file_prop.h; sourceTree = "<group>"; };
A9DC8191115DF59900FCD230 /* general.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = general.h; sourceTree = "<group>"; };
A9DC8192115DF59900FCD230 /* isma.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = isma.h; sourceTree = "<group>"; };
A9DC8193115DF59900FCD230 /* itmf_generic.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = itmf_generic.h; sourceTree = "<group>"; };
A9DC8194115DF59900FCD230 /* itmf_tags.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = itmf_tags.h; sourceTree = "<group>"; };
A9DC8195115DF59900FCD230 /* platform.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = platform.h; sourceTree = "<group>"; };
A9DC8196115DF59900FCD230 /* project.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = project.h; sourceTree = "<group>"; };
A9DC8197115DF59900FCD230 /* sample.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sample.h; sourceTree = "<group>"; };
A9DC8198115DF59900FCD230 /* streaming.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = streaming.h; sourceTree = "<group>"; };
A9DC8199115DF59900FCD230 /* track.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = track.h; sourceTree = "<group>"; };
A9DC819A115DF59900FCD230 /* track_prop.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = track_prop.h; sourceTree = "<group>"; };
A9DC819B115DF59900FCD230 /* mp4v2.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = mp4v2.h; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
8D15AC330486D014006FF6A4 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
8D15AC340486D014006FF6A4 /* Cocoa.framework in Frameworks */,
A9DC819C115DF59900FCD230 /* libmp4v2.a in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
1058C7A6FEA54F5311CA2CBB /* Linked Frameworks */ = {
isa = PBXGroup;
children = (
A9DC818B115DF59900FCD230 /* mp4v2 */,
1058C7A7FEA54F5311CA2CBB /* Cocoa.framework */,
);
name = "Linked Frameworks";
sourceTree = "<group>";
};
1058C7A8FEA54F5311CA2CBB /* Other Frameworks */ = {
isa = PBXGroup;
children = (
2A37F4C4FDCFA73011CA2CEA /* AppKit.framework */,
13E42FBA07B3F13500E4EEF1 /* CoreData.framework */,
2A37F4C5FDCFA73011CA2CEA /* Foundation.framework */,
);
name = "Other Frameworks";
sourceTree = "<group>";
};
19C28FB0FE9D524F11CA2CBB /* Products */ = {
isa = PBXGroup;
children = (
8D15AC370486D014006FF6A4 /* MP4Dump.app */,
);
name = Products;
sourceTree = "<group>";
};
2A37F4AAFDCFA73011CA2CEA /* MP4Dump */ = {
isa = PBXGroup;
children = (
2A37F4ABFDCFA73011CA2CEA /* Classes */,
2A37F4AFFDCFA73011CA2CEA /* Other Sources */,
2A37F4B8FDCFA73011CA2CEA /* Resources */,
2A37F4C3FDCFA73011CA2CEA /* Frameworks */,
19C28FB0FE9D524F11CA2CBB /* Products */,
);
name = MP4Dump;
sourceTree = "<group>";
};
2A37F4ABFDCFA73011CA2CEA /* Classes */ = {
isa = PBXGroup;
children = (
2A37F4AEFDCFA73011CA2CEA /* MyDocument.h */,
2A37F4ACFDCFA73011CA2CEA /* MyDocument.m */,
);
name = Classes;
sourceTree = "<group>";
};
2A37F4AFFDCFA73011CA2CEA /* Other Sources */ = {
isa = PBXGroup;
children = (
A9DAC2FB133204BD007CA155 /* AppDelegate.h */,
A9DAC2FC133204BD007CA155 /* AppDelegate.m */,
2564AD2C0F5327BB00F57823 /* MP4Dump_Prefix.pch */,
2A37F4B0FDCFA73011CA2CEA /* main.mm */,
);
name = "Other Sources";
sourceTree = "<group>";
};
2A37F4B8FDCFA73011CA2CEA /* Resources */ = {
isa = PBXGroup;
children = (
2A37F4B9FDCFA73011CA2CEA /* Credits.rtf */,
8D15AC360486D014006FF6A4 /* MP4Dump-Info.plist */,
089C165FFE840EACC02AAC07 /* InfoPlist.strings */,
1DDD58280DA1D0D100B32029 /* MyDocument.xib */,
1DDD582A0DA1D0D100B32029 /* MainMenu.xib */,
);
name = Resources;
sourceTree = "<group>";
};
2A37F4C3FDCFA73011CA2CEA /* Frameworks */ = {
isa = PBXGroup;
children = (
1058C7A6FEA54F5311CA2CBB /* Linked Frameworks */,
1058C7A8FEA54F5311CA2CBB /* Other Frameworks */,
);
name = Frameworks;
sourceTree = "<group>";
};
A9DC818B115DF59900FCD230 /* mp4v2 */ = {
isa = PBXGroup;
children = (
A9DC818D115DF59900FCD230 /* mp4v2 */,
A9DC818C115DF59900FCD230 /* libmp4v2.a */,
A9DC819B115DF59900FCD230 /* mp4v2.h */,
);
name = mp4v2;
path = ../../mp4v2;
sourceTree = SOURCE_ROOT;
};
A9DC818D115DF59900FCD230 /* mp4v2 */ = {
isa = PBXGroup;
children = (
A9DC818E115DF59900FCD230 /* chapter.h */,
A9DC818F115DF59900FCD230 /* file.h */,
A9DC8190115DF59900FCD230 /* file_prop.h */,
A9DC8191115DF59900FCD230 /* general.h */,
A9DC8192115DF59900FCD230 /* isma.h */,
A9DC8193115DF59900FCD230 /* itmf_generic.h */,
A9DC8194115DF59900FCD230 /* itmf_tags.h */,
A9DC8195115DF59900FCD230 /* platform.h */,
A9DC8196115DF59900FCD230 /* project.h */,
A9DC8197115DF59900FCD230 /* sample.h */,
A9DC8198115DF59900FCD230 /* streaming.h */,
A9DC8199115DF59900FCD230 /* track.h */,
A9DC819A115DF59900FCD230 /* track_prop.h */,
);
path = mp4v2;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
8D15AC270486D014006FF6A4 /* MP4Dump */ = {
isa = PBXNativeTarget;
buildConfigurationList = C05733C708A9546B00998B17 /* Build configuration list for PBXNativeTarget "MP4Dump" */;
buildPhases = (
8D15AC2B0486D014006FF6A4 /* Resources */,
8D15AC300486D014006FF6A4 /* Sources */,
8D15AC330486D014006FF6A4 /* Frameworks */,
);
buildRules = (
);
dependencies = (
);
name = MP4Dump;
productInstallPath = "$(HOME)/Applications";
productName = MP4Dump;
productReference = 8D15AC370486D014006FF6A4 /* MP4Dump.app */;
productType = "com.apple.product-type.application";
};
/* End PBXNativeTarget section */
/* Begin PBXProject section */
2A37F4A9FDCFA73011CA2CEA /* Project object */ = {
isa = PBXProject;
buildConfigurationList = C05733CB08A9546B00998B17 /* Build configuration list for PBXProject "MP4Dump" */;
compatibilityVersion = "Xcode 3.1";
developmentRegion = English;
hasScannedForEncodings = 1;
knownRegions = (
English,
Japanese,
French,
German,
);
mainGroup = 2A37F4AAFDCFA73011CA2CEA /* MP4Dump */;
projectDirPath = "";
projectRoot = "";
targets = (
8D15AC270486D014006FF6A4 /* MP4Dump */,
);
};
/* End PBXProject section */
/* Begin PBXResourcesBuildPhase section */
8D15AC2B0486D014006FF6A4 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
8D15AC2C0486D014006FF6A4 /* Credits.rtf in Resources */,
8D15AC2F0486D014006FF6A4 /* InfoPlist.strings in Resources */,
1DDD582C0DA1D0D100B32029 /* MyDocument.xib in Resources */,
1DDD582D0DA1D0D100B32029 /* MainMenu.xib in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXResourcesBuildPhase section */
/* Begin PBXSourcesBuildPhase section */
8D15AC300486D014006FF6A4 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
8D15AC310486D014006FF6A4 /* MyDocument.m in Sources */,
8D15AC320486D014006FF6A4 /* main.mm in Sources */,
A9DAC2FD133204BD007CA155 /* AppDelegate.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */
/* Begin PBXVariantGroup section */
089C165FFE840EACC02AAC07 /* InfoPlist.strings */ = {
isa = PBXVariantGroup;
children = (
089C1660FE840EACC02AAC07 /* English */,
);
name = InfoPlist.strings;
sourceTree = "<group>";
};
1DDD58280DA1D0D100B32029 /* MyDocument.xib */ = {
isa = PBXVariantGroup;
children = (
1DDD58290DA1D0D100B32029 /* English */,
);
name = MyDocument.xib;
sourceTree = "<group>";
};
1DDD582A0DA1D0D100B32029 /* MainMenu.xib */ = {
isa = PBXVariantGroup;
children = (
1DDD582B0DA1D0D100B32029 /* English */,
);
name = MainMenu.xib;
sourceTree = "<group>";
};
2A37F4B9FDCFA73011CA2CEA /* Credits.rtf */ = {
isa = PBXVariantGroup;
children = (
2A37F4BAFDCFA73011CA2CEA /* English */,
);
name = Credits.rtf;
sourceTree = "<group>";
};
/* End PBXVariantGroup section */
/* Begin XCBuildConfiguration section */
C05733C808A9546B00998B17 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
COPY_PHASE_STRIP = NO;
GCC_DYNAMIC_NO_PIC = NO;
GCC_ENABLE_FIX_AND_CONTINUE = YES;
GCC_MODEL_TUNING = G5;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = MP4Dump_Prefix.pch;
INFOPLIST_FILE = "MP4Dump-Info.plist";
INSTALL_PATH = "$(HOME)/Applications";
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"\"$(SRCROOT)/../../mp4v2\"",
);
PRODUCT_NAME = MP4Dump;
};
name = Debug;
};
C05733C908A9546B00998B17 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
GCC_MODEL_TUNING = G5;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = MP4Dump_Prefix.pch;
INFOPLIST_FILE = "MP4Dump-Info.plist";
INSTALL_PATH = "$(HOME)/Applications";
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"\"$(SRCROOT)/../../mp4v2\"",
);
PRODUCT_NAME = MP4Dump;
};
name = Release;
};
C05733CC08A9546B00998B17 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
HEADER_SEARCH_PATHS = "\"$(SRCROOT)/../../mp4v2\"/**";
ONLY_ACTIVE_ARCH = YES;
PREBINDING = NO;
SDKROOT = macosx10.8;
};
name = Debug;
};
C05733CD08A9546B00998B17 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
HEADER_SEARCH_PATHS = "\"$(SRCROOT)/../../mp4v2\"/**";
PREBINDING = NO;
SDKROOT = macosx10.8;
};
name = Release;
};
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
C05733C708A9546B00998B17 /* Build configuration list for PBXNativeTarget "MP4Dump" */ = {
isa = XCConfigurationList;
buildConfigurations = (
C05733C808A9546B00998B17 /* Debug */,
C05733C908A9546B00998B17 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
C05733CB08A9546B00998B17 /* Build configuration list for PBXProject "MP4Dump" */ = {
isa = XCConfigurationList;
buildConfigurations = (
C05733CC08A9546B00998B17 /* Debug */,
C05733CD08A9546B00998B17 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
rootObject = 2A37F4A9FDCFA73011CA2CEA /* Project object */;
}
+7
View File
@@ -0,0 +1,7 @@
//
// Prefix header for all source files of the 'MP4Dump' target in the 'MP4Dump' project
//
#ifdef __OBJC__
#import <Cocoa/Cocoa.h>
#endif
+21
View File
@@ -0,0 +1,21 @@
//
// MyDocument.h
// MP4Dump
//
// Created by Damiano Galassi on 27/03/10.
// Copyright 2010 __MyCompanyName__. All rights reserved.
//
#import <Cocoa/Cocoa.h>
@interface MyDocument : NSDocument
{
IBOutlet NSTextView * textView;
IBOutlet NSPopUpButton *logLevelButton;
NSString * result;
}
- (IBAction) setLogLevel: (id) sender;
@end
+95
View File
@@ -0,0 +1,95 @@
//
// MyDocument.m
// MP4Dump
//
// Created by Damiano Galassi on 27/03/10.
// Copyright 2010 __MyCompanyName__. All rights reserved.
//
#import "MyDocument.h"
#include "mp4v2.h"
extern NSString *libraryPath;
@implementation MyDocument
- (id)init
{
self = [super init];
if (self) {
// Add your subclass-specific initialization here.
// If an error occurs here, send a [self release] message and return nil.
}
return self;
}
- (NSString *)windowNibName
{
// Override returning the nib file name of the document
// If you need to use a subclass of NSWindowController or if your document supports multiple NSWindowControllers,
// you should remove this method and override -makeWindowControllers instead.
return @"MyDocument";
}
- (void)windowControllerDidLoadNib:(NSWindowController *) aController
{
if ([[NSUserDefaults standardUserDefaults] valueForKey:@"LogLevel"])
[logLevelButton selectItemWithTag:[[NSUserDefaults standardUserDefaults] integerForKey:@"LogLevel"]];
[super windowControllerDidLoadNib:aController];
[textView setFont:[NSFont fontWithName:@"Monaco" size:10]];
[textView setString:@""];
[textView insertText:result];
[textView setContinuousSpellCheckingEnabled:NO];
}
- (BOOL) loadFileDump:(NSURL *)absoluteURL error:(NSError **)outError
{
MP4FileHandle fileHandle = MP4Read([[absoluteURL path] UTF8String]);
MP4Dump(fileHandle, 0);
MP4Close(fileHandle, 0);
result = [NSString stringWithContentsOfFile:libraryPath encoding:NSASCIIStringEncoding error:outError];
if([[NSFileManager defaultManager] isDeletableFileAtPath:libraryPath])
[[NSFileManager defaultManager] removeItemAtPath:libraryPath error:nil];
if (result)
return YES;
else
return NO;
}
- (BOOL)readFromURL:(NSURL *)absoluteURL ofType:(NSString *)typeName error:(NSError **)outError
{
if ( outError != NULL && ![self loadFileDump:absoluteURL error:outError]) {
*outError = [NSError errorWithDomain:NSOSStatusErrorDomain code:unimpErr userInfo:NULL];
return NO;
}
if([[NSFileManager defaultManager] isDeletableFileAtPath:libraryPath])
[[NSFileManager defaultManager] removeItemAtPath:libraryPath error:nil];
return YES;
}
- (IBAction) setLogLevel: (id) sender
{
NSInteger level = [sender tag];
[[NSUserDefaults standardUserDefaults] setInteger:level forKey:@"LogLevel"];
MP4LogSetLevel(level);
if ([self loadFileDump:[self fileURL] error:nil]) {
[textView setString:@""];
[textView insertText:result];
}
}
- (void)updateChangeCount:(NSDocumentChangeType)changeType
{
}
@end
+14
View File
@@ -0,0 +1,14 @@
//
// main.m
// MP4Dump
//
// Created by Damiano Galassi on 27/03/10.
// Copyright 2010 __MyCompanyName__. All rights reserved.
//
#import <Cocoa/Cocoa.h>
int main(int argc, char *argv[])
{
return NSApplicationMain(argc, (const char **) argv);
}
+26
View File
@@ -0,0 +1,26 @@
#!/usr/bin/perl
use Video::Filename;
my $filename = $ARGV[0];
my $file = Video::Filename::new($filename);
if ($file->isTVshow()) {
print "tv" . "\n";
print $file->{name} . "\n";
print $file->{season} . "\n";
print $file->{episode} . "\n";
} elsif ($file->isEpisode()) {
print "tv" . "\n";
print $file->{name} . "\n";
print $file->{episode} . "\n";
print $file->{part} . "\n";
} elsif ($file->isMovie()) {
print "movie" . "\n";
print $file->{movie} . "\n";
} else {
print "unknown" . "\n";
}
exit;
+227
View File
@@ -0,0 +1,227 @@
# Copyright (c) 2008 Behan Webster. All rights reserved. This program is free
# software; you can redistribute it and/or modify it under the same terms
# as Perl itself.
package Debug::Simple;
use strict;
require Exporter;
use Data::Dumper;
use Term::ANSIColor qw(:constants);
$Term::ANSIColor::AUTORESET = 1;
use vars qw(@EXPORT @ISA $VERSION);
$VERSION = "0.10";
@ISA = qw(Exporter);
@EXPORT = qw(debuglevels warning debug verbose test);
my $opt;
###############################################################################
sub debuglevels {
# Needs to have the keys: quiet, debug, verbose, test
($opt) = @_;
&debug(5, "Command line options: ", OPTS => $opt);
}
###############################################################################
sub _list {
return (ref($_[0]) eq 'ARRAY') ? @{$_[0]} : @_;
}
###############################################################################
sub warning {
return if $opt->{quiet};
#warn ("Warning: ", @_);
print YELLOW ("Warning: ", @_);
print "";
}
###############################################################################
sub debug {
return if $opt->{quiet};
my @level = (&_list(shift), 0, 0, 0);
return unless (defined $opt->{debug} && $level[0] <= $opt->{debug})
|| ($opt->{verbose} && $level[1] && $level[1] <= $opt->{verbose})
|| ($opt->{test} && $level[2]);
#print "DEBUG\n" if defined $opt->{debug} && $level[0] <= $opt->{debug};
#print "VERBOSE: $opt->{verbose} && $level[1]\n" if defined $opt->{verbose} && $level[1] <= $opt->{verbose};
#print "TEST\n" if defined $opt->{test} && $level[3];
my $str = shift || '';
my $name = shift;
print BOLD "Debug: " unless $level[1] || $level[2];
print BOLD "$str";
if ($name && @_) {
my $save = $Data::Dumper::Varname;
$Data::Dumper::Varname = $name;
print BOLD Dumper(@_);
$Data::Dumper::Varname = $save;
}
print "";
}
###############################################################################
sub verbose {
return if $opt->{quiet};
my @level = (&_list(shift), 0, 0);
return unless ($opt->{verbose} && $level[0] && $level[0] <= $opt->{verbose})
|| ($opt->{test} && $level[1]);
print @_;
print "";
}
###############################################################################
sub test {
my $code = shift;
my $str = shift || $code;
if ($opt->{test}) {
print CYAN "$str\n";
} else {
eval $code;
print MAGENTA "Eval failed: $@\n" if $@;
return $@;
}
print "";
}
1;
###############################################################################
__END__
=head1 NAME
Debug::Simple - Very simple debugging statements
=head1 SYNOPSIS
use Debug::Simple;
my %opt = (quiet => 0, debug => 4, verbose => 1, test => 0);
Debug::Simple::debuglevels(\%opt);
warning("This is a warning\m");
debug(1, "This is a level 3 debug message\n");
debug(2, "This is a level 2 debug message with a Dump", NAME => \%opt);
verbose(1, "This is a verbose message\n");
test('print "test code"');
=head1 DESCRIPTION
This module provides a very simple way to provide debug/verbose/warning
messages. It is also trivially controlled via Getopt::Long.
The idea is to be able to put a bunch of debugging print statements throughout
your code that you can enable or disable.
=over 4
=item debuglevels(\%OPT)
C<debuglevels> registers the hashref C<HASH> as the place to read values used
to control whether text is output to the screen or not. There are 4 values
read from this hash: quiet, debug, verbose, and test.
=over
=item quiet
If non-zero, this will repress all output from Debug::Simple
=item debug
This indicates the level of debug messages desired. A debug
level of 4 prints all the debug messages from levels 1 to 4.
=item verbose
Like debug, this sets the level of verboseness. A verbose
level of 3 prints all verbose messages from 1 to 3.
=item test
If non-zero, the code passed to test() will be printed to the
screen instead of being executed.
=back
=item warning(STRING)
C<warning> prints the C<STRING> to stdout in YELLOW unless the "quiet" level is
non-zero (see C<debuglevels>). C<STRING> is prefaced with "Warning:".
=item debug(LEVEL, STRING, [NAME => REF])
C<debug> prints a debugging message to stdout as long as C<LEVEL> is at or below
the "debug" level. (see <debuglevels).
The debug message is printed in BOLD. It starts with "Debug: ", then C<STRING>,
and then optionally uses Data::Dumper to dump a data structure referred to by
C<REF>. C<NAME> is just a human readable name for C<REF> passed to Data::Dumper.
=item verbose(LEVEL, STRING)
C<verbose> prints C<STRING> to stdout as long as C<LEVEL> is at or below the
"verbose" level. (see C<debuglevels>).
=item test(CODE)
C<test> executes C<CODE> according to the "test" level. (see C<debuglevels>).
If the "test" level is non-zero the code is printed to stdout instead of being
executed.
=back
=head1 LEVELS
To make things marginally more useful, you can specify that a message can be
printed to stdout based on more than one level by specifying a list of levels.
For instance, for C<debug> you can also specify the "verbose" and "test" levels
at which the debug message will be printed. In the following example, the debug
message will be output at debug levels 1-2, verbose levels 1-3 or test level 1.
&debug([2,3,1], "This is a debug message\n");
In this case, the message will be printed to stdout if the verbose level is 1-2
or test level 1.
&verbose([2,1], "This is a verbose message\n");
=head1 EXAMPLE CODE
This example shows how Debug::Simple code can be tied in with GetOpt::Long.
use Debug::Simple;
use Getopt::Long;
use Pod::Usage;
pod2usage(2) unless GetOptions( $opt = {},
qw(help debug:i quiet test verbose|v+) );
pod2usage(1) if $opt->{help};
$opt->{debug} = 1 if defined $opt->{debug} && !$opt->{debug};
Debug::Simple::debuglevels($opt);
debug(2, "Command line options ", OPT=>$opt);
verbose(1, "Now on with the show\n");
...
=head1 AUTHOR
S<Behan Webster E<lt>behanw@websterwood.com<gt>>
=head1 COPYRIGHT
Copyright (c) 2004-2008 Behan Webster. All rights reserved. This program is free
software; you can redistribute it and/or modify it under the same terms
as Perl itself.
=cut
+259
View File
@@ -0,0 +1,259 @@
#!/usr/bin/perl
# ok, mar/98
#
package Text::Roman;
require 5.000;
require Exporter;
@ISA = (Exporter);
@EXPORT = qw(roman roman2int isroman mroman2int ismroman);
$VERSION = 3.01;
$ALGS = 'IVXLCDM';
@alg = split '', $ALGS;
# for int2rom:
@alginf = (-1, 0, 0, 2, 2, 4, 4);
%parsub = (IV=>A, IX=>B, XL=>E, XC=>F, CD=>G, CM=>H);
%val = (I=>1, V=>5, X=>10, L=>50, C=>100, D=>500, M=>1000,
A=>4, B=>9, E=>40, F=>90, G=>400, H=>900);
%maxpos = (I=>2, V=>3, X=>29, L=>39, C=>299, D=>399, M=>2999,
A=>0, B=>0, E=>9, F=>9, G=>99, H=>99);
for $i (0..$#alg)
{ $valg[$i] = $val{$alg[$i]};
}
sub roman_stx
{ my $x = shift;
my $aux = $$x;
$$x = uc $$x;
if ($$x eq $aux || lc $$x eq $aux)
{ if ($$x =~ /^[IXCMVLD]+$/ && $$x !~ /([IXCM])\1{3,}|([VLD])\2+/)
{ $$x =~ s/(IV|IX|XL|XC|CD|CM)/$parsub{$1}/g;
$$x !~ /[AB].*?I|[EF].*?X|[GH].*?C/;
}
else
{ '';}
}
else
{'';
}
}
sub roman2int
{ my $x = shift;
my ($at, $flag, $i);
my $val=0;
my $ant=0;
my @U;
my $U='';
if (&roman_stx(\$x))
{ @U = split('', $x);
for ($i = $#U; $i >= 0; $i--)
{ $at = $val{$U[$i]};
return '' if ($at<$ant);
$val += $at;
$ant = $at;
}
$val;
}
else
{ '';
}
}
sub mroman2int
# allows '_' milhar syntax (LX_XXIII, L_X_XXIII)
#
{ my $x = shift;
my $s=0;
my ($sroman, $i, $aux);
my $y='';
my @partes;
@partes = split ('_',$x);
$sroman = pop @partes;
for $i (@partes)
{ $y .= $i;
}
$aux = &roman2int($y);
return '' if ($y =~ /^(I{1,3})$/ || !$aux);
$s += $aux*1000;
$aux = &roman2int($sroman);
return '' if (!$aux);
$s+$aux;
}
sub ismroman
# allows '_' milhar syntax (LX_XXIII, L_X_XXIII)
#
{ my $x = shift;
my ($i,$sroman);
my $y='';
my @partes;
if ($x =~ /^[_IXCMVLD]+$/)
{ @partes = split ('_',$x);
$sroman = pop @partes;
for $i (@partes)
{ $y .= $i;
}
return '' if ($y =~ /^(I{1,3})$/ || !&isroman($y));
return &isroman($sroman);
}
}
sub isroman
# same efect that (&roman2int($x)>0), but fasted
#
{ my $x = shift;
my $y=$x;
$x = uc $x;
($x eq $y || lc $x eq $y) && $x =~ /^(M{1,3}(D(C{1,3}(L(X{1,3}(VI{0,3}|IV|I{1,3})?|X{0,3}IX|(VI{0,3}|IV|I{1,3}))?|XL(IX|(VI{0,3}|IV|I{1,3}))?|(X{1,3}(VI{0,3}|IV|I{1,3})?|X{0,3}IX|(VI{0,3}|IV|I{1,3})))?|C{0,3}XC(IX|(VI{0,3}|IV|I{1,3}))?|(L(X{1,3}(VI{0,3}|IV|I{1,3})?|X{0,3}IX|(VI{0,3}|IV|I{1,3}))?|XL(IX|(VI{0,3}|IV|I{1,3}))?|(X{1,3}(VI{0,3}|IV|I{1,3})?|X{0,3}IX|(VI{0,3}|IV|I{1,3}))))?|CD(XC(IX|(VI{0,3}|IV|I{1,3}))?|(L(X{1,3}(VI{0,3}|IV|I{1,3})?|X{0,3}IX|(VI{0,3}|IV|I{1,3}))?|XL(IX|(VI{0,3}|IV|I{1,3}))?|(X{1,3}(VI{0,3}|IV|I{1,3})?|X{0,3}IX|(VI{0,3}|IV|I{1,3}))))?|(C{1,3}(L(X{1,3}(VI{0,3}|IV|I{1,3})?|X{0,3}IX|(VI{0,3}|IV|I{1,3}))?|XL(IX|(VI{0,3}|IV|I{1,3}))?|(X{1,3}(VI{0,3}|IV|I{1,3})?|X{0,3}IX|(VI{0,3}|IV|I{1,3})))?|C{0,3}XC(IX|(VI{0,3}|IV|I{1,3}))?|(L(X{1,3}(VI{0,3}|IV|I{1,3})?|X{0,3}IX|(VI{0,3}|IV|I{1,3}))?|XL(IX|(VI{0,3}|IV|I{1,3}))?|(X{1,3}(VI{0,3}|IV|I{1,3})?|X{0,3}IX|(VI{0,3}|IV|I{1,3})))))?|M{0,3}CM(XC(IX|(VI{0,3}|IV|I{1,3}))?|(L(X{1,3}(VI{0,3}|IV|I{1,3})?|X{0,3}IX|(VI{0,3}|IV|I{1,3}))?|XL(IX|(VI{0,3}|IV|I{1,3}))?|(X{1,3}(VI{0,3}|IV|I{1,3})?|X{0,3}IX|(VI{0,3}|IV|I{1,3}))))?|(D(C{1,3}(L(X{1,3}(VI{0,3}|IV|I{1,3})?|X{0,3}IX|(VI{0,3}|IV|I{1,3}))?|XL(IX|(VI{0,3}|IV|I{1,3}))?|(X{1,3}(VI{0,3}|IV|I{1,3})?|X{0,3}IX|(VI{0,3}|IV|I{1,3})))?|C{0,3}XC(IX|(VI{0,3}|IV|I{1,3}))?|(L(X{1,3}(VI{0,3}|IV|I{1,3})?|X{0,3}IX|(VI{0,3}|IV|I{1,3}))?|XL(IX|(VI{0,3}|IV|I{1,3}))?|(X{1,3}(VI{0,3}|IV|I{1,3})?|X{0,3}IX|(VI{0,3}|IV|I{1,3}))))?|CD(XC(IX|(VI{0,3}|IV|I{1,3}))?|(L(X{1,3}(VI{0,3}|IV|I{1,3})?|X{0,3}IX|(VI{0,3}|IV|I{1,3}))?|XL(IX|(VI{0,3}|IV|I{1,3}))?|(X{1,3}(VI{0,3}|IV|I{1,3})?|X{0,3}IX|(VI{0,3}|IV|I{1,3}))))?|(C{1,3}(L(X{1,3}(VI{0,3}|IV|I{1,3})?|X{0,3}IX|(VI{0,3}|IV|I{1,3}))?|XL(IX|(VI{0,3}|IV|I{1,3}))?|(X{1,3}(VI{0,3}|IV|I{1,3})?|X{0,3}IX|(VI{0,3}|IV|I{1,3})))?|C{0,3}XC(IX|(VI{0,3}|IV|I{1,3}))?|(L(X{1,3}(VI{0,3}|IV|I{1,3})?|X{0,3}IX|(VI{0,3}|IV|I{1,3}))?|XL(IX|(VI{0,3}|IV|I{1,3}))?|(X{1,3}(VI{0,3}|IV|I{1,3})?|X{0,3}IX|(VI{0,3}|IV|I{1,3}))))))$/;
}
sub roman_div
{
my ($a, $b) = @_;
my $inf = $alginf[$b];
if ($b<0)
{ (0,-1); }
elsif ( int($a/$valg[$b])>0 )
{ ($b,-1); }
elsif ( $a+$valg[$inf]>=$valg[$b] )
{ ($b, $inf); }
else
{ &roman_div($a,$b-1); }
}
sub roman_do
{ my ($x, $str_x) = @_;
my ($aux, $inf);
($aux, $inf) = &roman_div($x,$#alg);
if ($x>0 && $inf<0)
{ &roman_do($x-$valg[$aux], $str_x.$alg[$aux]); }
elsif ($x>0 && $inf>=0)
{ &roman_do( $x+$valg[$inf]-$valg[$aux], $str_x.$alg[$inf].$alg[$aux] ); }
else
{ $str_x; }
}
sub roman
{ my ($x) = @_;
if ($x <1 || $x > 3999)
{'';}
else
{ roman_do($x,""); }
}
1;
__END__
=head1 NAME
Text::Roman - Converts roman algarism in integer numbers and the contrary, recognize algarisms.
=head1 SYNOPSIS
use Text::Roman;
print roman(123);
=head1 DESCRIPTION
Text::Roman::roman() is a very simple algarism converter. It converts a single integer
(in arabic algarisms) at a time to its roman correspondent. The conventional roman numbers
goes from 1 up to 3999. MROMANS (milhar romans) range is 1 up to 3999*1000+3999=4002999.
Up to these number we will found symbols as:??????but they do not concern this specific
package. There is no concern for mix cases, like 'Xv', 'XiiI', as legal roman algarism
numbers.
=over
=item B<roman($int)>: return string containing the roman corresponding to the given integer, or '' if the integer is out of domain...
=item B<roman2int($str)>: return '' if $str is not roman or return integer if it is.
=item B<isroman($str)>: verify whether the given string is a conventional roman number, if it is return 1; if it is not return 0...
=back
Quite same follows for B<mroman2int($str)> and B<ismroman($str)>, except that these functions
treat milhar romans.
=head1 SPECIFICATION
Roman number has origin in following BNF-like formula:
a = I{1,3}
b = V\a?|IV|\a
e = X{1,3}\b?|X{0,3}IX|\b
ee = IX|\b
f = L\e?|XL\ee?|\e
g = C{1,3}\f?|C{0,3}XC\ee?|\f
gg = XC\ee?|\f
h = D\g?|CD\gg?|\g
j = M{1,3}\h?|M{0,3}CM\gg?|\h
=head1 REFERENCES
Especification supplied by redactor's manual of newspaper "O Estado de São Paulo".
URL: http://www.estado.com.br/redac/norn-nro.html
=head1 EXAMPLE
use Text::Roman;
$roman = "XXXV";
$mroman = 'L_X_XXIII';
print roman(123), "\n";
print roman2int($roman), "\n" if isroman($roman);
print mroman2int($mroman), "\n" if ismroman($mroman);
=head1 BUGS
No one known.
=head1 AUTHOR
Peter de Padua Krauss, krauss@ifqsc.sc.usp.br.
=head1 COPYRIGHT
1.2-krauss/set/97; 1.0-krauss/3/ago/97
=cut
+609
View File
@@ -0,0 +1,609 @@
# Copyright (c) 2008 Behan Webster. All rights reserved. This program is free
# software; you can redistribute it and/or modify it under the same terms
# as Perl itself.
# Modified 2010 by Douglas Stebila to support parentheses in movie years
package Video::Filename;
use strict;
require Exporter;
use Debug::Simple;
use Data::Dumper;
use Term::ANSIColor qw(:constants);
use Text::Roman qw(roman2int);
$Term::ANSIColor::AUTORESET = 1;
use vars qw($VERSION @filePatterns @testFuncs);
$VERSION = "0.35.1";
@filePatterns = (
{ # DVD Episode Support - DddEee
# Perl > v5.10
re => '^(?:(?<name>.*?)[\/\s._-]+)?(?:d|dvd|disc|disk)[\s._]?(?<dvd>\d{1,2})[x\/\s._-]*(?:e|ep|episode)[\s._]?(?<episode>\d{1,2}(?:\.\d{1,2})?)(?:-?(?:(?:e|ep)[\s._]*)?(?<endep>\d{1,2}))?(?:[\s._]?(?:p|part)[\s._]?(?<part>\d+))?(?<subep>[a-z])?(?:[\/\s._-]*(?<epname>[^\/]+?))?$',
# Perl < v5.10
re_compat => '^(?:(.*?)[\/\s._-]+)?(?:d|dvd|disc|disk)[\s._]?(\d{1,2})[x\/\s._-]*(?:e|ep|episode)[\s._]?(\d{1,2})(?:-?(?:(?:e|ep)[\s._]*)?(\d{1,2}(?:\.\d{1,2})?))?(?:[\s._]?(?:p|part)[\s._]?(\d+))?([a-z])?(?:[\/\s._-]*([^\/]+?))?$',
keys_compat => [qw(name dvd episode endep part subep epname)],
test_funcs => [1, 0, 1, 0], # DVD TV Episode Movie
test_keys => [qw(filename name dvd episode endep part subep epname ext)],
test_files => [
['D01E02.Episode_name.avi', undef, 1, 2, undef, undef, undef, 'Episode_name', 'avi'],
['Series Name.D01E02.Episode_name.avi', 'Series Name', 1, 2, undef, undef, undef, 'Episode_name', 'avi'],
['Series Name/D01E02.Episode_name.avi', 'Series Name', 1, 2, undef, undef, undef, 'Episode_name', 'avi'],
['Series Name/D01E02/Episode_name.avi', 'Series Name', 1, 2, undef, undef, undef, 'Episode_name', 'avi'],
['Series Name.D01E02a.Episode_name.avi', 'Series Name', 1, 2, undef, undef, 'a', 'Episode_name', 'avi'],
['Series Name.D01E02p4.Episode_name.avi', 'Series Name', 1, 2, undef, 4, undef, 'Episode_name', 'avi'],
['Series Name.D01E02-03.Episode_name.avi', 'Series Name', 1, 2, 3, undef, undef, 'Episode_name', 'avi'],
['Series Name.D01E02-E03.Episode_name.avi', 'Series Name', 1, 2, 3, undef, undef, 'Episode_name', 'avi'],
['Series Name.D01E02E.03.Episode_name.avi', 'Series Name', 1, 2, 3, undef, undef, 'Episode_name', 'avi'],
['Series Name/D01E02E03/Episode_name.avi', 'Series Name', 1, 2, 3, undef, undef, 'Episode_name', 'avi'],
['D01E02E03/Episode name.avi', undef, 1, 2, 3, undef, undef, 'Episode name', 'avi'],
['Series Name.DVD_01.Episode_02.Episode_name.avi', 'Series Name', 1, 2, undef, undef, undef, 'Episode_name', 'avi'],
['Series Name.disk_V.Episode_XI.Episode_name.avi', 'Series Name', 5, 11, undef, undef, undef, 'Episode_name', 'avi'],
['Series Name.disc_V.Episode_XI.Part.XXV.Episode_name.avi', 'Series Name', 5, 11, undef, 25, undef, 'Episode_name', 'avi'],
['Series Name.DVD01.Ep02.Episode_name.avi', 'Series Name', 1, 2, undef, undef, undef, 'Episode_name', 'avi'],
['Series Name/dvd_01.Episode_02.Episode_name.avi', 'Series Name', 1, 2, undef, undef, undef, 'Episode_name', 'avi'],
['Series Name/disk_01/Episode_02.Episode_name.avi', 'Series Name', 1, 2, undef, undef, undef, 'Episode_name', 'avi'],
['Series Name/D.I/Ep02.Episode_name.avi', 'Series Name', 1, 2, undef, undef, undef, 'Episode_name', 'avi'],
['Series Name/D three/Ep five Episode_name.avi', 'Series Name', 3, 5, undef, undef, undef, 'Episode_name', 'avi'],
],
},
{ # TV Show Support - SssEee or Season_ss_Episode_ss
# Perl > v5.10
re => '^(?:(?<name>.*?)[\/\s._-]+)?(?:s|se|season|series)[\s._-]?(?<season>\d+)[x\/\s._-]*(?:e|ep|episode|[\/\s._-]+)[\s._-]?(?<episode>\d+)(?:-?(?:(?:e|ep)[\s._]*)?(?<endep>\d+))?(?:[\s._]?(?:p|part)[\s._]?(?<part>\d+))?(?<subep>[a-z])?(?:[\/\s._-]*(?<epname>[^\/]+?))?$',
# Perl < v5.10
re_compat => '^(?:(.*?)[\/\s._-]+)?(?:s|se|season|series)[\s._-]?(\d+)[x\/\s._-]*(?:e|ep|episode|[\/\s._-]+)[\s._-]?(\d+)(?:-?(?:(?:e|ep)[\s._]*)?(\d+))?(?:[\s._]?(?:p|part)[\s._]?(\d+))?([a-z])?(?:[\/\s._-]*([^\/]+?))?$',
keys_compat => [qw(name season episode endep part subep epname)],
test_funcs => [0, 1, 1, 0], # DVD TV Episode Movie
test_keys => [qw(filename name guess-name season episode endep part subep epname ext)],
test_files => [
['S01E02.Episode_name.avi', undef, undef, 1, 2, undef, undef, undef, 'Episode_name', 'avi'],
['Series Name.S01E02.Episode_name.avi', 'Series Name', undef, 1, 2, undef, undef, undef, 'Episode_name', 'avi'],
['Series Name/S01E02.Episode_name.avi', 'Series Name', undef, 1, 2, undef, undef, undef, 'Episode_name', 'avi'],
['Series Name/S01E02/Episode_name.avi', 'Series Name', undef, 1, 2, undef, undef, undef, 'Episode_name', 'avi'],
['Series/Name/S01E02/Episode_name.avi', 'Name', 'Series Name', 1, 2, undef, undef, undef, 'Episode_name', 'avi'],
['Series/Name/S01940E0237/Episode_name.avi', 'Name', 'Series Name', 1940, 237, undef, undef, undef, 'Episode_name', 'avi'],
['Series Name.S01E02a.Episode_name.avi', 'Series Name', undef, 1, 2, undef, undef, 'a', 'Episode_name', 'avi'],
['Series Name.S01E02p4.Episode_name.avi', 'Series Name', undef, 1, 2, undef, 4, undef, 'Episode_name', 'avi'],
['Series Name.S01E02-03.Episode_name.avi', 'Series Name', undef, 1, 2, 3, undef, undef, 'Episode_name', 'avi'],
['Series Name.S01E02-E03.Episode_name.avi', 'Series Name', undef, 1, 2, 3, undef, undef, 'Episode_name', 'avi'],
['Series Name.S01E02E.03.Episode_name.avi', 'Series Name', undef, 1, 2, 3, undef, undef, 'Episode_name', 'avi'],
['Series Name/S01E02E03/Episode_name.avi', 'Series Name', undef, 1, 2, 3, undef, undef, 'Episode_name', 'avi'],
['S01E02E03/Episode name.avi', undef, undef, 1, 2, 3, undef, undef, 'Episode name', 'avi'],
['Series Name.Season_01.Episode_02.Episode_name.avi', 'Series Name', undef, 1, 2, undef, undef, undef, 'Episode_name', 'avi'],
['Series Name.Season_V.Episode_XI.Episode_name.avi', 'Series Name', undef, 5, 11, undef, undef, undef, 'Episode_name', 'avi'],
['Series Name.Season_V.Episode_XI.Part.XXV.Episode_name.avi', 'Series Name', undef, 5, 11, undef, 25, undef, 'Episode_name', 'avi'],
['Series Name.Se01.Ep02.Episode_name.avi', 'Series Name', undef, 1, 2, undef, undef, undef, 'Episode_name', 'avi'],
['Series Name/Season_01.Episode_02.Episode_name.avi', 'Series Name', undef, 1, 2, undef, undef, undef, 'Episode_name', 'avi'],
['Series Name/Season_01/Episode_02.Episode_name.avi', 'Series Name', undef, 1, 2, undef, undef, undef, 'Episode_name', 'avi'],
['Series Name/Season_01/02.Episode_name.avi', 'Series Name', undef, 1, 2, undef, undef, undef, 'Episode_name', 'avi'],
['Series Name/S.I/Ep02.Episode_name.avi', 'Series Name', undef, 1, 2, undef, undef, undef, 'Episode_name', 'avi'],
['Series Name/S.one/Ep twelve.Episode_name.avi', 'Series Name', undef, 1, 12, undef, undef, undef, 'Episode_name', 'avi'],
],
},
{ # Movie IMDB Support
# Perl > v5.10
re => '^(?<movie>.*?)?(?:[\/\s._-]*(?<openb>\[)?(?<year>(?:19|20)\d{2})(?(<openb>)\]))?(?:[\/\s._-]*(?<openc>\[)?(?:(?:imdb|tt)[\s._-]*)*(?<imdb>\d{7})(?(<openc>)\]))(?:[\s._-]*(?<title>[^\/]+?))?$',
# Perl < v5.10
re_compat => '^(.*?)?(?:[\/\s._-]*\[?((?:19|20)\d{2})\]?)?(?:[\/\s._-]*\[?(?:(?:imdb|tt)[\s._-]*)*(\d{7})\]?)(?:[\s._-]*([^\/]+?))?$',
keys_compat => [qw(movie year imdb title)],
test_funcs => [0, 0, 0, 1], # DVD TV Episode Movie
test_keys => [qw(filename movie guess-movie year imdb title ext)],
test_files => [
['Movie Name [1996] [imdb 1234567].mkv', 'Movie Name', undef, 1996, 1234567, undef, 'mkv'],
['Movie Name [1996] [imdb tt1234567].mkv', 'Movie Name', undef, 1996, 1234567, undef, 'mkv'],
['Movie Name [1996] [1234567].avi', 'Movie Name', undef, 1996, 1234567, undef, 'avi'],
['Movie Name [1996] [tt1234567] foo.avi', 'Movie Name', undef, 1996, 1234567, 'foo', 'avi'],
['Movie Name [1996]/tt1234567-foo.avi', 'Movie Name', undef, 1996, 1234567, 'foo', 'avi'],
['Movie/Name/tt1234567_foo.avi', 'Name', 'Movie Name', undef, 1234567, 'foo', 'avi'],
['Movie Name.[tt0096657] bar.avi', 'Movie Name', undef, undef, '0096657', 'bar', 'avi'],
['Movie Name.tt0096657-foo.avi', 'Movie Name', undef, undef, '0096657', 'foo', 'avi'],
['Movie.Name.tt0096657foo.avi', 'Movie.Name', undef, undef, '0096657', 'foo', 'avi'],
['Movie Name.tt0096657_foo.avi', 'Movie Name', undef, undef, '0096657', 'foo', 'avi'],
['Movie Name.tt0096657.avi', 'Movie Name', undef, undef, '0096657', undef, 'avi'],
['Movie Name.[0096657].avi', 'Movie Name', undef, undef, '0096657', undef, 'avi'],
['imdb-tt0096657.avi', undef, undef, undef, '0096657', undef, 'avi'],
['tt0096657.mov', undef, undef, undef, '0096657', undef, 'mov'],
['tt0096857', undef, undef, undef, '0096857', undef, undef],
['1234576', undef, undef, undef, '1234576', undef, undef],
],
#warning => 'Found year instead of season+episode',
},
{ # Movie + Year Support
# Perl > v5.10
re => '^(?:(?<movie>.*?)[\/\s._-]*)?(?<openb>\[\(?)?(?<year>(?:19|20)\d{2})(?(<openb>)\)?\])(?:[\s._-]*(?<title>[^\/]+?))?$',
# Perl < v5.10
re_compat => '^(?:(.*?)[\/\s._-]*)?\[?\(?((?:19|20)\d{2})\)?\]?(?:[\s._-]*([^\/]+?))?$',
keys_compat => [qw(movie year title)],
test_funcs => [0, 0, 0, 1], # DVD TV Episode Movie
test_keys => [qw(filename movie year title ext)],
test_files => [
['Movie (1988).avi', 'Movie', 1988, undef, 'avi'],
['Movie.[1988].avi', 'Movie', 1988, undef, 'avi'],
['Movie.2000.title.avi', 'Movie', 2000, 'title', 'avi'],
['Movie/2009.title.avi', 'Movie', 2009, 'title', 'avi'],
],
#warning => 'Found year instead of season+episode',
},
{ # TV Show Support - see
# Perl > v5.10
re => '^(?:(?<name>.*?)[\/\s._-]*)?(?<season>\d{1,2}?)(?<episode>\d{2})(?:[^0-9][\s._-]*(?<epname>.+?))?$',
# Perl < v5.10
re_compat => '^(?:(.*?)[\/\s._-]*)?(\d{1,2}?)(\d{2})(?:[^0-9][\s._-]*(.+?))?$',
keys_compat => [qw(name season episode epname)],
test_funcs => [0, 1, 1, 0], # DVD TV Episode Movie
test_keys => [qw(filename name season episode epname ext)],
test_files => [
['SN102.Episode_name.avi', 'SN', 1, 2, 'Episode_name', 'avi'],
['Series Name.102.Episode_name.avi', 'Series Name', 1, 2, 'Episode_name', 'avi'],
['Series Name/102.Episode_name.avi', 'Series Name', 1, 2, 'Episode_name', 'avi'],
],
},
{ # TV Show Support - sxee
# Perl > v5.10
re => '^(?:(?<name>.*?)[\/\s._-]*)?(?<openb>\[)?(?<season>\d{1,2})[x\/](?<episode>\d{1,2})(?:-(?:\k<season>x)?(?<endep>\d{1,2}))?(?(<openb>)\])(?:[\s._-]*(?<epname>[^\/]+?))?$',
# Perl < v5.10
re_compat => '^(?:(.*?)[\/\s._-]*)?\[?(\d{1,2})[x\/](\d{1,2})(?:-(?:\d{1,2}x)?(\d{1,2}))?\]?(?:[\s._-]*([^\/]+?))?$',
keys_compat => [qw(name season episode endep epname)],
test_funcs => [0, 1, 1, 0], # DVD TV Episode Movie
test_keys => [qw(filename name season episode endep epname ext)],
test_files => [
['Series Name.1x02.Episode_name.avi', 'Series Name', 1, 2, undef, 'Episode_name', 'avi'],
['Series Name/1x02.Episode_name.avi', 'Series Name', 1, 2, undef, 'Episode_name', 'avi'],
['Series Name.[1x02].Episode_name.avi', 'Series Name', 1, 2, undef, 'Episode_name', 'avi'],
['Series Name.1x02-03.Episode_name.avi', 'Series Name', 1, 2, 3, 'Episode_name', 'avi'],
['Series Name.1x02-1x03.Episode_name.avi', 'Series Name', 1, 2, 3, 'Episode_name', 'avi'],
],
},
{ # TV Show Support - season only
# Perl > v5.10
re => '^(?:(?<name>.*?)[\/\s._-]+)?(?:s|se|season|series)[\s._]?(?<season>\d{1,2})(?:[\/\s._-]*(?<epname>[^\/]+?))?$',
# Perl < v5.10
re_compat => '^(?:(.*?)[\/\s._-]+)?(?:s|se|season|series)[\s._]?(\d{1,2})(?:[\/\s._-]*([^\/]+?))?$',
keys_compat => [qw(name season epname)],
test_funcs => [0, 0, 0, 0], # DVD TV Episode Movie
test_keys => [qw(filename name season epname ext)],
test_files => [
['Series Name.s1.Episode_name.avi', 'Series Name', 1, 'Episode_name', 'avi'],
['Series Name.s01.Episode_name.avi', 'Series Name', 1, 'Episode_name', 'avi'],
['Series Name/se01.Episode_name.avi', 'Series Name', 1, 'Episode_name', 'avi'],
['Series Name.season_1.Episode_name.avi', 'Series Name', 1, 'Episode_name', 'avi'],
['Series Name/season_1/Episode_name.avi', 'Series Name', 1, 'Episode_name', 'avi'],
['Series Name/season ten/Episode_name.avi', 'Series Name', 10, 'Episode_name', 'avi'],
],
},
{ # TV Show Support - episode only
# Perl > v5.10
re => '^(?:(?<name>.*?)[\/\s._-]*)?(?:(?:e|ep|episode)[\s._]?)?(?<episode>\d{1,2})(?:-(?:e|ep)?(?<endep>\d{1,2}))?(?:(?:p|part)(?<part>\d+))?(?<subep>[a-z])?(?:[\/\s._-]*(?<epname>[^\/]+?))?$',
# Perl < v5.10
re_compat => '^(?:(.*?)[\/\s._-]*)?(?:(?:e|ep|episode)[\s._]?)?(\d{1,2})(?:-(?:e|ep)?(\d{1,2}))?(?:(?:p|part)(\d+))?([a-z])?(?:[\/\s._-]*([^\/]+?))?$',
keys_compat => [qw(name episode endep part subep epname)],
test_funcs => [0, 0, 1, 0], # DVD TV Episode Movie
test_keys => [qw(filename name episode endep part subep epname ext)],
test_files => [
['Series Name.Episode_02.Episode_name.avi', 'Series Name', 2, undef, undef, undef, 'Episode_name', 'avi'],
['Series Name/Episode_02.Episode_name.avi', 'Series Name', 2, undef, undef, undef, 'Episode_name', 'avi'],
['Series Name/Ep02.Episode_name.avi', 'Series Name', 2, undef, undef, undef, 'Episode_name', 'avi'],
['E02.Episode_name.avi', undef, 2, undef, undef, undef, 'Episode_name', 'avi'],
['Series Name.E02.Episode_name.avi', 'Series Name', 2, undef, undef, undef, 'Episode_name', 'avi'],
['Series Name.02.Episode_name.avi', 'Series Nam', 2, undef, undef, undef, 'Episode_name', 'avi'],
['Series Name/E02.Episode_name.avi', 'Series Name', 2, undef, undef, undef, 'Episode_name', 'avi'],
['Series Name/02.Episode_name.avi', 'Series Name', 2, undef, undef, undef, 'Episode_name', 'avi'],
['Series Name/E02/Episode_name.avi', 'Series Name', 2, undef, undef, undef, 'Episode_name', 'avi'],
['Series Name/02/Episode_name.avi', 'Series Name', 2, undef, undef, undef, 'Episode_name', 'avi'],
['Series Name.E02a.Episode_name.avi', 'Series Name', 2, undef, undef, 'a', 'Episode_name', 'avi'],
['Series Name.E02p3.Episode_name.avi', 'Series Name', 2, undef, 3, undef, 'Episode_name', 'avi'],
['Series Name.E02-03.Episode_name.avi', 'Series Name', 2, 3, undef, undef, 'Episode_name', 'avi'],
['Series Name.E02-E03.Episode_name.avi', 'Series Name', 2, 3, undef, undef, 'Episode_name', 'avi'],
],
},
{ # Default Movie Support
# Perl > v5.10
re => '^(?<movie>.*)$',
# Perl < v5.10
re_compat => '^(.*)$',
keys_compat => [qw(movie)],
test_funcs => [0, 0, 0, 1], # DVD TV Episode Movie
test_keys => [qw(filename movie ext)],
test_files => [
['Movie.mov', 'Movie', 'mov'],
],
#warning => 'Found year instead of season+episode',
},
);
###############################################################################
sub new {
my $self = bless {};
# Read default values
for my $key (qw(file name season episode part options)) {
last unless defined $_[0];
if (ref $_[0]) {
# Use a hashref for values
while (my ($key, $value) = each %{$_[0]}) {
$self->{$key} = $value;
}
} else {
$self->{$key} = shift;
}
}
# Seed endep/subep from passed in episode
if (defined $self->{episode}) {
$self->{endep} = $1 if $self->{episode} =~ s/-(\d+)//i;
$self->{subep} = $1 if $self->{episode} =~ s/([a-z])$//i;
}
&debug(5, "VideoFilename: $self->{file}\n");
# Start parsing file
my $file = $self->{file};
$self->{dir} = $1 if $file =~ m|^(.*/)|;
$self->{filename} = $1 if $file;
$self->{ext} = lc $1 if $file =~ s/\.([0-9a-z]+)$//i;
# Translate appropriate roman/english numbers to numerals
my $prefix = '(?:d|dvd|disc|disk|s|se|season|e|ep|episode)[\s._-]+';
my $end = '(?:day|part)[\s._-]+';
$file = &_allroman2int($file, $prefix, $end);
$file = &_allnum2int($file, $prefix, $end);
# Strip out any irrelevant numbers which screw up parsing
$file =~ s/480p//;
$file =~ s/720p//;
$file =~ s/1080p//;
$file =~ s/x264//;
# Run pre-processed filename through list of patterns
for my $pat (@filePatterns) {
if ($] >= 5.010000) {
if ($file =~ /$pat->{re}/i) {
&warning($pat->{warning}) if defined $pat->{warning};
&debug(3, "PARSEINFO: $pat->{re}\n");
$self->{regex} = $pat->{re};
while (my ($key, $data) = each %-) {
$self->{$key} = $data->[0] if defined $data->[0] && !defined $self->{$key};
}
last;
}
} else { # No named groups in regexes
my @matches;
if (@matches = ($file =~ /$pat->{re_compat}/i)) {
#print "MACTHES: ".join(',', @matches)."\n";
&warning($pat->{warning}) if defined $pat->{warning};
&debug(3, "PARSEINFO: $pat->{re_compat}\n");
$self->{regex} = $pat->{re_compat};
my $count = 0;
foreach my $key (@{$pat->{keys_compat}}) {
$self->{$key} = $matches[$count] unless defined $self->{$key};
$count++;
}
last;
}
}
}
# Perhaps a movie is really a name with default season or episode
if ((defined $self->{name} || defined $self->{season} || defined $self->{episode}) && defined $self->{movie}) {
$self->{name} = $self->{movie} unless defined $self->{name};
delete $self->{movie};
}
# Process Series/Movie
for my $key (qw(name movie epname title)) {
if (defined $self->{$key}) {
if ($self->{$key} =~ /^.*\/(.*?)$/) {
# Get rid of any directory parts
$self->{"guess-$key"} = $self->{$key};
# Keep the original name without '/' just in case the name contains a subdir
$self->{$key} = $1;
$self->{"guess-$key"} =~ s/[\/\s._-]+/ /;
}
$self->{$key} =~ s/[$self->{spaces}]+/ /g if defined $self->{spaces};
$self->{$key} =~ s/^\s*(.+?)\s*$/$1/; # Remove leading/trailing separators
}
}
# Guess part from epname
if (defined $self->{epname} && !defined $self->{part}) {
my $rmpart = 'Episode|Part|PT'; # Remove "Part #" from episode name
my $epname = &_allnum2int($self->{epname}); # Make letters into integers
if ($epname =~ /(?:$rmpart) (\d+)/i
|| $epname =~ /(\d+)\s*(?:of|-)\s*\d+/i
|| $epname =~ /^(\d+)/
|| $epname =~ /[\s._-](\d+)$/
) {
$self->{part} = $1;
}
}
# Cosmetics
for my $key (qw(dvd season episode endep part)) {
$self->{$key} =~ s/^0+// if defined $self->{$key};
}
$self->{endep} = undef if $self->{endep} == $self->{episode};
# Convenience for some developpers
if (defined $self->{season}) {
$self->{seasonepisode} = sprintf("S%02dE%02d", $self->{season}, $self->{episode});
} elsif (defined $self->{dvd}) {
$self->{seasonepisode} = sprintf("D%02dE%02.1f", $self->{dvd}, $self->{episode});
}
&debug(2, '', VideoFilename=>$self);
return $self;
}
###############################################################################
sub _num2int {
my $str = shift;
my ($n, $c, $sum) = (0, 0, 0);
while ($str) {
$str =~ s/^[\s,]+//;
debug(3, "STR=$str NUM=$n\n");
if ($str =~ s/^(zero|and|&)//i) { next;
} elsif ($str =~ s/^one//i) { $n += 1;
} elsif ($str =~ s/^tw(o|en)//i) { $n += 2;
} elsif ($str =~ s/^th(ree|ir)//i) { $n += 3;
} elsif ($str =~ s/^four//i) { $n += 4;
} elsif ($str =~ s/^fi(ve|f)//i) { $n += 5;
} elsif ($str =~ s/^six//i) { $n += 6;
} elsif ($str =~ s/^seven//i) { $n += 7;
} elsif ($str =~ s/^eight//i) { $n += 8;
} elsif ($str =~ s/^nine//i) { $n += 9;
} elsif ($str =~ s/^(t|te|e)en//i) { $n += 10;
} elsif ($str =~ s/^eleven//i) { $n += 11;
} elsif ($str =~ s/^twelve//i) { $n += 12;
} elsif ($str =~ s/^t?y//i) { $n *= 10;
} elsif ($str =~ s/^hundred//i) { $c += $n * 100; $n = 0;
} elsif ($str =~ s/^thousand//i) { $sum += ($c+$n) * 1000; ($c,$n) = (0,0);
} elsif ($str =~ s/^million//i) { $sum += ($c+$n) * 1000000; ($c,$n) = (0,0);
} elsif ($str =~ s/^billion//i) { $sum += ($c+$n) * 1000000000; ($c,$n) = (0,0);
} elsif ($str =~ s/^trillion//i) { $sum += ($c+$n) * 1000000000000; ($c,$n) = (0,0);
}
}
$sum += ($c+$n);
debug(2, "STR=$str SUM=$sum\n");
return $sum;
}
sub _allnum2int {
my ($str, $prefix, $end) = @_;
my $single = 'zero|one|two|three|five|(?:twen|thir|four|fif|six|seven|nine)(?:|teen|ty)|eight(?:|een|y)|ten|eleven|twelve';
my $mult = 'hundred|thousand|(?:m|b|tr)illion';
my $regex = "((?:(?:$single|$mult)(?:$single|$mult|\s|,|and|&)+)?(?:$single|$mult))";
if ($] >= 5.010000) {
$str =~ s/$prefix\K\b$regex\b/&_num2int($1)/egis;
$str =~ s/$end\K\b$regex$/&_num2int($1)/egis if defined $end;
} else {
$str =~ s/($prefix)\b$regex\b/"$1".&_num2int($2)/egis;
$str =~ s/($end)\b$regex$/"$1".&_num2int($2)/egis if defined $end;
}
return $str;
}
sub _allroman2int {
my ($str, $prefix, $end) = @_;
my $roman = '[MC]*[DC]*[CX]*[LX]*[XI]*[VI]*';
if ($] >= 5.010000) {
$str =~ s/\b$prefix\K($roman)\b/roman2int($1)/egi;
$str =~ s/\b$end\K($roman)$/roman2int($1)/egi if defined $end;
} else {
$str =~ s/\b($prefix)($roman)\b/"$1".roman2int($2)/egi;
$str =~ s/\b($end)($roman)$/"$1".roman2int($2)/egi if defined $end;
}
return $str;
}
###############################################################################
sub isDVDshow {
my ($self) = @_;
return defined $self->{dvd} && defined $self->{episode};
}
###############################################################################
sub isTVshow {
my ($self) = @_;
return defined $self->{season} && defined $self->{episode};
}
###############################################################################
sub isEpisode {
my ($self) = @_;
return defined $self->{episode};
}
###############################################################################
sub isMovie {
my ($self) = @_;
return defined $self->{movie} || defined $self->{imdb};
}
###############################################################################
sub testVideoFilename {
my @funcs = qw(isDVDshow isTVshow isEpisode isMovie);
for my $pat (@filePatterns) {
for my $test (@{$pat->{test_files}}) {
my $file = new($test->[0]);
# Make the correct rule fired
if ($file->{regex} ne $pat->{re}) {
print RED "PATT RE: $pat->{re}\nFILE RE: $file->{regex}\n";
print RED "FAILED: $file->{file} (wrong rule)\n";
print Dumper($file); exit;
}
# Make sure all the attributes were correctly parsed
my $keys = $pat->{test_keys};
for my $i (1..8) {
my $attr = $file->{$keys->[$i]};
my $value = $test->[$i];
if ($attr ne $value) {
print RED "'$attr' ne '$value'\nFAILED: $file->{file}\n";
print Dumper($file); exit;
}
&verbose(1, "'$attr' eq '$value'\n");
}
# Make sure all the isXXXX() functions work properly
for my $i (0..$#funcs) {
unless (eval "\$file->$funcs[$i]()" == $pat->{test_funcs}->[$i]) {
print RED "\$file->$funcs[$i]() != $pat->{test_funcs}->[$i]\nFAILED: $file->{file}\n";
print Dumper($file); exit;
}
}
print GREEN "PASSED: $file->{file}\n";
}
}
}
###############################################################################
__END__
=head1 NAME
Video::Filename - Parse filenames for information about the video
=head1 SYNOPSIS
use Video::Filename;
my $file = Video::Filename::new($filename, [$name, [$season, [$episode]]]);
my $file = Video::Filename::new($filename, {
name => 'series name',
season => 4,
episode => 5,
spaces => '\s._-',
} );
# TV or DVD Episode
$file->{regex}
$file->{dir}
$file->{file}
$file->{name}
$file->{dvd}
$file->{season}
$file->{episode}
$file->{endep}
$file->{subep}
$file->{part}
$file->{epname}
$file->{ext}
# Movie
$file->{movie}
$file->{year}
$file->{imdb}
$file->{title}
$file->isDVDshow();
$file->isTVshow();
$file->isEpisode();
$file->isMovie();
$file->testVideoFilename();
=head1 DESCRIPTION
Video::Filename is used to parse information line name/season/episode and such
from a video filename. It also does a reasonable job at distinguishing a movie
from a tv episode.
=over 4
=item $file = Video::Filename::new(FILENAME, [NAME, [SEASON, [EPISODE]]]);
Parse C<FILENAME> and return a Video::Filename object containing the data. If
you specify C<NAME>, C<SEASON>, and/or C<EPISODE> it will override what is
parsed from C<FILENAME>.
Alternatively, arguments can be passed in a hashref. This also allows the user
to specify the option of specifying characters which are replaced with spaces
in the parsed 'name', 'epname', 'movie', and 'title' fields.
my $file = Video::Filename::new('This.is.a.name.s01e01.episode_title.avi', {
season => 4,
spaces => '\s._-',
} );
print Dumper($file);
$file = bless( {
'epname' => 'episode title',
'name' => 'This is a name',
'file' => 'This.is.a.name.s01e01.episode_title.avi',
'spaces' => '._',
'seasonepisode' => 'S04E01',
'episode' => 1,
'ext' => 'avi',
'season' => 4
}, 'Video::Filename' );
Notice that that the season was overridden in the call to new(), so it's "4"
instead of the "1" parsed from the file name.
=item isDVDshow();
Returns true if the object represents a DVD episode.
=item isTVshow();
Returns true if the object represents a TV episode.
=item isEpisode();
Returns true if the object represents an episode (TV or DVD).
=item isMovie();
Returns true if the object represents a Movie.
=item testVideoFilename();
Run a series of tests on the rules used to parse filenames. Basically a test
harness.
=back
=head1 COPYRIGHT
Copyright (c) 2008 by Behan Webster. All rights reserved.
=head1 LICENSE
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
=head1 AUTHOR
S<Behan Webster E<lt>behanw@websterwood.comE<gt>>
=cut
# vim: sw=4 ts=4