Ray J Dion ray
Aloha all the techies here.

I have decided that I need to learn Python. Don't ask me why, I think mostly because I want to play with both the language and the B2. While Python is up to version 3, the version on the B2 is 2.7. I don't know if the B3 has it or what version it is. Does not matter as I can't test it so leave that project to someone else.

I am fully aware that Andy has written a program to do a number of these things. My idea is a bit different only because I want to do it on the B2 with a web page front end. A learning experience for me. I welcome help as I go along.

Where do I begin? Well there has always been much discussion about the b2db file and the order things play in. We have Andy's program that can fix it up and a lot more. I just want to start learning. So I look at the file and I see that for certain albums, the b2db file actually lists them out of order. The first album on my list is an example:
Version 3
1064 Albums 57 mirror
10cc/Live in Concert, Volume 1
8 tracks
01 The Wall Street Shuffle.flac
02 I’m Mandy Fly Me.flac
03 Good Morning Judge.flac
05 The Stars Didn't Show.flac
06 Dreadlock Holiday.flac
07 Shine a Light in the Dark.flac
08 Feel the Benefit.flac
04 Welcome to Paradise.flac

What if as my first task I work to fix that? I already see issues with UFT-8 characters. Python 2.7 does not handle it as well as Python 3. I am also seeing issues with how Python prints out some strings. In most cases strings are delimited by single quotes. But in those cases where something is out of order, it almost always has one of the strings delimited with double quotes. A lot of these seem to have apostrophes in one of the track titles where I see UFT-8 encoding.

My mind races with other things that would be useful.
  • Actually do the disk scan function - try the command ls -1R /media/hdd1/music/  A challenge! (that is the number 1)
  • Verify playlists entries all exist in the b2db file.
  • Use some kind of indicators (xml I am thinking) to help auto create genre playlists. This would be hard but I am up for a challenge. More complex would be to create those xml files by using ffmpeg to read tags!
  • Create a routine that will collect data to help debug what is going on such as collect the status data. This would mean stealing code from within original.html. I am not an expert on JSON or any other parts of the webpage programming. I can do simple HTML though! I even taught a course on it years ago as a precursor to Dreamweaver.
So is there any interest in this? At some point I will be asking for copies of folks b2db files to test whatever I come up with. I hope I get some support. 

At some point this would need to be installed. If someone could clue me in as to where to look to create some kind of .gz file that could be automated for the non-technical users, I would be appreciative.

One trick I have already learned. Do you want a copy of your b2db file? Try:

http://<ipaddress>/hdd1/b2db

The file at least in Edge will be placed in your downloads folder!  It also works for b2settings and playlists!

Right now I am in the process of reading the file and outputting it in the same order. After I can do that, sorting will be learned.

Edit: I should have stated. Completely available for reuse by anyone, including Brennan! If I provide it, it is of course use at your own risk. I will make it as carefully as possible.

Ray
B2 is playing Man With A Mission by Procol Harum
Ray J Dion ray
Guess there is not a lot of interest. I am going to continue just to learn and understand. I see no reason we can't try to fulfill someone wish if possible. 

I'll still comment here when I find something interesting. I think I did tonight.

I am suspecting that when titles to tracks are decided by MusicBrainz certain characters get UFT-8 encoded. In particular the apostrophe. I notice in the b2db file there are places where it is encoded in three bytes. If I go in and manually change the title of the track to retype the apostrophe, do a Scan Disk, then download the b2db file again, the apostrophe is in ascii. The order of files also changes in that the file renamed is always listed last among the tracks.

Not much progress made today except in learning about sorting by list items and trying to do three level sorts (tracks/album/artist). The documentation is geared towards Python 3 and we have Python 2.7.

Ray
B2 is playing Wreck of the Edmond Fitzgerald by Gordon Lightfoot
Reply 0 0
MarkF
@ray
Of course I'm interested! Sorry for not speaking up sooner.
I'm just dealing with a plumbing problem today... 
Reply 0 0
JFBUK (John)
Hi Ray,
I am definitely interested too😇
Reply 0 0
Fred
Interested "hover fly" here too

Fred
Reply 0 0
Ray J Dion ray
Then I'll try not to take the silence in a bad way. Thanks for the feedback.

