Question Pathing design

Strahan

Member
Joined
Mar 28, 2015
Messages
11
Programming Experience
3-5
Hi! I'm rebuilding my old media browser. I made a PHP website to browse my media files and handle playing them and tracking where I am with shows. Thing is, I made it sixteen years ago. Over the years I've just modded it as necessary to meet my needs, and what I have now is absolutely ghastly lol. It's 8,305 lines of code in... two files lol. No classes either, no OO at all. Needless to say, it's high time to ditch that spaghetti mess. I decided to forgo the web approach all together and make a C# application. The web interface is not easy to work with my remote control whereas I'll have control over everything UI related in C#.

Anyway I digress. In my C# application, I have two main objects MediaEntry and MediaFile. When the app opens, it will display all MediaEntry at the root level. So the initial screen's list would be like:
C#:
Anime
Movies
Music Videos
TV Shows
The MediaEntry object has a string Path. A sample of the data would be like "anime//g//genjitsu shugi yuusha no oukoku saikenki//season 2". I figured I could find children by searching for entries where path = current path + "//". But then I was thinking perhaps it'd be better to just have a "parent" field. My objects have an "Id" int which relates to the database autoinc ID index field for the entry. Parent then would have that Id value of the parent entry. The reason I'm not 100% sure that's the way to go is then if I move an entry, I have to both update a parent and a path. Seems like I shouldn't need both then. Plus then to display the current path if I only have parent I guess I'd have to write something that iterates its way backwards up the tree? Sounds inefficient.

I figured instead of agonizing over it I'd just ask the community; when you design a hierarchical structure like this, what is the best practice for associating the levels with each other?

Thanks!
 
Maintaining parallel data structures is usually a bad idea unless there is something that you are trying to optimize read operations, and write operations are not frequent. In your shoes, I would just use the hierarchy of IDs.
 
Also, do the files even have to be organized in a folder tree that way? Why can't the files just match up with a FileId in that database, and the the heirarchy is only in the database? Or is the file/folder heirarchy there as a backup in case the database gets corrupted.
 
Yea, I found my original idea definitely does not work. I'm switching to specific parent IDs.

As to your question about organization, I'm not entirely sure what you mean. The way the program will work is I have a table "MediaEntries". So like I have, for example, this:
C#:
MediaEntry {
  Id = 6322
  Parent = 6321
  SitePath = "anime//v//vinland saga//season 1"
  SmbHost = "aivas"
  SmbShare = "anime-v$"
  SmbPath = "/Vinland Saga/Season 1"
  ...etc
}
Once I load that, I put the relevant info up on the screen then there is a FlowLayoutPanel for child entries. It searches the mediafiles table and finds all records with parent 6322 then builds a List with entries like:
C#:
MediaFile {
  Id = 109282
  Parent = 6322
  Filename = "[Foxtrot] Vinland Saga - 01 [BD 720p AAC] [3FD92B58].mkv"
  Episode = 1
  Duration = 1706
  ...etc
}
then populates the FLP. I can't just do a filesystem based navigation, because I keep running out of hard drive space lol. I built a 16 drive array with 3 TB drives, then that filled up. Next tax time I want to yank those 3s and replace with 14s, but until then I've been buying 8 TB drives and throwing them in other boxes and sharing them out. So like I may have the "A"s on the main fileserver, then "G"s would be on server2, "T"s may be on server3, etc. I figured it'd be easier to just use MySQL to keep track of everything.
 
Back
Top Bottom