Skip to content

Commit

Permalink
Broadcastify uploader fixes - 5.0 (#957)
Browse files Browse the repository at this point in the history
* upload call_info.call_json

* remove filename upload

* use log_header()
  • Loading branch information
taclane authored May 22, 2024
1 parent 84aea41 commit 172b49a
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions plugins/broadcastify_uploader/broadcastify_uploader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,11 @@ class Broadcastify_Uploader : public Plugin_Api {
mime = curl_mime_init(curl);

part = curl_mime_addpart(mime);
curl_mime_filedata(part, call_info.status_filename);
curl_mime_data(part, call_info.call_json.dump().c_str(), CURL_ZERO_TERMINATED);
curl_mime_filename(part, "call_meta.json");
curl_mime_type(part, "application/json");
curl_mime_name(part, "metadata");

part = curl_mime_addpart(mime);
curl_mime_data(part, call_info.converted, CURL_ZERO_TERMINATED);
curl_mime_name(part, "filename");

part = curl_mime_addpart(mime);
curl_mime_data(part, std::to_string(call_info.length).c_str(), CURL_ZERO_TERMINATED);
curl_mime_name(part, "callDuration");
Expand Down Expand Up @@ -261,45 +258,48 @@ class Broadcastify_Uploader : public Plugin_Api {
long response_code;
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code);

std::string loghdr = log_header(call_info.short_name,call_info.call_num,call_info.talkgroup_display,call_info.freq);

if (res != CURLM_OK || response_code != 200) {
BOOST_LOG_TRIVIAL(error) << "[" << call_info.short_name << "]\t\033[0;34m" << call_info.call_num << "C\033[0m\tTG: " << call_info.talkgroup_display << "\tFreq: " << format_freq(call_info.freq) << "\tBroadcastify Metadata Upload Error: " << response_buffer;
BOOST_LOG_TRIVIAL(error) << loghdr << "Broadcastify Metadata Upload Error: " << response_buffer;
return 1;
}

std::size_t spacepos = response_buffer.find(' ');
if (spacepos < 1) {
BOOST_LOG_TRIVIAL(error) << "[" << call_info.short_name << "]\t\033[0;34m" << call_info.call_num << "C\033[0m\tTG: " << call_info.talkgroup_display << "\tFreq: " << format_freq(call_info.freq) << "\tBroadcastify Metadata Upload Error: " << response_buffer;
BOOST_LOG_TRIVIAL(error) << loghdr << response_buffer;
return 1;
}

std::string code = response_buffer.substr(0, spacepos);
std::string message = response_buffer.substr(spacepos + 1);

if (code == "1" && (message.rfind("SKIPPED", 0) == 0)) {
BOOST_LOG_TRIVIAL(info) << "[" << call_info.short_name << "]\t\033[0;34m" << call_info.call_num << "C\033[0m\tTG: " << call_info.talkgroup_display << "\tFreq: " << format_freq(call_info.freq) << "\tBroadcastify Upload Skipped: " << message;
BOOST_LOG_TRIVIAL(info) << loghdr << "Broadcastify Upload Skipped: " << message;
return 0;
}

if (code == "1" && (message.rfind("REJECTED", 0) == 0)) {
BOOST_LOG_TRIVIAL(error) << "[" << call_info.short_name << "]\t\033[0;34m" << call_info.call_num << "C\033[0m\tTG: " << call_info.talkgroup_display << "\tFreq: " << format_freq(call_info.freq) << "\tBroadcastify Upload REJECTED: " << message;
BOOST_LOG_TRIVIAL(error) << loghdr << "Broadcastify Upload REJECTED: " << message;
return 0;
}

if (code != "0") {
BOOST_LOG_TRIVIAL(error) << "[" << call_info.short_name << "]\t\033[0;34m" << call_info.call_num << "C\033[0m\tTG: " << call_info.talkgroup_display << "\tFreq: " << format_freq(call_info.freq) << "\tBroadcastify Metadata Upload Error: " << message;
BOOST_LOG_TRIVIAL(error) << loghdr << "Broadcastify Metadata Upload Error: " << message;
return 1;
}

CURLcode audio_error = this->upload_audio_file(call_info.converted, message);

if (audio_error) {
BOOST_LOG_TRIVIAL(error) << "[" << call_info.short_name << "]\t\033[0;34m" << call_info.call_num << "C\033[0m\tTG: " << call_info.talkgroup_display << "\tFreq: " << format_freq(call_info.freq) << "\tBroadcastify Audio Upload Error: " << curl_easy_strerror(audio_error);
BOOST_LOG_TRIVIAL(error) << loghdr << "Broadcastify Audio Upload Error: " << curl_easy_strerror(audio_error);
return 1;
}

struct stat file_info;
stat(call_info.converted, &file_info);

BOOST_LOG_TRIVIAL(info) << "[" << call_info.short_name << "]\t\033[0;34m" << call_info.call_num << "C\033[0m\tTG: " << call_info.talkgroup_display << "\tFreq: " << format_freq(call_info.freq) << "\tBroadcastify Upload Success - file size: " << file_info.st_size;
BOOST_LOG_TRIVIAL(info) << loghdr << "Broadcastify Upload Success - file size: " << file_info.st_size;
return 0;
} else {
return 1;
Expand Down

0 comments on commit 172b49a

Please sign in to comment.