update stream count by 1 seem impossible

kissntel
kissntel
@popradio-stockholm
11 months ago
12 posts
I have a Shoutcast live stream and wants to update the audio_file_stream_count with 1 everytime a song is played.
I can get the audio_title and audio_artist out of the stream but tried so hard to update the
JrAudio database. I manually upload files with audio_title and audio_artist and_item_id a s o.
When playing those song on demand the it adds a play in the count, but not when in live stream.
The code that should do the job is this:
// Get all audio files that are part of this album
    $_sp = array(
    'search'                       => array(
      
	 
	   "audio_title = {$_post['song']}",
	 
     "audio_artist = {$_post['profile_name']}",

	     ),
    'return_keys'                  => array('_item_id'),
    'exclude_jrUser_keys'          => true,
    'exclude_jrProfile_quota_keys' => true,
    'order_by'                     => array('_created' => 'numerical_asc'),
    'limit'                        => 1
);

 $_rt = jrCore_db_search_items('jrAudio', $_sp);

    if (isset($_rt) && is_array($_rt)) {
   
 jrCore_db_increment_key('jrAudio',$_rt['_items'][0]['item_id'], 'audio_file_stream_count',1,true);
        return jrCore_json_response(array('success' => 1));
 }
   // return jrCore_json_response(array('error' => 'update failed'));
}
the code passed by without any error messages but nothing changes i the database?
What Am I missing?
Please, thank you. // Jacob
updated by @popradio-stockholm: 09/27/23 02:49:12AM
brian
@brian
11 months ago
10,139 posts
Hi Jacob - looks like you just have a small typo - change this:

jrCore_db_increment_key('jrAudio',$_rt['_items'][0]['item_id'], 'audio_file_stream_count',1,true);

To this:
jrCore_db_increment_key('jrAudio',$_rt['_items'][0]['_item_id'], 'audio_file_stream_count',1,true);

note the addition of the underscore to "item_id" so it becomes "_item_id" - the item ID is an internal key so always starts with an underscore.

Let me know if that works for you.

Thanks!


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
kissntel
kissntel
@popradio-stockholm
11 months ago
12 posts
Hi, oh, that was the original code and I forgot to change back. but somehow that doesn't work either.
I got a feeling it wont connect properly, remembered I saw some error said " cant find the column audio_file_stream_count. as I changed around.
I really dont now how to debug and see what is going on.
I noticed the Module jrShoutcastPlayer where the code is in is not registered as other modules are. Status is just an ? instead of a green spot. May that cause som issue to not work along with the Audio module?? Also I cant run system check since I bought this ShoutCast module. I could really be great if it works..
Thanks // Jacob
kissntel
kissntel
@popradio-stockholm
11 months ago
12 posts
Here are the modules that wont registered , jrShoutcastPlayer and jrAudioImport.
SHoutcastplayer causes coredump scenes now and then related to id3v2 and ffmpeg.
After my isp turn off coredump I can suddenly do a systemcheck and find out there is error according to this...
Try to turn off everything with conversions and id3 tags and hope that stops the coredump.
However the main issue from above remains.
zip
jrShoutcastPlayer.zip  •  830KB


updated by @popradio-stockholm: 06/17/23 07:20:41AM
brian
@brian
11 months ago
10,139 posts
OK thanks for attaching the module. So there's a couple things in the view I'll go over:

jrCore_validate_location_url();

You don't want this at the top of your view function UNLESS the view is being called by an XHR/Ajax request that has had the URL prepared with jrCore_set_csrf_cookie(). Your JS functions are not using that function so you do not want that at the top of your view function.

Here is your view function working for me:

/**
 * @param $_post
 * @param $_user
 * @param $_conf
 * @return bool|void
 */
