Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- char name[2048];
- char overview[8192];
- void read_episodes(json_reader_base& reader, Stream& output) {
- int root_array_depth = 0;
- // episodes opens with an array
- if(reader.read() && reader.node_type()==json_node_type::array) {
- root_array_depth = reader.depth();
- while(true) {
- // if we're at the end of the array, break
- if(reader.depth()==root_array_depth &&
- reader.node_type()==json_node_type::end_array) {
- break;
- }
- // read each "episode object"
- if(reader.read()&&
- reader.node_type()==json_node_type::object) {
- int episode_object_depth = reader.depth();
- int season_number = -1;
- int episode_number = -1;
- while(reader.read() &&
- reader.depth()>=episode_object_depth) {
- // make sure we don't read any nested objects
- // under this one
- if(reader.depth()==episode_object_depth &&
- reader.node_type()==json_node_type::field) {
- if(0==strcmp("episode_number",reader.value()) &&
- reader.read() &&
- reader.node_type()==json_node_type::value) {
- episode_number = reader.value_int();
- }
- if(0==strcmp("season_number",reader.value()) &&
- reader.read() &&
- reader.node_type()==json_node_type::value) {
- season_number = reader.value_int();
- }
- // gather the name
- if(0==strcmp("name",reader.value())) {
- name[0]=0;
- while(reader.read() && reader.is_value()) {
- strcat(name,reader.value());
- }
- }
- // gather the overview
- if(0==strcmp("overview",reader.value())) {
- overview[0]=0;
- while(reader.read() && reader.is_value()) {
- strcat(overview,reader.value());
- }
- }
- }
- }
- if(season_number>-1 && episode_number>-1 && name[0]) {
- output.printf("S%02dE%02d %s\r\n",
- season_number,
- episode_number,
- name);
- if(overview[0]) {
- output.printf("\t%s\r\n",overview);
- }
- output.println("");
- }
- }
- }
- }
- }
- void read_series(json_reader_base& reader, Stream& output) {
- while(reader.read()) {
- // find "episodes"
- switch(reader.node_type()) {
- case json_node_type::field:
- if(0==strcmp("episodes",reader.value())) {
- read_episodes(reader, output);
- }
- break;
- default:
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement