getCategoryMetadata.brs (6249B)
1 '******************************************************************** 2 '** Home Media Server Application - Get the metadata for a category 3 '** Copyright (c) 2022 Brian C. Lane All Rights Reserved. 4 '******************************************************************** 5 6 '******************************************************************* 7 ' Return a roArray of ContentNodes for the selected category 8 ' The list is sorted by title, and the ContentNode has the fields 9 ' setup for direct use with the VideoNode 10 ' 11 ' Pass the server url and the category (the subdirectory) to get the 12 ' metadata from. 13 '******************************************************************* 14 Function getCategoryMetadata(url As String, category As String) As Object 15 cat_url = url + "/" + category + "/" 16 listing = getDirectoryListing(cat_url) 17 listing_hash = CreateObject("roAssociativeArray") 18 for each f in listing 19 listing_hash.AddReplace(f, "") 20 end for 21 22 ' What kind of directory is this? 23 dirType = directoryType(listing_hash) 24 if dirType = 1 then 25 displayList = displayFiles(listing, { jpg : true }) 26 else if dirType = 2 then 27 displayList = displayFiles(listing, { mp3 : true }) 28 else if dirType = 3 then 29 displayList = displayFiles(listing, { mp4 : true, m4v : true, mov : true, wmv : true } ) 30 else if dirType = 4 then 31 displayList = displayFiles(listing, { mp4 : true, m4v : true, mov : true, wmv : true } ) 32 else 33 ' Assume movies if there is no type file 34 displayList = displayFiles(listing, { mp4 : true, m4v : true, mov : true, wmv : true } ) 35 end if 36 37 Sort(displayList, function(k) 38 return LCase(k[0]) 39 end function) 40 list = CreateObject("roArray", displayList.Count(), false) 41 for j = 0 to displayList.Count()-1 42 list.Push(MovieObject(displayList[j], cat_url, listing_hash)) 43 end for 44 return list 45 End Function 46 47 '********************************* 48 ' Return the type of the directory 49 ' 50 ' 1 = photos 51 ' 2 = songs 52 ' 3 = episodes 53 ' 4 = movies 54 '********************************* 55 Function directoryType(listing_hash As Object) As Integer 56 if listing_hash.DoesExist("photos") then 57 return 1 58 else if listing_hash.DoesExist("songs") then 59 return 2 60 else if listing_hash.DoesExist("episodes") then 61 return 3 62 else if listing_hash.DoesExist("movies") then 63 return 4 64 end if 65 return 0 66 End Function 67 68 '************************************************************** 69 ' Get the poster name for the content type 70 ' 71 ' First look for a specific .png or .jpg matching the basename, 72 ' then try 'default' 73 ' 74 ' Pass the full listing hash, the server url, basename of the 75 ' video, and content type. eg. SD, HD, FHD 76 ' 77 ' It returns the full url to the poster to use or "" if none 78 ' are found in the listing. 79 '************************************************************** 80 Function GetPosterURL(listing_hash as Object, url as String, basename as String, content as String) as String 81 if listing_hash.DoesExist(basename+"-"+content+".png") then 82 return url+basename+"-"+content+".png" 83 else if listing_hash.DoesExist(basename+"-"+content+".jpg") then 84 return url+basename+"-"+content+".jpg" 85 else if listing_hash.DoesExist("default-"+content+".png") then 86 return url+"default-"+content+".png" 87 else if listing_hash.DoesExist("default-"+content+".jpg") then 88 return url+"default-"+content+".jpg" 89 end if 90 91 return "" 92 End Function 93 94 '************************************************************ 95 ' Get the bif file url for the content type 96 ' 97 ' Pass the full listing hash, the server url, basename of the 98 ' video, and content type. eg. SD, HD, FHD 99 ' 100 ' It returns the full url to the bif file or "" if none are 101 ' found in the listing. 102 '************************************************************ 103 Function GetBifURL(listing_hash as Object, url as String, basename as String, content as String) as String 104 if listing_hash.DoesExist(basename+"-"+content+".bif") then 105 return url+basename+"-"+content+".bif" 106 end if 107 108 return "" 109 End Function 110 111 '***************************************************** 112 ' Create an object with the movie metadata 113 ' 114 ' Return a ContentNode with all the fields 115 ' needed for use with the VideoNode setup. 116 ' 117 ' Pass the filename, server url, and full listing_hash 118 '***************************************************** 119 Function MovieObject(file As Object, url As String, listing_hash as Object) As Object 120 o = CreateObject("roSGNode", "ContentNode") 121 o.ContentType = "movie" 122 o.ShortDescriptionLine1 = file[1]["basename"] 123 124 ' XXX says no field in ContentNode 125 ' o.IsHD = false 126 127 ' Assume there is always a SD poster 128 o.SDPosterURL = GetPosterURL(listing_hash, url, file[1]["basename"], "SD") 129 130 ' Fall back to lower existing poster for HD and FHD if they don't exist 131 o.HDPosterURL = GetPosterURL(listing_hash, url, file[1]["basename"], "HD") 132 if o.HDPosterURL = "" 133 o.HDPosterURL = o.SDPosterURL 134 end if 135 o.FHDPosterURL = GetPosterURL(listing_hash, url, file[1]["basename"], "FHD") 136 if o.FHDPosterURL = "" 137 if o.HDPosterURL <> "" 138 o.FHDPosterURL = o.HDPosterURL 139 else 140 o.FHDPosterURL = o.SDPosterURL 141 end if 142 end if 143 144 ' Setup the .bif files 145 o.SDBifURL = GetBifURL(listing_hash, url, file[1]["basename"], "SD") 146 o.HDBifURL = GetBifURL(listing_hash, url, file[1]["basename"], "HD") 147 o.FHDBifURL = GetBifURL(listing_hash, url, file[1]["basename"], "FHD") 148 149 ' NOTE: Cannot easily just read a file in this function 150 ' if listing_hash.DoesExist(file[1]["basename"]+".txt") then 151 ' o.Description = getDescription(url+file[1]["basename"]+".txt") 152 ' end if 153 154 o.HDBranded = false 155 o.Rating = "NR" 156 o.StarRating = 100 157 o.Title = file[1]["basename"] 158 o.Url = url + file[0] 159 160 streamFormat = { mp4 : "mp4", m4v : "mp4", mov : "mp4", 161 wmv : "wmv", hls : "hls" 162 } 163 if streamFormat.DoesExist(file[1]["extension"].Mid(1)) then 164 o.StreamFormat = streamFormat[file[1]["extension"].Mid(1)] 165 else 166 o.StreamFormat = "mp4" 167 end if 168 169 return o 170 End Function