Skip to content

Commit

Permalink
Merge pull request #9 from iPodControl/main
Browse files Browse the repository at this point in the history
added command line argument for csv / json. csv is default
  • Loading branch information
raleighlittles authored Dec 15, 2024
2 parents 63c0a5d + 5d33e72 commit e143cf8
Show file tree
Hide file tree
Showing 8 changed files with 196 additions and 130 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
**/**.DS_Store
**/*.csv
**/*.json
**/.vscode
**/.txt

# Added by cargo

/target
74 changes: 36 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,39 @@ This repository contains a parser/extractor for iTunesDB files, written in Rust.

The table below shows which iTunesDB files are supported.

| File type | Supported? |
|----------------------|------------------------------------------------------------------|
| Artwork DB | :negative_squared_cross_mark: Not yet supported |
| DeviceInfo | Partial - Can extract iPod name only |
| Equalizer Presets | :heavy_check_mark: Extracts both the iTunes and actual DSP values |
| On The Go Playlist | :negative_squared_cross_mark: Not yet supported |
| Photo Database | :heavy_check_mark: Can extract all associated metadata of images |
| PhotoFolderAlbums | Partial - only can detect the # of photo albums |
| PhotoFolderPrefs | No support planned. |
| PhotosFolderName | :negative_squared_cross_mark: Not yet supported |
| Play Counts | :heavy_check_mark: |
| Preferences | :heavy_check_mark: |
| WABContactsGroup | :negative_squared_cross_mark: Not yet supported |
| iEKInfo | :negative_squared_cross_mark: Not yet supported |
| iTunesDB | Partial - Songs and Podcasts only. No television or movies |
| iTunesPState | :negative_squared_cross_mark: Not yet supported |
| iTunesPlaylists | :grey_question: [Not documented yet](http://www.ipodlinux.org/ITunesDB/#iTunesPlaylists) |
| iTunesPodcasts | :grey_question: [Not documented yet](http://www.ipodlinux.org/ITunesDB/#iTunesPodcasts) |
| iTunesPrefs | :heavy_check_mark: |
| iTunesSD | :heavy_check_mark: |
| iTunesStats | :negative_squared_cross_mark: Not yet supported |
| File type | Supported? |
| -------------------- | --------------------------------------------------------------------------------------------- |
| Artwork DB | :negative_squared_cross_mark: Not yet supported |
| DeviceInfo | Partial - Can extract iPod name only |
| Equalizer Presets | :heavy_check_mark: Extracts both the iTunes and actual DSP values |
| On The Go Playlist | :negative_squared_cross_mark: Not yet supported |
| Photo Database | :heavy_check_mark: Can extract all associated metadata of images |
| PhotoFolderAlbums | Partial - only can detect the # of photo albums |
| PhotoFolderPrefs | No support planned. |
| PhotosFolderName | :negative_squared_cross_mark: Not yet supported |
| Play Counts | :heavy_check_mark: |
| Preferences | :heavy_check_mark: |
| WABContactsGroup | :negative_squared_cross_mark: Not yet supported |
| iEKInfo | :negative_squared_cross_mark: Not yet supported |
| iTunesDB | Partial - Songs and Podcasts only. No television or movies |
| iTunesPState | :negative_squared_cross_mark: Not yet supported |
| iTunesPlaylists | :grey_question: [Not documented yet](http://www.ipodlinux.org/ITunesDB/#iTunesPlaylists) |
| iTunesPodcasts | :grey_question: [Not documented yet](http://www.ipodlinux.org/ITunesDB/#iTunesPodcasts) |
| iTunesPrefs | :heavy_check_mark: |
| iTunesSD | :heavy_check_mark: |
| iTunesStats | :negative_squared_cross_mark: Not yet supported |
| iTunesVideoPlaylists | :grey_question: [Not documented yet](http://www.ipodlinux.org/ITunesDB/#iTunesVideoPlaylists) |
| winPrefs | :grey_question: [Not documented yet](http://www.ipodlinux.org/ITunesDB/#winPrefs_File) |

| winPrefs | :grey_question: [Not documented yet](http://www.ipodlinux.org/ITunesDB/#winPrefs_File) |

In examining your iPod's file system you'll find other types of files besides the one listed above. These are:

* [`.plist` files](https://en.wikipedia.org/wiki/Property_list)
- [`.plist` files](https://en.wikipedia.org/wiki/Property_list)

* [`.tone` files](https://github.com/raleighlittles/iPod_tone_file_player)
- [`.tone` files](https://github.com/raleighlittles/iPod_tone_file_player)

* `alarms` files: https://github.com/raleighlittles/iTunesDB-Parser/issues/6
- `alarms` files: https://github.com/raleighlittles/iTunesDB-Parser/issues/6

* `.itdb` files, which are just SQLite 3 databases with a different extension.
- `.itdb` files, which are just SQLite 3 databases with a different extension.

Because iPodLinux isn't maintained anymore, I was worried that the website (and thus the iTunesDB wiki) would be taken down at some point, so I downloaded the documentation.

Expand All @@ -61,15 +60,14 @@ The parser is written in Rust. You can build it by running `cargo build`.

It requires two arguments:

(1) the iTunesDB filename,
(1) the iTunesDB filename,

(2) the type of iTunesDB file.

The 7 possible "type" options are:


| Field | Value |
|---------------|------------------------------------------|
| ------------- | ---------------------------------------- |
| "photo" | Photos Database files, no iThmb files |
| "itunes" | iTunes DB (music and podcasts only) file |
| "itprefs" | iTunes Preferences file |
Expand All @@ -80,9 +78,10 @@ The 7 possible "type" options are:
| "equalizer" | Equalizer Presets file |
| "itunessd" | iTunesSD file |


```bash
$ /target/debug/itunesdb_parser <path-to-itunesdb-file> '<type>'
$ cd iTunesDB-Parser/parser
$ cargo build
$ ./target/debug/itunesdb_parser <path-to-itunesdb-file> '<type>'
```

For iTunesDB, Photos Database, Equalizer files, and Playcounts files, a CSV will be generated with all the relevant information. For example, if you run it on an iTunesDB file, the output CSV will contain the info for all songs and podcasts mentioned in the iTunesDB file.
Expand All @@ -103,24 +102,23 @@ There's 2 extra utilities that may be of use:

<img src="./docs/Spotify_Primary_Logo_RGB_Black.png" alt="Spotify logo" width="100">

* Spotify integration: This creates a Spotify playlist out of the songs that were found on your iPod. See the README in that directory for more.
- Spotify integration: This creates a Spotify playlist out of the songs that were found on your iPod. See the README in that directory for more.

* Song renaming functionality: iPods (generally ?) store the song files on their hard drive, however, the filenames are usually just a generic unique ID. I wrote a Python script that lets you rename the songs to have the song title and artist name instead, using the data that is in the iTunesDB file. See the README in that directory for more information.
- Song renaming functionality: iPods (generally ?) store the song files on their hard drive, however, the filenames are usually just a generic unique ID. I wrote a Python script that lets you rename the songs to have the song title and artist name instead, using the data that is in the iTunesDB file. See the README in that directory for more information.

# Future roadmap

This project is a very early work-in-progress. The next major feature to come is [iThumb file decoding](https://github.com/raleighlittles/iTunesDB-Parser/issues/4)


# Interested in contributing?

If you have any iTunesDB files from the unsupported list and are willing to share, please contact me.

Special thanks to:

* @AZProductions
* @joshkenney
- @AZProductions
- @joshkenney

for providing iTunesDB files!

<a href="https://www.buymeacoffee.com/raleighlittles" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/default-orange.png" alt="Buy Me A Coffee" height="45" width="175"></a>
<a href="https://www.buymeacoffee.com/raleighlittles" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/default-orange.png" alt="Buy Me A Coffee" height="45" width="175"></a>
6 changes: 4 additions & 2 deletions parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
chrono = "0.4.31"
csv = "1.3.0"
chrono = { version = "0.4.31", features = ["serde"] } # Add serde feature
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"

# Languages parsing
isolang = "2.4.0"
isolang = "2.4.0"
9 changes: 7 additions & 2 deletions parser/src/itunesdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
use crate::helpers::helpers;
use crate::helpers::itunesdb_helpers;

pub struct Podcast {
use serde::Serialize;


#[derive(Serialize)]
pub struct Podcast {
pub podcast_title : String,
pub podcast_publisher : String,
pub podcast_genre : String,
Expand All @@ -35,7 +39,8 @@
}
}

pub struct Song {
#[derive(Serialize)]
pub struct Song {
pub file_extension: String,
pub bitrate_kbps: u32,
pub sample_rate_hz: u32,
Expand Down
23 changes: 22 additions & 1 deletion parser/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ mod equalizer;
use std::io::Read;

fn main() {
// add a check for the number of arguments
let args: Vec<String> = std::env::args().collect();

if args.len() < 3 {
panic!("Usage: {} <iTunes DB filename> <type> [format=csv|json]", args[0]);
}

let itunesdb_filename: String = std::env::args()
.nth(1)
.expect("Missing first parameter: iTunes DB filename");
Expand All @@ -61,6 +68,20 @@ fn main() {
);
}

// Default to "csv" if no format specified
let output_format = if args.len() > 3 {
match args[3].to_lowercase().as_str() {
"json" => "json",
"csv" => "csv",
_ => {
eprintln!("Invalid format specified. Using default 'csv'");
"csv"
}
}
} else {
"csv"
};

let mut itunesdb_file_as_bytes = Vec::new();

// https://stackoverflow.com/questions/47660946/why-does-a-file-need-to-be-mutable-to-call-readread-to-string
Expand All @@ -85,7 +106,7 @@ fn main() {
photos_csv_writer,
);
} else if itunesdb_file_type == "itunes" {
parsers::itunesdb_parser::parse_itunesdb_file(itunesdb_file_as_bytes);
parsers::itunesdb_parser::parse_itunesdb_file(itunesdb_file_as_bytes, output_format.to_string());
} else if itunesdb_file_type == "itprefs" {
parsers::preferences_parser::parse_itunes_prefs_file(itunesdb_file_as_bytes);
} else if itunesdb_file_type == "playcounts" {
Expand Down
Loading

0 comments on commit e143cf8

Please sign in to comment.