Ray
B2 is playing Sound track from South Pacific (also known as South Pathetic when it is the show you are putting on). Happy Talk right now.
Reply 0 0
Ray J Dion ray
Today was interesting. Decided to approach it a little differently. Can I do most of the work on the Linux command line? It eliminates some of the UTF kind of issues. For those of you wondering how I find all this time. I don't watch TV much and I try to challenge myself by avoiding watching videos on the computer too.
The ls (list) command was tough, it does most of the sorting work but case matters. The recursive (-R) was useful but it pulls all files so coverart.jpg, toc, and diskid were all in the printout. If people have other types of files it gets pretty random. I use an error.txt file to log errors that I will eventually fix. At least that is what I tell myself.
I tried the find command and similarly saw some good things and bad. The worst was no sorting, so it was just as bad as using b2db.
I gave up for a while, went back to Python.
I had a second go at it. Came up with a pretty impressive command. If you use it from the music directory you can get all of the files SORTED! It however generates a huge text file. I will say the format of that file may make my python skill sufficient to create a b2db file.

find -mindepth 3 -maxdepth 3 |egrep '.flac|.mp3' | sort -f >outlist

It creates a file called outlist that can be downloaded to my computer with a web browser (http://<ipaddress>/hdd1/music/outlist). No extension because if I add .txt, the browser treats it as a page. Mine is about 1 Megabyte.
The only problems I see at point:
  • I have to add all of the other music file extensions that the B2 uses. I suppose I could add WAV now but I don't have any. If you have the approved extensions, pls let me know.
  • It does not count mirror files. I could do something similar by using min and max at 4 to count those. easy peasy.
  • It does not report empty albums. I have an artist called testartist with an album called testalbum. It has a coverart.jpg file. No tracks. The artist, album and coverart show up in the WebUI. I have not checked if it is included in artist and album counts for the current b2db. I am trying to make notes of where differences of counts will occur.

The absolutely biggest advantage of this is that I can process the file one line at a time to the end of the file. The only headache I see is that there is a line in the b2db that says XX tracks after the artist/album line. I have to go back and plug in that number. 

Ray
B2 is playing You by The Carpenters.
Reply 0 0
Ray J Dion ray
Spent the afternoon today working on the python. It works. I was able to recreate a b2db file. Obviously I can't review 14,000 lines and they are different enough that diff and grep simply don't do enough. I was able to do a compare with Notepad++ on windows. All of my development has been on windows as the tools are better.  The error I discovered is that I had 8 empty album folders though most had coverart. All of the errors seem to be renaming errors. Only one of them did I have to rip the CD again. So WAV files worked as well. I think that makes the first hurdle a success. 

The process is that a linux script will do a find on the music directory and list all tracks sorted alphabetically in a big text file. The python program will then take that that file and prune it into a valid b2db format. This takes less than 30 seconds or so to run end to end.

An issue with this will be we can't look at the stats in the B2 menu structure anymore. I had not thought about this. All of the management of the b2db file would have to be done externally. I am going to have to run my own stats process. I think it is already in the script or easily added. Just did some simple grep commands, maybe not so simple. 

I stared at web code today. I don't understand it. I need to search for simple complete examples, hit this button and the script runs. Then somehow provide that output on the webpage. If I can do it for one script, then I could do other things with more buttons such as run the usb scripts. It will be even better if we can somehow download a file that others could post with information needed to help debug their issues. 

Ray
B2 is playing Circle by Harry Chapin
Reply 0 0
MarkF

An issue with this will be we can't look at the stats in the B2 menu structure anymore. I had not thought about this. All of the management of the b2db file would have to be done externally. I am going to have to run my own stats process. I think it is already in the script or easily added. Just did some simple grep commands, maybe not so simple. 


Simple question, possibly long answer: why can't you look at stats using the B2 menu structure?
If all you're doing is replacing the b2db file with one of your own, and it is (a) the same length as Brennan's, and (b) lists all the same artists, albums, tracks, and track counts, why would the Brennan stats not be valid and unchanged?

I ask this because when I use AndyC's external sorting program and put the sorted b2db file back, the stats are still the same -- as you would expect -- so no problems occur.

If the stats aren't calculated on the fly when the b2db file is read (at boot?) but are stored somewhere (where?) after running Scan Disk, why not run Scan Disk first, then replace the b2db with your version?
Reply 0 0
AJ
Ray,

I am currently suffering with flu and my brain is a bit muddled, however if I have understood you correctly I think that you can possibly get what you want using the following URL

http://<Brennans-IP-Address>/b2gci.fcgi?getWebInfo

which returns the following JSON

{
version: "Version BB1 Jun 15 2022 14:12:51",
tracks: "4424",
albums: "345",
artists: "90",
USBTracks: "0",
USBAlbums: "0",
USBArtists: "0",
wavs: "2",
flacs: "4",
mp3s: "4418",
aacs: "0",
capacity: "29.30",
videos: "10",
used: "17.33",
trackSpaceUsed: "169738",
albumSpaceUsed: "13052",
artistSpaceUsed: "1416",
trackSpace: "7000000",
albumSpace: "900000",
artistSpace: "200000",
maxTracks: "170000",
maxAlbums: "15000",
maxArtists: "6000"
}


The WebUI accesses the Brennan using this url with different arguments, which produce a response as JSON.  So basically anything that you do with the WebUI can be done with this mechanism.  Contrary to popular belief  there are no webpages generated on the Brennan, it is all JavaScript running in the browser using this mechanism to access the relevant data.

The attached python file is some test code that demonstrate a few things using this interface.

Hope this is of some use.

Andrew.
 
Reply 0 0
Ray J Dion ray
Easy answer first.
Thanks for that Andrew. I'll be looking it over. I picked up that everthing in the /var/www directory is pretty much JavaScript which is still very foreign to me. I've done copy and pasting in web pages to make calls to routines, but never written any from scratch. I was thinking yesterday how could I create a smaller web page that only included the top left corner of original.html that I could pop out and always see what is playing. I suppose I could use the the mobile front page to do it.

Ok that answer was longer than I expected. :-)

