Oleg Oshmyan avatar Oleg Oshmyan committed 9b7a626

Added --lyricsFile and APar_MetaData_atomLyrics_Set

Comments (0)

Files changed (3)

src/AtomicParsley.h

   char* env_PicOptions);
 
 void APar_MetaData_atomGenre_Set(const char* atomPayload);
+void APar_MetaData_atomLyrics_Set(const char* lyricsPath);
 void APar_MetaData_atom_QuickInit(short atom_num, const uint32_t atomFlags,
   uint32_t supplemental_length, uint32_t allotment = MAXDATA_PAYLOAD + 1);
 
 #define Meta_comment             'c'
 #define Meta_year                'y'
 #define Meta_lyrics              'l'
+#define Meta_lyrics_file         0xC7
 #define Meta_composer            'w'
 #define Meta_copyright           'x'
 #define Meta_grouping            'G'
 "  --comment      (string)     Set the comment tag\n"
 "  --year         (num|UTC)    Year tag (see --longhelp for \"Release Date\")\n"
 "  --lyrics       (string)     Set lyrics (not subject to 256 byte limit)\n"
+"  --lyricsFile   (/path)      Set lyrics to the content of a file\n"
 "  --composer     (string)     Set the composer tag\n"
 "  --copyright    (string)     Set the copyright tag\n"
 "  --grouping     (string)     Set the grouping tag\n"
 "  --year             ,  -y   (num|UTC)    Set the year tag: \"moov.udta.meta.ilst.\302�day.data\"\n"
 "                                          set with UTC \"2006-09-11T09:00:00Z\" for Release Date\n"
 "  --lyrics           ,  -l   (str)    Set the lyrics tag: \"moov.udta.meta.ilst.\302�lyr.data\"\n"
+"  --lyricsFiles      ,       (/path)  Set the lyrics tag to the content of a file\n"
 "  --composer         ,  -w   (str)    Set the composer tag: \"moov.udta.meta.ilst.\302�wrt.data\"\n"
 "  --copyright        ,  -x   (str)    Set the copyright tag: \"moov.udta.meta.ilst.cprt.data\"\n"
 "  --grouping         ,  -G   (str)    Set the grouping tag: \"moov.udta.meta.ilst.\302�grp.data\"\n"
         { "comment",          required_argument,  NULL,           Meta_comment },
         { "year",             required_argument,  NULL,           Meta_year },
         { "lyrics",           required_argument,  NULL,           Meta_lyrics },
+        { "lyricsFile",       required_argument,  NULL,           Meta_lyrics_file },
         { "composer",         required_argument,  NULL,           Meta_composer },
         { "copyright",        required_argument,  NULL,           Meta_copyright },
         { "grouping",         required_argument,  NULL,           Meta_grouping },
             break;
         }
 
+        case Meta_lyrics_file : {
+            APar_ScanAtoms(ISObasemediafile);
+            if ( !APar_assert(metadata_style == ITUNES_STYLE, 1, "lyrics") ) {
+                break;
+            }
+
+            APar_MetaData_atomLyrics_Set(optarg);
+            break;
+        }
+
         case Meta_composer : {
             APar_ScanAtoms(ISObasemediafile);
             if ( !APar_assert(metadata_style == ITUNES_STYLE, 1, "composer") ) {
 }
 
 /*----------------------
+APar_MetaData_atomLyrics_Set
+	lyricsPath - the path that was provided to a (hopefully) existent txt file
+
+	lyrics will be read from a file because they can contain multiple lines. Lines are stored with old Mac-style line endings (single carriage return).
+----------------------*/
+void APar_MetaData_atomLyrics_Set(const char* lyricsPath) {
+	if (metadata_style == ITUNES_STYLE) {
+		TestFileExistence(lyricsPath, true);
+		off_t file_len = findFileSize(lyricsPath);
+
+		APar_Verify__udta_meta_hdlr__atom();
+		modified_atoms = true;
+
+		AtomicInfo* lyricsData_atom = APar_FindAtom("moov.udta.meta.ilst.�lyr.data", true, VERSIONED_ATOM, 0);
+		APar_MetaData_atom_QuickInit(lyricsData_atom->AtomicNumber, AtomFlags_Data_Text, 0, file_len + 1);
+
+		FILE* lyrics_file = APar_OpenFile(lyricsPath, "r");
+		off_t chars_read = 0;
+		char* dest = lyricsData_atom->AtomicData + 4;
+		while (!feof(lyrics_file) && !ferror(lyrics_file) && chars_read < file_len) {
+			fgets(dest, file_len + 1 - chars_read, lyrics_file);
+			size_t new_chars = strlen(dest); //NUL bytes in the file will cause parts of the text to be skipped
+			chars_read += new_chars;
+			dest += new_chars;
+			if (dest[-1] == '\n') dest[-1] = '\r';
+		}
+		lyricsData_atom->AtomicLength += chars_read;
+		fclose(lyrics_file);
+
+		APar_FlagMovieHeader();
+	} //end if (metadata_style == ITUNES_STYLE)
+	return;
+}
+
+/*----------------------
 APar_MetaData_atomArtwork_Init
 	atom_num - the AtomicNumber of the atom in the parsedAtoms array (probably newly created)
 	artworkPath - the path that was provided on a (hopefully) existant jpg/png file
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.