function view_jrShoutcastPlayer_update($_post, $_user, $_conf)
{ if (!isset($_post['song']) || strlen($_post['song']) == 0) { return jrCore_json_response(array('error' => 'invalid song title')); } if (!isset($_post['profile_name'])) { return jrCore_json_response(array('error' => 'invalid profile name')); } // Get all audio files that are part of this album $_sp = array( 'search' => array( "audio_title = {$_post['song']}", "profile_name = {$_post['profile_name']}", "audio_artist = {$_post['profile_name']}" // "_item_id = 3" - use by brian for testing ), 'return_item_id_only' => true, 'exclude_jrUser_keys' => true, 'exclude_jrProfile_quota_keys' => true, 'order_by' => false, 'limit' => 1 ); $_rt = jrCore_db_search_items('jrAudio', $_sp); if (isset($_rt) && is_array($_rt)) { jrCore_db_increment_key('jrAudio', reset($_rt), 'audio_file_stream_count', 1, true); return jrCore_json_response(array('success' => 1)); } return jrCore_json_response(array('error' => 'update failed')); }

Note a couple changes I made:

'return_item_id_only'          => true,

In your case you are only interested in the _item_id - by using the "return_item_id_only" $_rt will just be a simple array with the matching ID if found - i.e.

0 => 3

This is much more efficient since it saves a second query that gets the actual keys for the item.

I also set "order_by" to FALSE - there's no reason to request an order when you're getting one result.

Attached is the update - let me know how that works for you.
zip
jrShoutcastPlayer.zip  •  841KB

20230617-071708.jpg
20230617-071708.jpg  •  567KB




--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net

updated by @brian: 06/17/23 07:26:24AM
kissntel
kissntel
@popradio-stockholm
11 months ago
12 posts
Thank you. I been testing through the night but can't se any counts increase in the audio_file_stream_counts when listening to live stream. I believe (and it´s my wish) it will shows in the charts display.
It worked for you (_item_id =3) , how did you actually test that?
I still got the feeling that Shoutcast won't connect to the audio module?
Cant be far away now from working as it should.
Another thing I noticed. I cant upload audiofiles on a profile when jrShoutcastplayer module is active.
But available when I turn it off?? That is strange...
Thanks again for your help. // J
kissntel
kissntel
@popradio-stockholm
11 months ago
12 posts
The same with SiteBuilder. Doesn t work properly while Shoutcast module is active??
Can not figure out how they are connected...
brian
@brian
11 months ago
10,139 posts
If Site Builder is not working I suspect there are likely some Javascript errors on your site - turn on the Developer Tools in your browser and view the site - look in the "Console" tab for any Javascript errors.


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
kissntel
kissntel
@popradio-stockholm
10 months ago
12 posts
here are two things showing on almost every site on my jamroom..
1.DevTools failed to load source map: Could not load content for https://popradio.se/data/cache/jrMediaPro/bootstrap.min.css.map: Unexpected token '<', "


<!-- BEGIN"... is not valid JSON

2. (index):5265 Uncaught ReferenceError: gdprAllowPersonalizedAds is not defined
at (index):5265:1
this note changes depend on what site I am at.

I havent change any javascript code. The problem with SiteBuilder and uploading files started when Shoutcastplayer module was installed. The problems most likely are within this module.
Still no counts shows from the livestream.
can i debug somehow to find out if it catch the _item_id correct?
michael
@michael
10 months ago
7,695 posts
looks like you have the "Template Names In Source" turned on.
site.jpg
site.jpg  •  101KB

kissntel
kissntel
@popradio-stockholm
10 months ago
12 posts
@michael
Thank you for input. I cant tell if the "template name in source" effects modules to work or not??? However, it is off now,
Your attached jpg telling that audio_file_stream_count is working correctly?
Well, in the jr_jraudio_item_key table, the audio_file_stream_count value is not increasing or changing when listen to a song through the shoutcast stream as well as not showing in the charts...
What do you actually mean by saying it works correct?
// Jacob
michael
@michael
10 months ago
7,695 posts
oh yeah, if you have that turned on it will most likely break many things. it inject the name of the template into the source code so you can locate where a section of code is. It does not care if that breaks the code or not.

The way it does it is with HTML comments which look like this:
<!-- BEGIN template_name.tpl -->
That will definitely break a json file.
brian
@brian
10 months ago
10,139 posts
Yep - like Michael has pointed out - make sure that is disabled. That's really only useful when customizing or designing a skin.


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
kissntel
kissntel
@popradio-stockholm
10 months ago
12 posts
OK, thanks for info although I ve never changed those settings.
All my problems remains, and happens when Shoutcastplayer module is activated.
When Shoutcastplayer is disabled then SiteBuilder, audio upload and more works as it should.
No difference with Template Names In Source on or off.?
I believe the Shoutcast module not connects with database at all using jrcore_db functions.??
I ask again, is there a way to debug, log or anything that shows what is going on, to see if the code catch the _item_id?
1. In feb 2022 I asked Jamroom if the can help med building SHoutcast stream module.
2.Answer was yes
3. I Payed
4. After many month (with many reminders from me) I got a module that doesnt work, as well as effect other modules not work properly either.
5. The developer disapperad and stop answer my mails...
6. Over a year now I ve been trying to have the code connect to database, using AI and all sort of inputs..
I cant understand how it could be so hard to update an item in a database.
brian
@brian
10 months ago
10,139 posts
Sorry you're still having a problem with this - I did test the module you sent me and the VIEW works no problem - i.e. if you call:

https://yoursite.com/sc_player/update

and you've set the _item_id in the view - i.e.

jrCore_db_increment_key('jrAudio', 3, 'audio_file_stream_count', 1, true);

You will see that it works. I think the problem you are having is that this update view is not being called.

What function calls the "update" view to trigger the stream count?


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
kissntel
kissntel
@popradio-stockholm
10 months ago
12 posts
hello, thank you for quick response.
When calling https://popradio.se/sc_player/update after changed the _item_id to 3
results in "The Page Not Exist".
popradio.se/radio/update results in the normal radiosite where I listens to the stream.
Cant see nowhere that it works. Have no idea how to show things in a view mode?

--What function calls the "update" view to trigger the stream count?--
Am I suppused to know that? Maybe you mean the AdvancedChart??
I actually dont understand what you mean.
// Jacob
michael
@michael
10 months ago
7,695 posts
Need to get some feedback from Nate on here, he's the one that understands whats supposed to happen. @nate
brian
@brian
10 months ago
10,139 posts
kissntel:
I actually dont understand what you mean.

What's the URL to a page on your site where it SHOULD be working? Maybe we can get an idea of the issue form the JS console.


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
kissntel
kissntel
@popradio-stockholm
10 months ago
12 posts
Hello,
as now I want it to work from the Home (index) (url= https://popradio.se) page as well as from the Radio ( https://popradio.se/radio) page which now shows with this link :
{jrCore_include template="player.tpl" module="jrShoutcastPlayer"}
I believe this link above is the right place for the player to work and I can put it wherever I want it on the site.
The stream itself comes from another server https://popradiostream.se. No port is needed to tell here.
This is the Shoutcast broadcast server.
The music plays, the albumcover shows, we got the title and artist from the stream but cant put this in the database as with the stream count. The main idea was to add (create) the artist and title in the database if not exist. The actual mp3 file I will add at a later point if needed (with JrAudioImport Module or manually).
Thank you
michael
@michael
10 months ago
7,695 posts
The stand alone 'Pop Up' player is on this url:
https://popradio.se/ShoutcastPlayer/popup

There's a link to it from the /radio page.

From within that page there is a call to /update :
https://popradio.se/ShoutcastPlayer/update?audio_title=The%20World%20s%20Greatest&profile_name=R.%20Kelly&_=1687840891592

That is returning
error: "Invalid Song Title".

That seems like it could be why the incrementing is not happening perhaps.

There's also a lot of GET requests to itunes going on which seems unusual.

--edit--
The GET requests are to itunes to get the album covers.
1.jpg
1.jpg  •  20KB

2.jpg
2.jpg  •  90KB


updated by @michael: 06/26/23 09:52:33PM
kissntel
kissntel
@popradio-stockholm
10 months ago
12 posts
Thank you,
I think the Shoutcastplayer is the main streamingsite, popupplayer includes the same but in different design. I wonders if that "invalid song title" shows on every song?
I noticed that all spaces (%20) is not present in the attached images but in the link:
https://popradio.se/ShoutcastPlayer/update?audio_title=The%20World%20s%20Greatest&profile_name=R.%20Kelly&_=1687840891592 .... became "TheWorldGreatest... " R.%20Kelly became RKelly. What happens with the dot?

Maybe that is correct but somehow strange...
Call Itunes for the Covers, but seems like it look only for artist. Most of the times it shows like random song cover but from correct artist.
MyBroadcast program have an output URL
https://popradiostream.se/admin.cgi?pass=xxxxxxxx&sid=1&mode=updinfo&dj=%u&artist=%a&songtitle=%t&urlcover=%U1&temp=%p&currentlisteners=%l
where %U1 is the url link to the correct album cover.
I will somehow try to implement this url in shoutcastplayer. Perhaps can use the artist and title from this as well instead of catching from the stream??
// Jacob
updated by @popradio-stockholm: 06/27/23 02:13:38AM
michael
@michael
10 months ago
7,695 posts
The URL that should be being used in the /update currently is:
/update?audio_title=
but that should be
/update?song=

--edit--
Alternatively if you don't know what is causing that url to be like that then changing the _update() function to allow ?audio_title works too, use this function:
PREVIOUSLY
function view_jrShoutcastPlayer_update($_post, $_user, $_conf) {
    jrCore_validate_location_url();
    if (!isset($_post['song']) || strlen($_post['song']) == 0) {
        return jrCore_json_response(array('error' => 'invalid song title'));
    }
    if (!isset($_post['profile_name']) || strlen($_post['song']) == 0) {
        return jrCore_json_response(array('error' => 'invalid profile name'));
    }
    // Get all audio files that are part of this album
    $_sp = array(
        'search'                       => array(
            "audio_title = {$_post['song']}",
           "profile_name = {$_post['profile_name']}",
		 // jake put in kod
         "audio_artist = {$_post['profile_name']}",
		  // SLUT JAKE


        ),
        'return_keys'                  => array('_item_id'),
        'exclude_jrUser_keys'          => true,
        'exclude_jrProfile_quota_keys' => true,
        'order_by'                     => array('_created' => 'numerical_asc'),
        'limit'                        => 1
    );
    $_rt = jrCore_db_search_items('jrAudio', $_sp);
    if (isset($_rt) && is_array($_rt)) {
        jrCore_db_increment_key('jrAudio',$_rt['_items'][0]['_item_id'],'audio_file_stream_count',1,true);
        return jrCore_json_response(array('success' => 1));
    }
    return jrCore_json_response(array('error' => 'update failed'));
}
CHANGE IT TO:
function view_jrShoutcastPlayer_update($_post, $_user, $_conf)
{ jrCore_validate_location_url(); $title = ''; if (!empty($_post['song'])) { $title = $_post['song']; } elseif (!empty($_post['audio_title'])) { $title = $_post['audio_title']; } if (!empty($title)) { return jrCore_json_response(array('error' => 'invalid song title')); } if (!isset($_post['profile_name'])) { return jrCore_json_response(array('error' => 'invalid profile name')); } // Get all audio files that are part of this album $_sp = array( 'search' => array( "audio_title = {$title}", "profile_name = {$_post['profile_name']}", // jake put in kod "audio_artist = {$_post['profile_name']}", // SLUT JAKE ), 'return_keys' => array('_item_id'), 'exclude_jrUser_keys' => true, 'exclude_jrProfile_quota_keys' => true, 'order_by' => array('_created' => 'numerical_asc'), 'limit' => 1 ); $_rt = jrCore_db_search_items('jrAudio', $_sp); if (isset($_rt) && is_array($_rt)) { jrCore_db_increment_key('jrAudio', $_rt['_items'][0]['_item_id'], 'audio_file_stream_count', 1, true); return jrCore_json_response(array('success' => 1)); } return jrCore_json_response(array('error' => 'update failed')); }

updated by @michael: 06/27/23 05:42:06PM
michael
@michael
10 months ago
7,695 posts
What Im seeing is that whenever the shoutcast stream changes from one song to another many thing happen, one of which is the /update url is called. That just happened and this URL was generated:
https://popradio.se/ShoutcastPlayer/update?audio_title=Trap%20Queen&profile_name=Fetty%20Wap&_=1687913313586

Even changing that to the correct update variable the update still fails:
https://popradio.se/ShoutcastPlayer/update?song=Trap%20Queen&profile_name=Fetty%20Wap&_=1687913313586

The reason is that the search for that song is not found or the profile is not found. Do you have a profile on your site for "Fetty Wap"? and does that profile have a song in their audio list called "Trap Queen".

It could be formatting, and probably would be best to use cleaner variables to search on like the audio_title_url if that exists and the profile_url if that exists.
michael
@michael
10 months ago
7,695 posts
If you can get that search "// Get all audio files that are part of this album" lined up with the song that needs incrementing then incrementing will happen. Right now your search is not finding the song to increment.
kissntel
kissntel
@popradio-stockholm
10 months ago
12 posts
Hello Michael,
getting correct song and artist is what im been trying to do for such long time.
Brian change the _update function to:
------
function view_jrShoutcastPlayer_update($_post, $_user, $_conf)
{
if (!isset($_post['song']) || strlen($_post['song']) == 0) {
return jrCore_json_response(array('error' => 'invalid song title'));
}
if (!isset($_post['profile_name'])) {
return jrCore_json_response(array('error' => 'invalid profile name'));
}
// Get all audio files that are part of this album
$_sp = array(
'search' => array(

"audio_title = {$_post['song']}",
"profile_name = {$_post['profile_name']}",

// "audio_artist = {$_post['profile_name']}"
// "_item_id = 3" - use by brian for testing

),
'return_item_id_only' => true,
'exclude_jrUser_keys' => true,
'exclude_jrProfile_quota_keys' => true,
'order_by' => false,
'limit' => 1
);
$_rt = jrCore_db_search_items('jrAudio', $_sp);
if (isset($_rt) && is_array($_rt)) {
jrCore_db_increment_key('jrAudio', reset($_rt), 'audio_file_stream_count', 1, true);

return jrCore_json_response(array('success' => 1));
}
return jrCore_json_response(array('error' => 'update failed'));
}
------
I noticed the reset($_rt) in the increment line... ???
However, that didn't work so I will try the changes you suggest.
The column that show the artist in the jr_jraudio_item_key table are
audio_artist i.e Billy Joel
audio_file_artist i.e Billy Joel
.... shows the song in the table are
audio_file_title i e Uptown girl
audio_title i.e Uptown girl

audio_title_url shows Uptown-girl
profile_url is not present in that table.

I ´ll inform you when tested the code...
Thank you // Jacob
michael
@michael
10 months ago
7,695 posts
send the admin login deteails to support at jamroom dot net and I'll login and see if there's a cleaner data value we can use. (tomorrow, late here.)

Tags