Why can't you use the stats? I was a little too broad. Each time the b2 collects the stats it is based on doing a Scan Disk. The numbers are updated if you use the B2 to rip and add, or the web pages to delete things. Stats are updated in real time.  To update both stats and b2db, you must run both Scan Disk and my program.
I could add music via NAS and then run my program to update the b2db. The stats however would be wrong until you run Scan Disk. The rest of the machine however would work just fine where all of the new music is accessible. That means I could make the numbers report incorrectly. If I always used my program and NAS, that could be very significant amount of errors. If I found a way to update the stats as stored/managed on the B2, then the numbers would be real. Consider my statement as being too conservative, I will be very direct when I think I have an issue. This particular one will provide incorrect data to work from. 

For clarity. When I first ran the program the number of lines was different. I had 8 no track albums. I did not check how the B2 was counting them in the artist and album counts. My program ignored and in fact did not include them in my version of the b2db. They are in the Brennan version of the b2db. You can click on them in the webUI and see that there are no tracks and I could see the coverart in the bottom right corner. So my program matches lines ONLY if there are tracks in every album. Should that be an error or is it a better way to do it? 

Instead of calling it my program, can anyone think of a spiffy name for it? I want to do some cleanup (more approriate file names) and then I will use some name to create a distribution. It will be manual for now and intended to have folks test and/or provide feedback. I had thought I would source it with b2db data. If I had done that, then I could test myself and ask for copies of your b2db files. I however like the fact that I can use the actual files and create the file efficiently.

My testing today I guess will need to be actually replacing my b2db file and running it for a few days. The correct lines are there, don't expect issues but Murphy could be hiding something.

Ray
B2 is playing The House You Live In by Gordon Lightfoot
Reply 0 0
Ray J Dion ray
Ok. I did not remember that the B2 does a quick scan when it starts up. I can do a replace of the file followed by a normal shutdown and startup. The new stats are based on my b2db file. Been looking for a way to initialize a new 'quick scan'.

Ray
B2 is playing I Wouldn't Bet For Water by Sheena Easton
Reply 0 0
MarkF
Ok. I did not remember that the B2 does a quick scan when it starts up. I can do a replace of the file followed by a normal shutdown and startup. The new stats are based on my b2db file. Been looking for a way to initialize a new 'quick scan'.

Reboot?
Reply 0 0
AJ
I believe that the actual database is held in memory, and that the stats are maintained as and when items are added or removed from the database. I think that the quick scan that you refer to is actually part of the process of reading the b2db file and creating the database.

So, if I understand what you are trying to achieve correctly then you will need to force the b2db file to be reloaded recreating the database. This is presumably what happens when you load a new b2db from a USB device. Unfortunately, there is no upload a new b2db option from the WebUI, if there was you could probably do this using the WebAPI.

So, it appears that it is probably not possible to do what you want without some code changes on the Brennan.

Andrew.
Reply 0 0
Ray J Dion ray
Agree with you both. A reboot after writing out the new b2db is appropriate. That is what I meant by 'when it starts up'.  It is good that a normal shutdown does not rewrite the b2db as best I can tell. I am just trying to do things that don't require that action.

Andrew just to confirm. Since you reference the IP address of the B2 I am guessing the code you provided runs on the desktop and is making calls to resident functions on the B2. Please correct me if I am wrong. I get a error on the URL_STRING line with the ending double quote.

I am a cut and paste kind of hacker. :-)  I have actually gotten a lot to work that way for many projects at work and home.
Ray 
B2 is playing Sweet and Simple by Journey
Reply 0 0
Reply