├── .gitmodules ├── LICENSE ├── README.md ├── screenshots ├── because-you-watched.png ├── my-list.png ├── settings-location.png ├── settings.png └── watch-again.png └── src ├── .gitignore ├── Jellyfin.Plugin.HomeScreenSections.sln ├── Jellyfin.Plugin.HomeScreenSections ├── Config │ └── settings.html ├── Configuration │ ├── PluginConfiguration.cs │ └── config.html ├── Controllers │ ├── HomeScreenController.cs │ ├── ModularHomeViewsController.cs │ └── loadSections.js ├── Helpers │ ├── MiscExtensions.cs │ ├── TransformationPatches.cs │ └── TranslationHelper.cs ├── HomeScreen │ ├── CollectionManagerProxy.cs │ ├── HomeScreenManager.cs │ └── Sections │ │ ├── BecauseYouWatchedSection.cs │ │ ├── ContinueWatchingSection.cs │ │ ├── LatestMoviesSection.cs │ │ ├── LatestShowsSection.cs │ │ ├── LiveTvSection.cs │ │ ├── MyListSection.cs │ │ ├── MyMediaSection.cs │ │ ├── NextUpSection.cs │ │ ├── PluginDefinedSection.cs │ │ ├── RecentlyAddedMoviesSection.cs │ │ ├── RecentlyAddedShowsSection.cs │ │ ├── TopTenSection.cs │ │ └── WatchAgainSection.cs ├── HomeScreenSectionsPlugin.cs ├── Inject │ ├── HomeScreenSections.css │ └── HomeScreenSections.js ├── Jellyfin.Plugin.HomeScreenSections.csproj ├── Library │ └── IHomeScreenManager.cs ├── Model │ ├── Dto │ │ └── HomeScreenSectionPayload.cs │ ├── PatchRequestPayload.cs │ └── SectionRegisterPayload.cs ├── PluginServiceRegistrator.cs ├── Properties │ └── AssemblyInfo.cs └── Services │ └── StartupService.cs └── logo.png /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "jellyfin-web"] 2 | path = jellyfin-web 3 | url = https://github.com/IAmParadox27/jellyfin-web.git 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

Home Screen Sections (Modular Home)

2 |

A Jellyfin Plugin

3 |

4 | Logo 5 |
6 |
7 | 8 | GPL 3.0 License 9 | 10 | 11 | Current Release 12 | 13 |

14 | 15 | ## Introduction 16 | Home Screen Sections (commonly referred to as Modular Home) is a Jellyfin plugin which allows users to update their web client's home screen to be a bit more dynamic and more "Netflixy". 17 | 18 | ### Sections Included 19 | A lot of the sections included are the base sections that would appear in a vanilla instance of Jellyfin. This has been done because using Modular Home hasn't been integrated to work side by side with the vanilla home screen and instead wholesale replaces it. Since a lot of the sections are useful and contain everything you'd want in a home screen they've been included for convenience. 20 | 21 | > **NOTE**: Its worth noting that the sections that have been created are one's that I myself use for my own instance, if there is a section that's missing check the "Adding your own sections" heading below for info on how you can create your own. 22 | 23 | These vanilla sections are listed here: 24 | 25 | - My Media 26 | - Same as vanilla Jellyfin 27 | - Continue Watching 28 | - Same as vanilla Jellyfin 29 | - Next Up 30 | - Same as vanilla Jellyfin 31 | - Recently Added Movies/TV Shows 32 | - Same as vanilla Jellyfin 33 | - Live TV 34 | - Mostly the same as vanilla Jellyfin. _Current State is untested since updating to 10.10.3 so may find that there are issues_ 35 | 36 | The sections that are new for this plugin (and most likely the reason you would use this plugin in the first place) are outlined here: 37 | 38 | - Latest Movies/TV Shows 39 | - These are movies/shows that have recently aired (or released) rather than when they were added to your library. 40 | 41 | - Because You Watched 42 | - Very similar to Netflix's "because you watched" section, a maximum of 5 of these will appear when the section is enabled 43 | Because You Watched Preview 44 | 45 | - Watch Again 46 | - Again similar to Netflix's feature of the same name, this will request Movies in a Collection and TV Shows that have been watched to their completion and will provide the user an option to watch the show/movie collection again. The listed entry will be the first movie to be released in that collection (done by Premiere Date) or the first episode in the series 47 | Watch Again Preview 48 | 49 | - My List 50 | - Again similar to Netflix's feature. This requires a bit more setup than the others to get working. It looks for a playlist called "My List" and retrieves the entries in that playlist. 51 | My List Preview 52 | 53 | ## Installation 54 | 55 | ### Prerequisites 56 | - This plugin is based on Jellyfin Version `10.10.7` 57 | - The following plugins are required to also be installed, please following their installation guides: 58 | - File Transformation (https://github.com/IAmParadox27/jellyfin-plugin-file-transformation) at least v2.2.1.0 59 | - Plugin Pages (https://github.com/IAmParadox27/jellyfin-plugin-pages) at least v2.2.2.0 60 | 61 | ### Installation 62 | 1. Add `https://www.iamparadox.dev/jellyfin/plugins/manifest.json` to your plugin repositories. 63 | 2. Install `Home Screen Sections` from the Catalogue. 64 | 3. Restart Jellyfin. 65 | 4. On the user's homepage, open the hamburger menu and you should see a link for settings to "Modular Home". Click this. 66 | 5. At the top there is a button to enable support and it will retrieve all sections that are available on your instance. Select all that apply. 67 | 6. Save the settings. _Please note currently the user is not provided any feedback when the settings are saved_. 68 | 7. Force refresh your webpage (or app) and you should see your new sections instead of the original ones. 69 | ## Upcoming Features/Known Issues 70 | If you find an issue with any of the sections or usage of the plugin, please open an issue on GitHub. 71 | 72 | ### FAQ 73 | 74 | #### I've installed the plugins and don't get any options or changes. How do I fix? 75 | This is common, particularly on a fresh install. The first thing you should try is the following 76 | 1. Launch your browsers developer tools 77 | 78 | ![image](https://github.com/user-attachments/assets/e8781a69-464e-430e-a07c-5172a620ef84) 79 | 80 | 3. Open the **Network** tab across the top bar 81 | 4. Check the **Disable cache** checkbox 82 | 5. Refresh the page **while the dev tools are still open** 83 | 84 | ![image](https://github.com/user-attachments/assets/6f8c3fc7-89a3-4475-b8a6-cd4a58d51b84) 85 | 86 | #### How can I tell if its worked? 87 | 88 | > The easiest way to confirm whether the user is using the modular home settings is to check whether the movie posters are portrait or landscape. Due to how the cards are delivered from the backend all cards are forced to be landscape 89 | ## Contribution 90 | ### Adding your own sections 91 | > This is great an' all but I want a section that doesn't exist here. Can I make one? 92 | 93 | Yep! Home Screen Sections exposes HTTP endpoints which can be used to register sections. 94 | 95 | Send an HTTP POST request to `http(s)://{YOUR_JELLYFIN_URL}/HomeScreen/RegisterSection` with data in the following structure 96 | ```json 97 | { 98 | "id": "", // Unique ID for your section 99 | "displayText":"", // What text should be displayed for your section 100 | "limit": 1, // This can only be 1 at the moment, I am working hard to support more than 1 section via HTTP request 101 | "additionalData": "", // Any accompanying data you want sent to your endpoint 102 | "resultsEndpoint":"" // The endpoint that will be requested when the section is requested. Expected to return `QueryResult` 103 | } 104 | ``` 105 | 106 | ### Pull Requests 107 | I'm open to any and all pull requests that expand the functionality of this plugin, while keeping within the scope of what its outlined to do, however if the PR includes new sections which **are not** vanilla implementations it will be rejected as the above approach is preferred. 108 | 109 | I don't want this plugin to bloat with lots of section types another server admin might not want, best to keep those as "plugin plugins". 110 | -------------------------------------------------------------------------------- /screenshots/because-you-watched.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IAmParadox27/jellyfin-plugin-home-sections/07f005f47d2b32b7b3d815134aeaa599b71ae9a7/screenshots/because-you-watched.png -------------------------------------------------------------------------------- /screenshots/my-list.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IAmParadox27/jellyfin-plugin-home-sections/07f005f47d2b32b7b3d815134aeaa599b71ae9a7/screenshots/my-list.png -------------------------------------------------------------------------------- /screenshots/settings-location.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IAmParadox27/jellyfin-plugin-home-sections/07f005f47d2b32b7b3d815134aeaa599b71ae9a7/screenshots/settings-location.png -------------------------------------------------------------------------------- /screenshots/settings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IAmParadox27/jellyfin-plugin-home-sections/07f005f47d2b32b7b3d815134aeaa599b71ae9a7/screenshots/settings.png -------------------------------------------------------------------------------- /screenshots/watch-again.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IAmParadox27/jellyfin-plugin-home-sections/07f005f47d2b32b7b3d815134aeaa599b71ae9a7/screenshots/watch-again.png -------------------------------------------------------------------------------- /src/.gitignore: -------------------------------------------------------------------------------- 1 | bin/ 2 | obj/ 3 | .vs/ 4 | .idea/ 5 | artifacts 6 | Release 7 | *.zip 8 | node_modules 9 | dist/ -------------------------------------------------------------------------------- /src/Jellyfin.Plugin.HomeScreenSections.sln: -------------------------------------------------------------------------------- 1 | Microsoft Visual Studio Solution File, Format Version 12.00 2 | # Visual Studio Version 17 3 | VisualStudioVersion = 17.3.32505.426 4 | MinimumVisualStudioVersion = 10.0.40219.1 5 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jellyfin.Plugin.HomeScreenSections", "Jellyfin.Plugin.HomeScreenSections\Jellyfin.Plugin.HomeScreenSections.csproj", "{D7F7C6FE-9D27-40F9-90E8-F23FC8743BCA}" 6 | EndProject 7 | Global 8 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 9 | Debug|Any CPU = Debug|Any CPU 10 | Release|Any CPU = Release|Any CPU 11 | EndGlobalSection 12 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 13 | {D7F7C6FE-9D27-40F9-90E8-F23FC8743BCA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 14 | {D7F7C6FE-9D27-40F9-90E8-F23FC8743BCA}.Debug|Any CPU.Build.0 = Debug|Any CPU 15 | {D7F7C6FE-9D27-40F9-90E8-F23FC8743BCA}.Release|Any CPU.ActiveCfg = Release|Any CPU 16 | {D7F7C6FE-9D27-40F9-90E8-F23FC8743BCA}.Release|Any CPU.Build.0 = Release|Any CPU 17 | EndGlobalSection 18 | EndGlobal 19 | -------------------------------------------------------------------------------- /src/Jellyfin.Plugin.HomeScreenSections/Config/settings.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |

Modular Home - Settings:

4 | 5 |
6 | 10 |
11 | 12 |
13 |

Enabled Sections

14 |
15 |
16 |
17 | 18 |
19 | 22 |
23 | -------------------------------------------------------------------------------- /src/Jellyfin.Plugin.HomeScreenSections/Configuration/PluginConfiguration.cs: -------------------------------------------------------------------------------- 1 | using MediaBrowser.Model.Plugins; 2 | 3 | namespace Jellyfin.Plugin.HomeScreenSections.Configuration 4 | { 5 | public class PluginConfiguration : BasePluginConfiguration 6 | { 7 | public bool Enabled { get; set; } = false; 8 | 9 | public bool AllowUserOverride { get; set; } = true; 10 | 11 | public string? LibreTranslateUrl { get; set; } = ""; 12 | 13 | public string? LibreTranslateApiKey { get; set; } = ""; 14 | 15 | public SectionSettings[] SectionSettings { get; set; } = Array.Empty(); 16 | } 17 | 18 | public enum SectionViewMode 19 | { 20 | Portrait, 21 | Landscape, 22 | Square 23 | } 24 | 25 | public class SectionSettings 26 | { 27 | public string SectionId { get; set; } = string.Empty; 28 | 29 | public bool Enabled { get; set; } 30 | 31 | public bool AllowUserOverride { get; set; } 32 | 33 | public int LowerLimit { get; set; } 34 | 35 | public int UpperLimit { get; set; } 36 | 37 | public int OrderIndex { get; set; } 38 | 39 | public SectionViewMode ViewMode { get; set; } = SectionViewMode.Landscape; 40 | } 41 | } -------------------------------------------------------------------------------- /src/Jellyfin.Plugin.HomeScreenSections/Configuration/config.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Home Screen Sections 5 | 6 | 7 |
8 |
9 |
10 |
11 |

Home Screen Sections

12 | 13 | 14 | Help 15 | 16 |
17 |
18 |
19 |
20 |
21 | Global Settings 22 |
23 | 31 |
Is Home Screen Sections enabled by default for all users?
32 |
33 |
34 | 42 |
Is the user allowed to enable/disable this plugin for their view?
43 |
44 |
45 | 46 | URL for LibreTranslate instance to use for translations. 47 |
48 |
49 | 50 | API Key for LibreTranslate instance. 51 |
52 |
53 |
54 | Section Settings 55 |
56 |
57 |
58 |
59 | 62 |
63 |
64 | 65 | 120 | 121 | 248 |
249 | 250 | -------------------------------------------------------------------------------- /src/Jellyfin.Plugin.HomeScreenSections/Controllers/HomeScreenController.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | using System.Net.Http.Headers; 3 | using System.Reflection; 4 | using System.Text.RegularExpressions; 5 | using Jellyfin.Data.Entities; 6 | using Jellyfin.Data.Enums; 7 | using Jellyfin.Extensions; 8 | using Jellyfin.Plugin.HomeScreenSections.Configuration; 9 | using Jellyfin.Plugin.HomeScreenSections.Helpers; 10 | using Jellyfin.Plugin.HomeScreenSections.HomeScreen.Sections; 11 | using Jellyfin.Plugin.HomeScreenSections.Library; 12 | using Jellyfin.Plugin.HomeScreenSections.Model; 13 | using Jellyfin.Plugin.HomeScreenSections.Model.Dto; 14 | using Jellyfin.Plugin.HomeScreenSections.Services; 15 | using MediaBrowser.Common.Configuration; 16 | using MediaBrowser.Common.Extensions; 17 | using MediaBrowser.Controller; 18 | using MediaBrowser.Model.Dto; 19 | using MediaBrowser.Model.Querying; 20 | using Microsoft.AspNetCore.Http; 21 | using Microsoft.AspNetCore.Mvc; 22 | using Newtonsoft.Json; 23 | using Newtonsoft.Json.Linq; 24 | 25 | namespace Jellyfin.Plugin.HomeScreenSections.Controllers 26 | { 27 | /// 28 | /// API controller for the Modular Home Screen. 29 | /// 30 | [ApiController] 31 | [Route("[controller]")] 32 | public class HomeScreenController : ControllerBase 33 | { 34 | private readonly IHomeScreenManager m_homeScreenManager; 35 | private readonly IDisplayPreferencesManager m_displayPreferencesManager; 36 | private readonly IServerApplicationHost m_serverApplicationHost; 37 | private readonly IApplicationPaths m_applicationPaths; 38 | 39 | public HomeScreenController( 40 | IHomeScreenManager homeScreenManager, 41 | IDisplayPreferencesManager displayPreferencesManager, 42 | IServerApplicationHost serverApplicationHost, 43 | IApplicationPaths applicationPaths) 44 | { 45 | m_homeScreenManager = homeScreenManager; 46 | m_displayPreferencesManager = displayPreferencesManager; 47 | m_serverApplicationHost = serverApplicationHost; 48 | m_applicationPaths = applicationPaths; 49 | } 50 | 51 | [HttpGet("home-screen-sections.js")] 52 | [Produces("application/javascript")] 53 | public ActionResult GetPluginScript() 54 | { 55 | Stream? stream = Assembly.GetExecutingAssembly() 56 | .GetManifestResourceStream(typeof(HomeScreenSectionsPlugin).Namespace + 57 | ".Inject.HomeScreenSections.js"); 58 | 59 | if (stream == null) 60 | { 61 | return NotFound(); 62 | } 63 | 64 | return File(stream, "application/javascript"); 65 | } 66 | 67 | [HttpGet("home-screen-sections.css")] 68 | [Produces("text/css")] 69 | public ActionResult GetPluginStylesheet() 70 | { 71 | Stream? stream = Assembly.GetExecutingAssembly() 72 | .GetManifestResourceStream(typeof(HomeScreenSectionsPlugin).Namespace + 73 | ".Inject.HomeScreenSections.css"); 74 | 75 | if (stream == null) 76 | { 77 | return NotFound(); 78 | } 79 | 80 | return File(stream, "text/css"); 81 | } 82 | 83 | [HttpGet("Configuration")] 84 | [ProducesResponseType(StatusCodes.Status200OK)] 85 | public ActionResult GetHomeScreenConfiguration() 86 | { 87 | return HomeScreenSectionsPlugin.Instance.Configuration; 88 | } 89 | 90 | [HttpGet("Sections")] 91 | [ProducesResponseType(StatusCodes.Status200OK)] 92 | public ActionResult> GetHomeScreenSections( 93 | [FromQuery] Guid? userId, 94 | [FromQuery] string? language) 95 | { 96 | string displayPreferencesId = "usersettings"; 97 | Guid itemId = displayPreferencesId.GetMD5(); 98 | 99 | DisplayPreferences displayPreferences = m_displayPreferencesManager.GetDisplayPreferences(userId ?? Guid.Empty, itemId, "emby"); 100 | ModularHomeUserSettings? settings = m_homeScreenManager.GetUserSettings(userId ?? Guid.Empty); 101 | 102 | List sectionTypes = m_homeScreenManager.GetSectionTypes().Where(x => settings?.EnabledSections.Contains(x.Section ?? string.Empty) ?? false).ToList(); 103 | 104 | List sectionInstances = new List(); 105 | 106 | List homeSectionOrderTypes = new List(); 107 | foreach (HomeSection section in displayPreferences.HomeSections.OrderBy(x => x.Order)) 108 | { 109 | switch (section.Type) 110 | { 111 | case HomeSectionType.SmallLibraryTiles: 112 | homeSectionOrderTypes.Add("MyMedia"); 113 | break; 114 | case HomeSectionType.Resume: 115 | homeSectionOrderTypes.Add("ContinueWatching"); 116 | break; 117 | case HomeSectionType.LatestMedia: 118 | homeSectionOrderTypes.Add("LatestMovies"); 119 | homeSectionOrderTypes.Add("LatestShows"); 120 | break; 121 | case HomeSectionType.NextUp: 122 | homeSectionOrderTypes.Add("NextUp"); 123 | break; 124 | } 125 | } 126 | 127 | foreach (string type in homeSectionOrderTypes) 128 | { 129 | IHomeScreenSection? sectionType = sectionTypes.FirstOrDefault(x => x.Section == type); 130 | 131 | if (sectionType != null) 132 | { 133 | if (sectionType.Limit > 1) 134 | { 135 | SectionSettings? sectionSettings = HomeScreenSectionsPlugin.Instance.Configuration.SectionSettings.FirstOrDefault(x => 136 | x.SectionId == sectionType.Section); 137 | 138 | Random rnd = new Random(); 139 | int instanceCount = rnd.Next(sectionSettings?.LowerLimit ?? 0, sectionSettings?.UpperLimit ?? sectionType.Limit ?? 1); 140 | 141 | for (int i = 0; i < instanceCount; ++i) 142 | { 143 | sectionInstances.Add(sectionType.CreateInstance(userId, sectionInstances.Where(x => x.GetType() == sectionType.GetType()))); 144 | } 145 | } 146 | else if (sectionType.Limit == 1) 147 | { 148 | sectionInstances.Add(sectionType.CreateInstance(userId)); 149 | } 150 | } 151 | } 152 | 153 | sectionTypes.RemoveAll(x => homeSectionOrderTypes.Contains(x.Section ?? string.Empty)); 154 | 155 | IEnumerable> groupedOrderedSections = HomeScreenSectionsPlugin.Instance.Configuration.SectionSettings 156 | .OrderBy(x => x.OrderIndex) 157 | .GroupBy(x => x.OrderIndex); 158 | 159 | foreach (IGrouping orderedSections in groupedOrderedSections) 160 | { 161 | List tmpPluginSections = new List(); // we want these randomly distributed among each other. 162 | 163 | foreach (SectionSettings sectionSettings in orderedSections) 164 | { 165 | IHomeScreenSection? sectionType = sectionTypes.FirstOrDefault(x => x.Section == sectionSettings.SectionId); 166 | 167 | if (sectionType != null) 168 | { 169 | if (sectionType.Limit > 1) 170 | { 171 | Random rnd = new Random(); 172 | int instanceCount = rnd.Next(sectionSettings?.LowerLimit ?? 0, sectionSettings?.UpperLimit ?? sectionType.Limit ?? 1); 173 | 174 | for (int i = 0; i < instanceCount; ++i) 175 | { 176 | IHomeScreenSection[] tmpSectionInstances = tmpPluginSections.Where(x => x?.GetType() == sectionType.GetType()) 177 | .Concat(sectionInstances.Where(x => x.GetType() == sectionType.GetType())).ToArray(); 178 | 179 | tmpPluginSections.Add(sectionType.CreateInstance(userId, tmpSectionInstances)); 180 | } 181 | } 182 | else if (sectionType.Limit == 1) 183 | { 184 | tmpPluginSections.Add(sectionType.CreateInstance(userId)); 185 | } 186 | } 187 | } 188 | 189 | tmpPluginSections.Shuffle(); 190 | 191 | sectionInstances.AddRange(tmpPluginSections); 192 | } 193 | 194 | List sections = sectionInstances.Where(x => x != null).Select(x => 195 | { 196 | HomeScreenSectionInfo info = x.AsInfo(); 197 | 198 | info.ViewMode = HomeScreenSectionsPlugin.Instance.Configuration.SectionSettings.FirstOrDefault(x => x.SectionId == info.Section)?.ViewMode ?? info.ViewMode ?? SectionViewMode.Landscape; 199 | 200 | if (language != "en" && !string.IsNullOrEmpty(language?.Trim()) && 201 | info.DisplayText != null) 202 | { 203 | string? translatedResult = TranslationHelper.TranslateAsync(info.DisplayText, "en", language.Trim()) 204 | .GetAwaiter().GetResult(); 205 | 206 | info.DisplayText = translatedResult; 207 | } 208 | 209 | return info; 210 | }).ToList(); 211 | 212 | return new QueryResult( 213 | 0, 214 | sections.Count, 215 | sections); 216 | } 217 | 218 | [HttpGet("Section/{sectionType}")] 219 | public QueryResult GetSectionContent( 220 | [FromRoute] string sectionType, 221 | [FromQuery, Required] Guid userId, 222 | [FromQuery] string? additionalData, 223 | [FromQuery] string? language) 224 | { 225 | HomeScreenSectionPayload payload = new HomeScreenSectionPayload 226 | { 227 | UserId = userId, 228 | AdditionalData = additionalData 229 | }; 230 | 231 | return m_homeScreenManager.InvokeResultsDelegate(sectionType, payload, Request.Query); 232 | } 233 | 234 | [HttpPost("RegisterSection")] 235 | public ActionResult RegisterSection([FromBody] SectionRegisterPayload payload) 236 | { 237 | m_homeScreenManager.RegisterResultsDelegate(new PluginDefinedSection(payload.Id, payload.DisplayText!, payload.Route, payload.AdditionalData) 238 | { 239 | OnGetResults = sectionPayload => 240 | { 241 | JObject jsonPayload = JObject.FromObject(sectionPayload); 242 | 243 | string? publishedServerUrl = m_serverApplicationHost.GetType() 244 | .GetProperty("PublishedServerUrl", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(m_serverApplicationHost) as string; 245 | 246 | HttpClient client = new HttpClient(); 247 | client.BaseAddress = new Uri(publishedServerUrl ?? $"http://localhost:{m_serverApplicationHost.HttpPort}"); 248 | 249 | HttpResponseMessage responseMessage = client.PostAsync(payload.ResultsEndpoint, 250 | new StringContent(jsonPayload.ToString(Formatting.None), MediaTypeHeaderValue.Parse("application/json"))).GetAwaiter().GetResult(); 251 | 252 | return JsonConvert.DeserializeObject>(responseMessage.Content.ReadAsStringAsync().GetAwaiter().GetResult()) ?? new QueryResult(); 253 | } 254 | }); 255 | 256 | return Ok(); 257 | } 258 | } 259 | } 260 | -------------------------------------------------------------------------------- /src/Jellyfin.Plugin.HomeScreenSections/Controllers/ModularHomeViewsController.cs: -------------------------------------------------------------------------------- 1 | using Jellyfin.Plugin.HomeScreenSections.Configuration; 2 | using Jellyfin.Plugin.HomeScreenSections.Library; 3 | using MediaBrowser.Model; 4 | using MediaBrowser.Model.Plugins; 5 | using MediaBrowser.Model.Querying; 6 | using Microsoft.AspNetCore.Mvc; 7 | using Microsoft.Extensions.Logging; 8 | 9 | namespace Jellyfin.Plugin.HomeScreenSections.Controllers 10 | { 11 | /// 12 | /// API controller for Modular Home plugin. 13 | /// 14 | [ApiController] 15 | [Route("[controller]")] 16 | public class ModularHomeViewsController : ControllerBase 17 | { 18 | private readonly ILogger m_logger; 19 | private readonly IHomeScreenManager m_homeScreenManager; 20 | 21 | /// 22 | /// Constructor. 23 | /// 24 | /// Instance of interface. 25 | /// Instance of interface. 26 | public ModularHomeViewsController(ILogger logger, IHomeScreenManager homeScreenManager) 27 | { 28 | m_logger = logger; 29 | m_homeScreenManager = homeScreenManager; 30 | } 31 | 32 | /// 33 | /// Get the view for the plugin. 34 | /// 35 | /// The view identifier. 36 | /// View. 37 | [HttpGet("{viewName}")] 38 | public ActionResult GetView([FromRoute] string viewName) 39 | { 40 | return ServeView(viewName); 41 | } 42 | 43 | /// 44 | /// Get the section types that are registered in Modular Home. 45 | /// 46 | /// Array of . 47 | [HttpGet("Sections")] 48 | public QueryResult GetSectionTypes() 49 | { 50 | // Todo add reading whether the section is enabled or disabled by the user. 51 | List items = new List(); 52 | 53 | IEnumerable sections = m_homeScreenManager.GetSectionTypes(); 54 | 55 | foreach (IHomeScreenSection section in sections) 56 | { 57 | HomeScreenSectionInfo item = section.GetInfo(); 58 | 59 | item.ViewMode ??= SectionViewMode.Landscape; 60 | 61 | items.Add(item); 62 | } 63 | 64 | return new QueryResult(null, items.Count, items); 65 | } 66 | 67 | /// 68 | /// Get the user settings for Modular Home. 69 | /// 70 | /// The user ID. 71 | /// . 72 | [HttpGet("UserSettings")] 73 | public ActionResult GetUserSettings([FromQuery] Guid userId) 74 | { 75 | IEnumerable defaultEnabledSections = 76 | HomeScreenSectionsPlugin.Instance.Configuration.SectionSettings.Where(x => x.Enabled); 77 | 78 | return m_homeScreenManager.GetUserSettings(userId) ?? new ModularHomeUserSettings 79 | { 80 | UserId = userId, 81 | EnabledSections = defaultEnabledSections.Select(x => x.SectionId).ToList() 82 | }; 83 | } 84 | 85 | /// 86 | /// Update the user settings for Modular Home. 87 | /// 88 | /// Instance of . 89 | /// Status. 90 | [HttpPost("UserSettings")] 91 | public ActionResult UpdateSettings([FromBody] ModularHomeUserSettings obj) 92 | { 93 | m_homeScreenManager.UpdateUserSettings(obj.UserId, obj); 94 | 95 | return Ok(); 96 | } 97 | 98 | private ActionResult ServeView(string viewName) 99 | { 100 | if (HomeScreenSectionsPlugin.Instance == null) 101 | { 102 | return BadRequest("No plugin instance found"); 103 | } 104 | 105 | IEnumerable pages = HomeScreenSectionsPlugin.Instance.GetViews(); 106 | 107 | if (pages == null) 108 | { 109 | return NotFound("Pages is null or empty"); 110 | } 111 | 112 | PluginPageInfo? view = pages.FirstOrDefault(pageInfo => pageInfo?.Name == viewName, null); 113 | 114 | if (view == null) 115 | { 116 | return NotFound("No matching view found"); 117 | } 118 | 119 | Stream? stream = HomeScreenSectionsPlugin.Instance.GetType().Assembly.GetManifestResourceStream(view.EmbeddedResourcePath); 120 | 121 | if (stream == null) 122 | { 123 | m_logger.LogError("Failed to get resource {Resource}", view.EmbeddedResourcePath); 124 | return NotFound(); 125 | } 126 | 127 | return File(stream, MimeTypes.GetMimeType(view.EmbeddedResourcePath)); 128 | } 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /src/Jellyfin.Plugin.HomeScreenSections/Controllers/loadSections.js: -------------------------------------------------------------------------------- 1 | async function test(elem, apiClient, user, userSettings) { 2 | function getHomeScreenSectionFetchFn(serverId, sectionInfo, serverConnections, _userSettings) { 3 | return function() { 4 | var __userSettings = _userSettings; 5 | 6 | var _apiClient = serverConnections.getApiClient(serverId); 7 | var queryParams = { 8 | UserId: _apiClient.getCurrentUserId(), 9 | AdditionalData: sectionInfo.AdditionalData, 10 | Language: localStorage.getItem(apiClient.getCurrentUserId() + '-language') 11 | }; 12 | 13 | if (sectionInfo.Section === 'NextUp') { 14 | var cutoffDate = new Date(); 15 | cutoffDate.setDate(cutoffDate.getDate() - _userSettings.maxDaysForNextUp()); 16 | 17 | queryParams.NextUpDateCutoff = cutoffDate.toISOString(); 18 | queryParams.EnableRewatching = _userSettings.enableRewatchingInNextUp(); 19 | } 20 | 21 | var getUrl = _apiClient.getUrl("HomeScreen/Section/" + sectionInfo.Section, queryParams); 22 | return _apiClient.getJSON(getUrl); 23 | } 24 | } 25 | 26 | function getHomeScreenSectionItemsHtmlFn(useEpisodeImages, enableOverflow, sectionKey, cardBuilder, getShapeFn, additionalSettings) { 27 | return function(items) { 28 | return cardBuilder.getCardsHtml({ 29 | items: items, 30 | preferThumb: additionalSettings.ViewMode === 'Portrait' ? null : 'auto', 31 | inheritThumb: !useEpisodeImages, 32 | shape: getShapeFn(enableOverflow), 33 | overlayText: false, 34 | showTitle: additionalSettings.DisplayTitleText, 35 | showParentTitle: additionalSettings.DisplayTitleText, 36 | lazy: true, 37 | showDetailsMenu: additionalSettings.ShowDetailsMenu, 38 | overlayPlayButton: "MyMedia" !== sectionKey, 39 | context: "home", 40 | centerText: true, 41 | allowBottomPadding: false, 42 | cardLayout: false, 43 | showYear: true, 44 | lines: additionalSettings.DisplayTitleText ? (sectionKey === "MyMedia" ? 1 : 2) : 0 45 | }); 46 | } 47 | } 48 | 49 | function loadHomeSection(page, apiClient, user, userSettings, sectionInfo, options) { 50 | var sectionClass = sectionInfo.Section; 51 | if (sectionInfo.Limit > 1) { 52 | sectionClass += "-" + sectionInfo.AdditionalData; 53 | } 54 | var var5_, var6_, var7_, var8_, elem = page.querySelector("." + sectionClass); 55 | if (null !== elem) { 56 | var html = ""; 57 | var layoutManager = {{layoutmanager_hook}}.A; 58 | html += '
'; 59 | if (!layoutManager.tv && sectionInfo.Route !== undefined) { 60 | var route = undefined; 61 | if (sectionInfo.OriginalPayload !== undefined) { 62 | route = p.appRouter.getRouteUrl(sectionInfo.OriginalPayload, { 63 | serverId: apiClient.serverId() 64 | }); 65 | } else { 66 | route = p.appRouter.getRouteUrl(sectionInfo.Route, { 67 | serverId: apiClient.serverId() 68 | }) 69 | } 70 | 71 | html += ''; 72 | html += '

'; 73 | html += sectionInfo.DisplayText; 74 | html += "

"; 75 | html += ''; 76 | html += "
"; 77 | } else { 78 | html += '

'; 79 | html += sectionInfo.DisplayText; 80 | html += "

"; 81 | } 82 | 83 | html += "
"; 84 | html += '
'; 85 | html += '
'; 86 | html += "
"; 87 | html += "
"; 88 | elem.classList.add("hide"); 89 | elem.innerHTML = html; 90 | 91 | var var13_, var14_, itemsContainer = elem.querySelector(".itemsContainer"); 92 | 93 | if (itemsContainer !== null) { 94 | if (sectionInfo.ContainerClass !== undefined) { 95 | itemsContainer.classList.add(sectionInfo.ContainerClass); 96 | } 97 | 98 | var cardBuilder = {{cardbuilder_hook}}.default; 99 | 100 | var cardSettings = { 101 | ViewMode: sectionInfo.ViewMode, 102 | DisplayTitleText: sectionInfo.DisplayTitleText, 103 | ShowDetailsMenu: sectionInfo.ShowDetailsMenu 104 | } 105 | 106 | itemsContainer.fetchData = getHomeScreenSectionFetchFn(apiClient.serverId(), sectionInfo, u.A, userSettings); 107 | 108 | var getBackdropShape = y.UI; 109 | var getPortraitShape = y.xK; 110 | var getSquareShape = y.zP; 111 | 112 | var getShapeFn = getBackdropShape; 113 | if (cardSettings.ViewMode === 'Portrait') 114 | { 115 | getShapeFn = getPortraitShape; 116 | } 117 | else if (cardSettings.ViewMode === 'Square') 118 | { 119 | getShapeFn = getSquareShape; 120 | } 121 | 122 | itemsContainer.getItemsHtml = getHomeScreenSectionItemsHtmlFn(userSettings.useEpisodeImagesInNextUpAndResume(), options.enableOverflow, sectionInfo.Section, cardBuilder, getShapeFn, cardSettings); 123 | itemsContainer.parentContainer = elem; 124 | } 125 | } 126 | return Promise.resolve() 127 | } 128 | 129 | async function isUserUsingHomeScreenSections(_userSettings, _apiClient) { 130 | var pluginConfig = await _apiClient.getJSON(_apiClient.getUrl("HomeScreen/Configuration")); 131 | 132 | if (pluginConfig.AllowUserOverride === true) { 133 | if (_userSettings && _userSettings.getData() && _userSettings.getData().CustomPrefs && _userSettings.getData().CustomPrefs.useModularHome !== undefined) { 134 | return _userSettings.getData().CustomPrefs.useModularHome === "true"; 135 | } 136 | } 137 | 138 | return pluginConfig.Enabled; 139 | } 140 | 141 | if (await isUserUsingHomeScreenSections(userSettings, apiClient)) { 142 | return function(elem, apiClient, user, userSettings) { 143 | var var39_, var39_3, var39_4; 144 | return var39_ = this, void 0, var39_4 = function() { 145 | var var44_, options, var44_3, var44_4, var44_5, var44_6, var44_7, sectionInfo, var44_9, var44_10, var44_11; 146 | return function(param45_, param45_2) { 147 | var var46_, var47_, var48_, var49_ = { 148 | label: 0, 149 | sent: function() { 150 | if (1 & var48_[0]) throw var48_[1]; 151 | return var48_[1] 152 | }, 153 | trys: [], 154 | ops: [] 155 | }, 156 | var58_ = Object.create(("function" == typeof Iterator ? Iterator : Object).prototype); 157 | return var58_.next = fn69_(0), var58_.throw = fn69_(1), var58_.return = fn69_(2), "function" == typeof Symbol && (var58_[Symbol.iterator] = function() { 158 | return this 159 | }), var58_; 160 | 161 | function fn69_(param69_) { 162 | return function(param70_) { 163 | return function(param71_) { 164 | if (var46_) throw TypeError("Generator is already executing."); 165 | for (; var58_ && (var58_ = 0, param71_[0] && (var49_ = 0)), var49_;) try { 166 | if (var46_ = 1, var47_ && (var48_ = 2 & param71_[0] ? var47_.return : param71_[0] ? var47_.throw || ((var48_ = var47_.return) && var48_.call(var47_), 0) : var47_.next) && !(var48_ = var48_.call(var47_, param71_[1])).done) return var48_; 167 | switch (var47_ = 0, var48_ && (param71_ = [2 & param71_[0], var48_.value]), param71_[0]) { 168 | case 0: 169 | case 1: 170 | var48_ = param71_; 171 | break; 172 | case 4: 173 | return var49_.label++, { 174 | value: param71_[1], 175 | done: !1 176 | }; 177 | case 5: 178 | var49_.label++, var47_ = param71_[1], param71_ = [0]; 179 | continue; 180 | case 7: 181 | param71_ = var49_.ops.pop(), var49_.trys.pop(); 182 | continue; 183 | default: 184 | if (!((var48_ = (var48_ = var49_.trys).length > 0 && var48_[var48_.length - 1]) || 6 !== param71_[0] && 2 !== param71_[0])) { 185 | var49_ = 0; 186 | continue 187 | } 188 | if (3 === param71_[0] && (!var48_ || param71_[1] > var48_[0] && param71_[1] < var48_[3])) { 189 | var49_.label = param71_[1]; 190 | break 191 | } 192 | if (6 === param71_[0] && var49_.label < var48_[1]) { 193 | var49_.label = var48_[1], var48_ = param71_; 194 | break 195 | } 196 | if (var48_ && var49_.label < var48_[2]) { 197 | var49_.label = var48_[2], var49_.ops.push(param71_); 198 | break 199 | } 200 | var48_[2] && var49_.ops.pop(), var49_.trys.pop(); 201 | continue 202 | } 203 | param71_ = param45_2.call(param45_, var49_) 204 | } catch (let110_) { 205 | param71_ = [6, let110_], var47_ = 0 206 | } finally { 207 | var46_ = var48_ = 0 208 | } 209 | if (5 & param71_[0]) throw param71_[1]; 210 | return { 211 | value: param71_[0] ? param71_[1] : void 0, 212 | done: !0 213 | } 214 | }([param69_, param70_]) 215 | } 216 | } 217 | }(this, (function(param120_) { 218 | switch (param120_.label) { 219 | case 0: 220 | var var123_, var123_2, var123_3; 221 | return [4, (var123_ = apiClient, var123_2 = { 222 | UserId: apiClient.getCurrentUserId(), 223 | Language: localStorage.getItem(apiClient.getCurrentUserId() + '-language') 224 | }, var123_3 = var123_.getUrl("HomeScreen/Sections", var123_2), var123_.getJSON(var123_3))]; 225 | case 1: 226 | if (var44_ = param120_.sent(), options = { 227 | enableOverflow: !0 228 | }, var44_3 = "", var44_4 = [], void 0 !== var44_.Items) { 229 | for (var44_5 = 0; var44_5 < var44_.TotalRecordCount; var44_5++) var44_6 = var44_.Items[var44_5].Section, var44_.Items[var44_5].Limit > 1 && (var44_6 += "-" + var44_.Items[var44_5].AdditionalData), var44_3 += '
'; 230 | if (elem.innerHTML = var44_3, elem.classList.add("homeSectionsContainer"), var44_.TotalRecordCount > 0) 231 | for (var44_7 = 0; var44_7 < var44_.Items.length; var44_7++) sectionInfo = var44_.Items[var44_7], var44_4.push(loadHomeSection(elem, apiClient, 0, userSettings, sectionInfo, options)) 232 | } 233 | return var44_.TotalRecordCount > 0 ? [2, Promise.all(var44_4).then((function() { 234 | var var134_2, var134_3, var134_4; 235 | return var134_2 = { 236 | refresh: !0 237 | }, var134_3 = elem.querySelectorAll(".itemsContainer"), var134_4 = [], Array.prototype.forEach.call(var134_3, (function(param139_) { 238 | param139_.resume && var134_4.push(param139_.resume(var134_2)) 239 | })), Promise.all(var134_4) 240 | }))] : (var44_9 = (null === (var44_11 = user.Policy) || void 0 === var44_11 ? void 0 : var44_11.IsAdministrator) ? s.Ay.translate("NoCreatedLibraries", '
', "") : s.Ay.translate("AskAdminToCreateLibrary"), var44_3 += '
', var44_3 += "

" + s.Ay.translate("MessageNothingHere") + "

", var44_3 += "

" + var44_9 + "

", var44_3 += "
", elem.innerHTML = var44_3, (var44_10 = elem.querySelector("#button-createLibrary")) && var44_10.addEventListener("click", (function() { 241 | l.default.navigate("dashboard/libraries") 242 | })), [2]) 243 | } 244 | })) 245 | }, new(var39_3 = void 0, var39_3 = Promise)((function(param160_, param160_2) { 246 | function fn161_(param161_) { 247 | try { 248 | fn175_(var39_4.next(param161_)) 249 | } catch (let164_) { 250 | param160_2(let164_) 251 | } 252 | } 253 | 254 | function fn168_(param168_) { 255 | try { 256 | fn175_(var39_4.throw(param168_)) 257 | } catch (let171_) { 258 | param160_2(let171_) 259 | } 260 | } 261 | 262 | function fn175_(param175_) { 263 | var var176_; 264 | param175_.done ? param160_(param175_.value) : ((var176_ = param175_.value) instanceof var39_3 ? var176_ : new var39_3((function(param181_) { 265 | param181_(var176_) 266 | }))).then(fn161_, fn168_) 267 | } 268 | fn175_((var39_4 = var39_4.apply(var39_, [])).next()) 269 | })) 270 | }(elem, apiClient, user, userSettings); 271 | } else { 272 | return this.originalLoadSections(elem, apiClient, user, userSettings); 273 | } 274 | } -------------------------------------------------------------------------------- /src/Jellyfin.Plugin.HomeScreenSections/Helpers/MiscExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using Jellyfin.Data.Entities; 3 | using MediaBrowser.Controller.Collections; 4 | using MediaBrowser.Controller.Entities.Movies; 5 | 6 | namespace Jellyfin.Plugin.HomeScreenSections.Helpers; 7 | 8 | public static class MiscExtensions 9 | { 10 | public static IEnumerable GetCollections(this ICollectionManager collectionManager, User user) 11 | { 12 | return collectionManager.GetType() 13 | .GetMethod("GetCollections", BindingFlags.Instance | BindingFlags.NonPublic)? 14 | .Invoke(collectionManager, new object?[] 15 | { 16 | user 17 | }) as IEnumerable ?? Enumerable.Empty(); 18 | } 19 | } -------------------------------------------------------------------------------- /src/Jellyfin.Plugin.HomeScreenSections/Helpers/TransformationPatches.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Text.RegularExpressions; 3 | using Jellyfin.Plugin.HomeScreenSections.Model; 4 | using MediaBrowser.Common.Net; 5 | 6 | namespace Jellyfin.Plugin.HomeScreenSections.Helpers 7 | { 8 | public static class TransformationPatches 9 | { 10 | public static string LoadSections(PatchRequestPayload content) 11 | { 12 | // replace `",loadSections:` with itself followed by our function followed by `",originalLoadSections:` 13 | Stream replacementStream = Assembly.GetExecutingAssembly().GetManifestResourceStream($"{typeof(HomeScreenSectionsPlugin).Namespace}.Controllers.loadSections.js")!; 14 | using TextReader replacementTextReader = new StreamReader(replacementStream); 15 | 16 | string[] parts = content.Contents!.Split(",loadSections:", StringSplitOptions.RemoveEmptyEntries); 17 | Regex variableFind = new Regex(@"var\s+([a-zA-Z][^=]*)="); 18 | string thisVariableName = variableFind.Matches(parts[0]).Last().Groups[1].Value; 19 | string replacementText = replacementTextReader.ReadToEnd() 20 | .Replace("{{this_hook}}", thisVariableName) 21 | .Replace("{{layoutmanager_hook}}", "n") // TODO: lookup the first "assigned" variable after `var` 22 | .Replace("{{cardbuilder_hook}}", "h"); // TODO: lookup the last "assigned" variable in block that includes "SmallLibraryTiles" 23 | 24 | string regex = content.Contents.Replace(",loadSections:", $",loadSections:{replacementText},originalLoadSections:"); 25 | 26 | return regex; 27 | } 28 | 29 | public static string IndexHtml(PatchRequestPayload content) 30 | { 31 | NetworkConfiguration networkConfiguration = HomeScreenSectionsPlugin.Instance.ServerConfigurationManager.GetNetworkConfiguration(); 32 | 33 | string rootPath = ""; 34 | if (!string.IsNullOrWhiteSpace(networkConfiguration.BaseUrl)) 35 | { 36 | rootPath = $"/{networkConfiguration.BaseUrl.TrimStart('/').Trim()}"; 37 | } 38 | 39 | string replacementText0 = $""; 40 | string replacementText1 = $""; 41 | 42 | return content.Contents! 43 | .Replace("", $"{replacementText0}") 44 | .Replace("", $"{replacementText1}"); 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /src/Jellyfin.Plugin.HomeScreenSections/Helpers/TranslationHelper.cs: -------------------------------------------------------------------------------- 1 | using System.Net.Http.Headers; 2 | using Newtonsoft.Json; 3 | using Newtonsoft.Json.Linq; 4 | 5 | namespace Jellyfin.Plugin.HomeScreenSections.Helpers; 6 | 7 | public static class TranslationHelper 8 | { 9 | public static async Task TranslateAsync(string text, string srcLanguage, string destLanguage) 10 | { 11 | if (HomeScreenSectionsPlugin.Instance.Configuration.LibreTranslateUrl != null) 12 | { 13 | try 14 | { 15 | JObject jsonPayload = new JObject(); 16 | jsonPayload["q"] = text; 17 | jsonPayload["source"] = srcLanguage; 18 | jsonPayload["target"] = destLanguage; 19 | jsonPayload["api_key"] = HomeScreenSectionsPlugin.Instance.Configuration.LibreTranslateApiKey; 20 | 21 | HttpClient client = new HttpClient(); 22 | HttpResponseMessage response = await client.PostAsync( 23 | $"{HomeScreenSectionsPlugin.Instance.Configuration.LibreTranslateUrl}/translate", 24 | new StringContent(jsonPayload.ToString(Formatting.None), 25 | MediaTypeHeaderValue.Parse("application/json"))); 26 | 27 | JObject responseObj = JObject.Parse(await response.Content.ReadAsStringAsync()); 28 | 29 | return responseObj.Value("translatedText"); 30 | } 31 | catch 32 | { 33 | // ignored 34 | } 35 | } 36 | 37 | return text; 38 | } 39 | } -------------------------------------------------------------------------------- /src/Jellyfin.Plugin.HomeScreenSections/HomeScreen/CollectionManagerProxy.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using Jellyfin.Data.Entities; 3 | using MediaBrowser.Controller.Collections; 4 | using MediaBrowser.Controller.Entities.Movies; 5 | 6 | namespace Jellyfin.Plugin.HomeScreenSections.HomeScreen 7 | { 8 | public class CollectionManagerProxy 9 | { 10 | private readonly ICollectionManager m_collectionManager; 11 | 12 | public CollectionManagerProxy(ICollectionManager collectionManager) 13 | { 14 | m_collectionManager = collectionManager; 15 | } 16 | 17 | public IEnumerable GetCollections(User user) 18 | { 19 | return m_collectionManager.GetType() 20 | .GetMethod("GetCollections", BindingFlags.Instance | BindingFlags.NonPublic)? 21 | .Invoke(m_collectionManager, new object?[] 22 | { 23 | user 24 | }) as IEnumerable ?? Enumerable.Empty(); 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /src/Jellyfin.Plugin.HomeScreenSections/HomeScreen/HomeScreenManager.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | using Jellyfin.Plugin.HomeScreenSections.Configuration; 3 | using Jellyfin.Plugin.HomeScreenSections.HomeScreen.Sections; 4 | using Jellyfin.Plugin.HomeScreenSections.Library; 5 | using Jellyfin.Plugin.HomeScreenSections.Model.Dto; 6 | using MediaBrowser.Common.Configuration; 7 | using MediaBrowser.Model.Dto; 8 | using MediaBrowser.Model.Querying; 9 | using Microsoft.AspNetCore.Http; 10 | using Microsoft.Extensions.DependencyInjection; 11 | using Newtonsoft.Json; 12 | using Newtonsoft.Json.Linq; 13 | 14 | namespace Jellyfin.Plugin.HomeScreenSections.HomeScreen 15 | { 16 | /// 17 | /// Manager for the Modular Home Screen. 18 | /// 19 | public class HomeScreenManager : IHomeScreenManager 20 | { 21 | private Dictionary m_delegates = new Dictionary(); 22 | private Dictionary m_userFeatureEnabledStates = new Dictionary(); 23 | 24 | private readonly IServiceProvider m_serviceProvider; 25 | private readonly IApplicationPaths m_applicationPaths; 26 | 27 | private const string c_settingsFile = "ModularHomeSettings.json"; 28 | 29 | /// 30 | /// Constructor. 31 | /// 32 | /// Instance of the interface. 33 | /// Instance of the interface. 34 | public HomeScreenManager(IServiceProvider serviceProvider, IApplicationPaths applicationPaths) 35 | { 36 | m_serviceProvider = serviceProvider; 37 | m_applicationPaths = applicationPaths; 38 | 39 | string userFeatureEnabledPath = Path.Combine(m_applicationPaths.PluginConfigurationsPath, typeof(HomeScreenSectionsPlugin).Namespace!, "userFeatureEnabled.json"); 40 | if (File.Exists(userFeatureEnabledPath)) 41 | { 42 | m_userFeatureEnabledStates = JsonConvert.DeserializeObject>(File.ReadAllText(userFeatureEnabledPath)) ?? new Dictionary(); 43 | } 44 | 45 | RegisterResultsDelegate(); 46 | RegisterResultsDelegate(); 47 | RegisterResultsDelegate(); 48 | RegisterResultsDelegate(); 49 | RegisterResultsDelegate(); 50 | RegisterResultsDelegate(); 51 | RegisterResultsDelegate(); 52 | RegisterResultsDelegate(); 53 | RegisterResultsDelegate(); 54 | RegisterResultsDelegate(); 55 | RegisterResultsDelegate(); 56 | 57 | // Removed from public access while its still in dev. 58 | //RegisterResultsDelegate(); 59 | } 60 | 61 | /// 62 | public IEnumerable GetSectionTypes() 63 | { 64 | return m_delegates.Values; 65 | } 66 | 67 | /// 68 | public QueryResult InvokeResultsDelegate(string key, HomeScreenSectionPayload payload, IQueryCollection queryCollection) 69 | { 70 | if (m_delegates.ContainsKey(key)) 71 | { 72 | return m_delegates[key].GetResults(payload, queryCollection); 73 | } 74 | 75 | return new QueryResult(Array.Empty()); 76 | } 77 | 78 | /// 79 | public void RegisterResultsDelegate() where T : IHomeScreenSection 80 | { 81 | T handler = ActivatorUtilities.CreateInstance(m_serviceProvider); 82 | 83 | RegisterResultsDelegate(handler); 84 | } 85 | 86 | public void RegisterResultsDelegate(T handler) where T : IHomeScreenSection 87 | { 88 | if (handler.Section != null) 89 | { 90 | m_delegates[handler.Section] = handler; 91 | } 92 | } 93 | 94 | public void RegisterResultsDelegate(Type homeScreenSectionType) 95 | { 96 | IHomeScreenSection handler = (IHomeScreenSection)ActivatorUtilities.CreateInstance(m_serviceProvider, homeScreenSectionType); 97 | 98 | if (handler.Section != null) 99 | { 100 | if (!m_delegates.ContainsKey(handler.Section)) 101 | { 102 | m_delegates.Add(handler.Section, handler); 103 | } 104 | else 105 | { 106 | throw new Exception($"Section type '{handler.Section}' has already been registered to type '{m_delegates[handler.Section].GetType().FullName}'."); 107 | } 108 | } 109 | } 110 | 111 | /// 112 | public bool GetUserFeatureEnabled(Guid userId) 113 | { 114 | if (m_userFeatureEnabledStates.ContainsKey(userId)) 115 | { 116 | return m_userFeatureEnabledStates[userId]; 117 | } 118 | 119 | m_userFeatureEnabledStates.Add(userId, false); 120 | 121 | return false; 122 | } 123 | 124 | /// 125 | public void SetUserFeatureEnabled(Guid userId, bool enabled) 126 | { 127 | if (!m_userFeatureEnabledStates.ContainsKey(userId)) 128 | { 129 | m_userFeatureEnabledStates.Add(userId, enabled); 130 | } 131 | 132 | m_userFeatureEnabledStates[userId] = enabled; 133 | 134 | string userFeatureEnabledPath = Path.Combine(m_applicationPaths.PluginConfigurationsPath, typeof(HomeScreenSectionsPlugin).Namespace!, "userFeatureEnabled.json"); 135 | new FileInfo(userFeatureEnabledPath).Directory?.Create(); 136 | File.WriteAllText(userFeatureEnabledPath, JObject.FromObject(m_userFeatureEnabledStates).ToString(Formatting.Indented)); 137 | } 138 | 139 | /// 140 | public ModularHomeUserSettings? GetUserSettings(Guid userId) 141 | { 142 | string pluginSettings = Path.Combine(m_applicationPaths.PluginConfigurationsPath, typeof(HomeScreenSectionsPlugin).Namespace!, c_settingsFile); 143 | 144 | ModularHomeUserSettings? settings = new ModularHomeUserSettings 145 | { 146 | UserId = userId 147 | }; 148 | if (File.Exists(pluginSettings)) 149 | { 150 | JArray settingsArray = JArray.Parse(File.ReadAllText(pluginSettings)); 151 | 152 | if (settingsArray.Select(x => JsonConvert.DeserializeObject(x.ToString())).Any(x => x != null && x.UserId.Equals(userId))) 153 | { 154 | settings = settingsArray.Select(x => JsonConvert.DeserializeObject(x.ToString())).First(x => x != null && x.UserId.Equals(userId)); 155 | } 156 | } 157 | 158 | // If there are none enabled by the user then add all the default enabled settings. 159 | if (settings?.EnabledSections.Count == 0) 160 | { 161 | settings.EnabledSections.AddRange(HomeScreenSectionsPlugin.Instance.Configuration.SectionSettings.Where(x => x.Enabled).Select(x => x.SectionId)); 162 | } 163 | 164 | if (settings != null) 165 | { 166 | IEnumerable forcedSectionSettings = HomeScreenSectionsPlugin.Instance.Configuration.SectionSettings.Where(x => !x.AllowUserOverride); 167 | 168 | foreach (SectionSettings sectionSettings in forcedSectionSettings) 169 | { 170 | if (sectionSettings.Enabled && !settings.EnabledSections.Contains(sectionSettings.SectionId)) 171 | { 172 | settings.EnabledSections.Add(sectionSettings.SectionId); 173 | } 174 | else if (!sectionSettings.Enabled && settings.EnabledSections.Contains(sectionSettings.SectionId)) 175 | { 176 | settings.EnabledSections.Remove(sectionSettings.SectionId); 177 | } 178 | } 179 | } 180 | 181 | return settings; 182 | } 183 | 184 | /// 185 | public bool UpdateUserSettings(Guid userId, ModularHomeUserSettings userSettings) 186 | { 187 | string pluginSettings = Path.Combine(m_applicationPaths.PluginConfigurationsPath, typeof(HomeScreenSectionsPlugin).Namespace!, c_settingsFile); 188 | FileInfo fInfo = new FileInfo(pluginSettings); 189 | fInfo.Directory?.Create(); 190 | 191 | JArray settings = new JArray(); 192 | List newSettings = new List(); 193 | 194 | if (File.Exists(pluginSettings)) 195 | { 196 | settings = JArray.Parse(File.ReadAllText(pluginSettings)); 197 | newSettings = settings.Select(x => JsonConvert.DeserializeObject(x.ToString())).ToList()!; 198 | newSettings.RemoveAll(x => x != null && x.UserId.Equals(userId)); 199 | 200 | newSettings.Add(userSettings); 201 | 202 | settings.Clear(); 203 | } 204 | 205 | foreach (ModularHomeUserSettings? userSetting in newSettings) 206 | { 207 | settings.Add(JObject.FromObject(userSetting ?? new ModularHomeUserSettings())); 208 | } 209 | 210 | File.WriteAllText(pluginSettings, settings.ToString(Formatting.Indented)); 211 | 212 | return true; 213 | } 214 | } 215 | } 216 | -------------------------------------------------------------------------------- /src/Jellyfin.Plugin.HomeScreenSections/HomeScreen/Sections/BecauseYouWatchedSection.cs: -------------------------------------------------------------------------------- 1 | using Jellyfin.Data.Entities; 2 | using Jellyfin.Data.Enums; 3 | using Jellyfin.Plugin.HomeScreenSections.Configuration; 4 | using Jellyfin.Plugin.HomeScreenSections.Library; 5 | using Jellyfin.Plugin.HomeScreenSections.Model.Dto; 6 | using MediaBrowser.Controller.Collections; 7 | using MediaBrowser.Controller.Dto; 8 | using MediaBrowser.Controller.Entities; 9 | using MediaBrowser.Controller.Entities.Movies; 10 | using MediaBrowser.Controller.Library; 11 | using MediaBrowser.Model.Dto; 12 | using MediaBrowser.Model.Entities; 13 | using MediaBrowser.Model.Querying; 14 | using Microsoft.AspNetCore.Http; 15 | 16 | namespace Jellyfin.Plugin.HomeScreenSections.HomeScreen.Sections 17 | { 18 | public class BecauseYouWatchedSection : IHomeScreenSection 19 | { 20 | public string? Section => "BecauseYouWatched"; 21 | 22 | public string? DisplayText { get; set; } = "Because You Watched"; 23 | 24 | public int? Limit => 5; 25 | 26 | public string? Route => null; 27 | 28 | public string? AdditionalData { get; set; } 29 | 30 | public object? OriginalPayload => null; 31 | 32 | private IUserDataManager UserDataManager { get; set; } 33 | private IUserManager UserManager { get; set; } 34 | private ILibraryManager LibraryManager { get; set; } 35 | private IDtoService DtoService { get; set; } 36 | private ICollectionManager CollectionManager { get; set; } 37 | private CollectionManagerProxy CollectionManagerProxy { get; set; } 38 | 39 | public BecauseYouWatchedSection(IUserDataManager userDataManager, IUserManager userManager, ILibraryManager libraryManager, 40 | IDtoService dtoService, ICollectionManager collectionManager, CollectionManagerProxy collectionProxy) 41 | { 42 | UserDataManager = userDataManager; 43 | UserManager = userManager; 44 | LibraryManager = libraryManager; 45 | DtoService = dtoService; 46 | CollectionManager = collectionManager; 47 | CollectionManagerProxy = collectionProxy; 48 | } 49 | 50 | public IHomeScreenSection CreateInstance(Guid? userId, IEnumerable? otherInstances = null) 51 | { 52 | User? user = userId is null || userId.Value.Equals(default) 53 | ? null 54 | : UserManager.GetUserById(userId.Value); 55 | 56 | BecauseYouWatchedSection section = new BecauseYouWatchedSection(UserDataManager, UserManager, LibraryManager, DtoService, CollectionManager, CollectionManagerProxy); 57 | 58 | DtoOptions? dtoOptions = new DtoOptions 59 | { 60 | Fields = new[] 61 | { 62 | ItemFields.PrimaryImageAspectRatio, 63 | ItemFields.MediaSourceCount 64 | } 65 | }; 66 | 67 | InternalItemsQuery? query = new InternalItemsQuery(user) 68 | { 69 | IncludeItemTypes = new[] 70 | { 71 | BaseItemKind.Movie 72 | }, 73 | OrderBy = new[] { (ItemSortBy.DatePlayed, SortOrder.Descending), (ItemSortBy.Random, SortOrder.Descending) }, 74 | Limit = 7, 75 | ParentId = Guid.Empty, 76 | Recursive = true, 77 | IsPlayed = true, 78 | DtoOptions = dtoOptions 79 | }; 80 | 81 | List? recentlyPlayedMovies = LibraryManager.GetItemList(query); 82 | 83 | recentlyPlayedMovies = recentlyPlayedMovies.Where(x => !otherInstances?.Select(y => y.AdditionalData).Contains(x.Id.ToString()) ?? true).Where(x => 84 | { 85 | if (user != null) 86 | { 87 | IEnumerable? collections = CollectionManagerProxy.GetCollections(user) 88 | .Where(y => y.GetChildren(user, true).OfType().Contains(x as Movie)); 89 | 90 | foreach (BoxSet? collection in collections) 91 | { 92 | if (collection.GetChildren(user, true).OfType().Any(y => otherInstances?.Select(z => z.AdditionalData).Contains(y.Id.ToString()) ?? true)) 93 | { 94 | return false; 95 | } 96 | } 97 | } 98 | 99 | return true; 100 | }).ToList(); 101 | 102 | Random rnd = new Random(); 103 | 104 | if (recentlyPlayedMovies.Count == 0) 105 | { 106 | return null!; 107 | } 108 | 109 | BaseItem item = recentlyPlayedMovies.ElementAt(rnd.Next(0, recentlyPlayedMovies.Count)); 110 | 111 | section.AdditionalData = item.Id.ToString(); 112 | section.DisplayText = "Because You Watched " + item.Name; 113 | 114 | return section; 115 | } 116 | 117 | public QueryResult GetResults(HomeScreenSectionPayload payload, IQueryCollection queryCollection) 118 | { 119 | User user = UserManager.GetUserById(payload.UserId)!; 120 | 121 | DtoOptions? dtoOptions = new DtoOptions 122 | { 123 | Fields = new[] 124 | { 125 | ItemFields.PrimaryImageAspectRatio, 126 | ItemFields.MediaSourceCount 127 | }, 128 | ImageTypes = new[] 129 | { 130 | ImageType.Thumb, 131 | ImageType.Backdrop, 132 | ImageType.Primary, 133 | }, 134 | ImageTypeLimit = 1 135 | }; 136 | 137 | BaseItem? item = LibraryManager.GetItemById(Guid.Parse(payload.AdditionalData ?? Guid.Empty.ToString())); 138 | 139 | List? similar = LibraryManager.GetItemList(new InternalItemsQuery(UserManager.GetUserById(payload.UserId)) 140 | { 141 | Limit = 8, 142 | IncludeItemTypes = new[] 143 | { 144 | BaseItemKind.Movie 145 | }, 146 | IsMovie = true, 147 | SimilarTo = item, 148 | User = user, 149 | IsPlayed = false, // Maybe make this configuable but this is the preferred default behaviour. 150 | EnableGroupByMetadataKey = true, 151 | DtoOptions = dtoOptions 152 | }); 153 | 154 | return new QueryResult(DtoService.GetBaseItemDtos(similar, dtoOptions, user)); 155 | } 156 | 157 | public HomeScreenSectionInfo GetInfo() 158 | { 159 | return new HomeScreenSectionInfo 160 | { 161 | Section = Section, 162 | DisplayText = DisplayText, 163 | AdditionalData = AdditionalData, 164 | Route = Route, 165 | Limit = Limit ?? 1, 166 | OriginalPayload = OriginalPayload, 167 | ViewMode = SectionViewMode.Landscape 168 | }; 169 | } 170 | } 171 | } 172 | -------------------------------------------------------------------------------- /src/Jellyfin.Plugin.HomeScreenSections/HomeScreen/Sections/ContinueWatchingSection.cs: -------------------------------------------------------------------------------- 1 | using Jellyfin.Data.Entities; 2 | using Jellyfin.Data.Enums; 3 | using Jellyfin.Plugin.HomeScreenSections.Configuration; 4 | using Jellyfin.Plugin.HomeScreenSections.Library; 5 | using Jellyfin.Plugin.HomeScreenSections.Model.Dto; 6 | using MediaBrowser.Controller.Dto; 7 | using MediaBrowser.Controller.Entities; 8 | using MediaBrowser.Controller.Library; 9 | using MediaBrowser.Controller.Session; 10 | using MediaBrowser.Model.Dto; 11 | using MediaBrowser.Model.Entities; 12 | using MediaBrowser.Model.Querying; 13 | using Microsoft.AspNetCore.Http; 14 | 15 | namespace Jellyfin.Plugin.HomeScreenSections.HomeScreen.Sections 16 | { 17 | /// 18 | /// Continue Watching Section. 19 | /// 20 | public class ContinueWatchingSection : IHomeScreenSection 21 | { 22 | /// 23 | public string? Section => "ContinueWatching"; 24 | 25 | /// 26 | public string? DisplayText { get; set; } = "Continue Watching"; 27 | 28 | /// 29 | public int? Limit => 1; 30 | 31 | /// 32 | public string? Route => null; 33 | 34 | /// 35 | public string? AdditionalData { get; set; } = null; 36 | 37 | public object? OriginalPayload => null; 38 | 39 | private readonly IUserViewManager m_userViewManager; 40 | private readonly IUserManager m_userManager; 41 | private readonly IDtoService m_dtoService; 42 | private readonly ILibraryManager m_libraryManager; 43 | private readonly ISessionManager m_sessionManager; 44 | 45 | /// 46 | /// Constructor. 47 | /// 48 | /// Instance of interface. 49 | /// Instance of interface. 50 | /// Instance of interface. 51 | /// Instance of interface. 52 | /// Instance of interface. 53 | public ContinueWatchingSection(IUserViewManager userViewManager, 54 | IUserManager userManager, 55 | IDtoService dtoService, 56 | ILibraryManager libraryManager, 57 | ISessionManager sessionManager) 58 | { 59 | m_userViewManager = userViewManager; 60 | m_userManager = userManager; 61 | m_dtoService = dtoService; 62 | m_libraryManager = libraryManager; 63 | m_sessionManager = sessionManager; 64 | } 65 | 66 | /// 67 | public QueryResult GetResults(HomeScreenSectionPayload payload, IQueryCollection queryCollection) 68 | { 69 | User? user = m_userManager.GetUserById(payload.UserId); 70 | DtoOptions? dtoOptions = new DtoOptions 71 | { 72 | Fields = new List 73 | { 74 | ItemFields.PrimaryImageAspectRatio 75 | }, 76 | ImageTypeLimit = 1, 77 | ImageTypes = new List 78 | { 79 | ImageType.Thumb, 80 | ImageType.Backdrop, 81 | ImageType.Primary, 82 | } 83 | }; 84 | 85 | Guid[]? ancestorIds = Array.Empty(); 86 | 87 | Guid[]? excludeFolderIds = user!.GetPreferenceValues(PreferenceKind.LatestItemExcludes); 88 | if (excludeFolderIds.Length > 0) 89 | { 90 | ancestorIds = m_libraryManager.GetUserRootFolder().GetChildren(user, true) 91 | .Where(i => i is Folder) 92 | .Where(i => !excludeFolderIds.Contains(i.Id)) 93 | .Select(i => i.Id) 94 | .ToArray(); 95 | } 96 | 97 | QueryResult? itemsResult = m_libraryManager.GetItemsResult(new InternalItemsQuery(user) 98 | { 99 | OrderBy = new[] { (ItemSortBy.DatePlayed, SortOrder.Descending) }, 100 | IsResumable = true, 101 | Limit = 12, 102 | Recursive = true, 103 | DtoOptions = dtoOptions, 104 | MediaTypes = new MediaType[] 105 | { 106 | MediaType.Video 107 | }, 108 | IsVirtualItem = false, 109 | CollapseBoxSetItems = false, 110 | EnableTotalRecordCount = false, 111 | AncestorIds = ancestorIds 112 | }); 113 | 114 | IReadOnlyList? returnItems = m_dtoService.GetBaseItemDtos(itemsResult.Items, dtoOptions, user); 115 | 116 | return new QueryResult( 117 | null, 118 | itemsResult.TotalRecordCount, 119 | returnItems); 120 | } 121 | 122 | /// 123 | public IHomeScreenSection CreateInstance(Guid? userId, IEnumerable? otherInstances = null) 124 | { 125 | return this; 126 | } 127 | 128 | public HomeScreenSectionInfo GetInfo() 129 | { 130 | return new HomeScreenSectionInfo 131 | { 132 | Section = Section, 133 | DisplayText = DisplayText, 134 | AdditionalData = AdditionalData, 135 | Route = Route, 136 | Limit = Limit ?? 1, 137 | OriginalPayload = OriginalPayload, 138 | ViewMode = SectionViewMode.Landscape, 139 | AllowViewModeChange = false 140 | }; 141 | } 142 | } 143 | } 144 | -------------------------------------------------------------------------------- /src/Jellyfin.Plugin.HomeScreenSections/HomeScreen/Sections/LatestMoviesSection.cs: -------------------------------------------------------------------------------- 1 | using Jellyfin.Data.Entities; 2 | using Jellyfin.Data.Enums; 3 | using Jellyfin.Plugin.HomeScreenSections.Configuration; 4 | using Jellyfin.Plugin.HomeScreenSections.Library; 5 | using Jellyfin.Plugin.HomeScreenSections.Model.Dto; 6 | using MediaBrowser.Controller.Dto; 7 | using MediaBrowser.Controller.Entities; 8 | using MediaBrowser.Controller.Library; 9 | using MediaBrowser.Model.Dto; 10 | using MediaBrowser.Model.Entities; 11 | using MediaBrowser.Model.Querying; 12 | using Microsoft.AspNetCore.Http; 13 | 14 | namespace Jellyfin.Plugin.HomeScreenSections.HomeScreen.Sections 15 | { 16 | public class LatestMoviesSection : IHomeScreenSection 17 | { 18 | public string? Section => "LatestMovies"; 19 | 20 | public string? DisplayText { get; set; } = "Latest Movies"; 21 | 22 | public int? Limit => 1; 23 | 24 | public string? Route { get; set; } = null; 25 | 26 | public string? AdditionalData { get; set; } 27 | 28 | public object? OriginalPayload { get; set; } = null; 29 | 30 | private readonly IUserViewManager m_userViewManager; 31 | private readonly IUserManager m_userManager; 32 | private readonly ILibraryManager m_libraryManager; 33 | private readonly IDtoService m_dtoService; 34 | 35 | public LatestMoviesSection(IUserViewManager userViewManager, 36 | IUserManager userManager, 37 | ILibraryManager libraryManager, 38 | IDtoService dtoService) 39 | { 40 | m_userViewManager = userViewManager; 41 | m_userManager = userManager; 42 | m_libraryManager = libraryManager; 43 | m_dtoService = dtoService; 44 | } 45 | 46 | public QueryResult GetResults(HomeScreenSectionPayload payload, IQueryCollection queryCollection) 47 | { 48 | DtoOptions? dtoOptions = new DtoOptions 49 | { 50 | Fields = new List 51 | { 52 | ItemFields.PrimaryImageAspectRatio, 53 | ItemFields.Path 54 | } 55 | }; 56 | 57 | dtoOptions.ImageTypeLimit = 1; 58 | dtoOptions.ImageTypes = new List 59 | { 60 | ImageType.Thumb, 61 | ImageType.Backdrop, 62 | ImageType.Primary, 63 | }; 64 | 65 | User? user = m_userManager.GetUserById(payload.UserId); 66 | 67 | Folder? movieFolder = m_libraryManager.GetUserRootFolder() 68 | .GetChildren(user, true) 69 | .OfType() 70 | .FirstOrDefault(x => (x as ICollectionFolder)?.CollectionType == CollectionType.movies); 71 | 72 | QueryResult? latestMovies = movieFolder?.GetItems(new InternalItemsQuery 73 | { 74 | IncludeItemTypes = new[] 75 | { 76 | BaseItemKind.Movie 77 | }, 78 | Limit = 16, 79 | User = user, 80 | OrderBy = new[] 81 | { 82 | (ItemSortBy.PremiereDate, SortOrder.Descending) 83 | } 84 | }); 85 | 86 | return new QueryResult(Array.ConvertAll(latestMovies?.Items.ToArray() ?? Array.Empty(), 87 | i => m_dtoService.GetBaseItemDto(i, dtoOptions, user))); 88 | } 89 | 90 | public IHomeScreenSection CreateInstance(Guid? userId, IEnumerable? otherInstances = null) 91 | { 92 | return this; 93 | } 94 | 95 | public HomeScreenSectionInfo GetInfo() 96 | { 97 | return new HomeScreenSectionInfo 98 | { 99 | Section = Section, 100 | DisplayText = DisplayText, 101 | AdditionalData = AdditionalData, 102 | Route = Route, 103 | Limit = Limit ?? 1, 104 | OriginalPayload = OriginalPayload, 105 | ViewMode = SectionViewMode.Landscape 106 | }; 107 | } 108 | } 109 | } -------------------------------------------------------------------------------- /src/Jellyfin.Plugin.HomeScreenSections/HomeScreen/Sections/LatestShowsSection.cs: -------------------------------------------------------------------------------- 1 | using Jellyfin.Data.Entities; 2 | using Jellyfin.Data.Enums; 3 | using Jellyfin.Plugin.HomeScreenSections.Configuration; 4 | using Jellyfin.Plugin.HomeScreenSections.Library; 5 | using Jellyfin.Plugin.HomeScreenSections.Model.Dto; 6 | using MediaBrowser.Controller.Dto; 7 | using MediaBrowser.Controller.Entities; 8 | using MediaBrowser.Controller.Entities.TV; 9 | using MediaBrowser.Controller.Library; 10 | using MediaBrowser.Controller.TV; 11 | using MediaBrowser.Model.Dto; 12 | using MediaBrowser.Model.Entities; 13 | using MediaBrowser.Model.Querying; 14 | using Microsoft.AspNetCore.Http; 15 | 16 | namespace Jellyfin.Plugin.HomeScreenSections.HomeScreen.Sections 17 | { 18 | public class LatestShowsSection : IHomeScreenSection 19 | { 20 | public string? Section => "LatestShows"; 21 | 22 | public string? DisplayText { get; set; } = "Latest Shows"; 23 | 24 | public int? Limit => 1; 25 | 26 | public string? Route { get; } 27 | 28 | public string? AdditionalData { get; set; } 29 | 30 | public object? OriginalPayload { get; } 31 | 32 | private readonly IUserViewManager m_userViewManager; 33 | private readonly IUserManager m_userManager; 34 | private readonly ILibraryManager m_libraryManager; 35 | private readonly ITVSeriesManager m_tvSeriesManager; 36 | private readonly IDtoService m_dtoService; 37 | 38 | public LatestShowsSection(IUserViewManager userViewManager, 39 | IUserManager userManager, 40 | ILibraryManager libraryManager, 41 | ITVSeriesManager tvSeriesManager, 42 | IDtoService dtoService) 43 | { 44 | m_userViewManager = userViewManager; 45 | m_userManager = userManager; 46 | m_libraryManager = libraryManager; 47 | m_tvSeriesManager = tvSeriesManager; 48 | m_dtoService = dtoService; 49 | } 50 | 51 | public QueryResult GetResults(HomeScreenSectionPayload payload, IQueryCollection queryCollection) 52 | { 53 | DtoOptions? dtoOptions = new DtoOptions 54 | { 55 | Fields = new List 56 | { 57 | ItemFields.PrimaryImageAspectRatio, 58 | ItemFields.Path 59 | } 60 | }; 61 | 62 | dtoOptions.ImageTypeLimit = 1; 63 | dtoOptions.ImageTypes = new List 64 | { 65 | ImageType.Thumb, 66 | ImageType.Backdrop, 67 | ImageType.Primary, 68 | }; 69 | 70 | User? user = m_userManager.GetUserById(payload.UserId); 71 | 72 | List episodes = m_libraryManager.GetItemList(new InternalItemsQuery(user) 73 | { 74 | IncludeItemTypes = new[] { BaseItemKind.Episode }, 75 | OrderBy = new[] { (ItemSortBy.PremiereDate, SortOrder.Descending) }, 76 | DtoOptions = new DtoOptions 77 | { Fields = new[] { ItemFields.SeriesPresentationUniqueKey }, EnableImages = false } 78 | }); 79 | 80 | List series = episodes 81 | .Where(x => !x.IsUnaired && !x.IsVirtualItem) 82 | .Select(x => (x.FindParent(), (x as Episode)?.PremiereDate)) 83 | .GroupBy(x => x.Item1) 84 | .Select(x => (x.Key, x.Max(y => y.PremiereDate))) 85 | .OrderByDescending(x => x.Item2) 86 | .Select(x => x.Key as BaseItem) 87 | .Take(16) 88 | .ToList(); 89 | 90 | return new QueryResult(Array.ConvertAll(series.ToArray(), 91 | i => m_dtoService.GetBaseItemDto(i, dtoOptions, user))); 92 | } 93 | 94 | public IHomeScreenSection CreateInstance(Guid? userId, IEnumerable? otherInstances = null) 95 | { 96 | return this; 97 | } 98 | 99 | public HomeScreenSectionInfo GetInfo() 100 | { 101 | return new HomeScreenSectionInfo 102 | { 103 | Section = Section, 104 | DisplayText = DisplayText, 105 | AdditionalData = AdditionalData, 106 | Route = Route, 107 | Limit = Limit ?? 1, 108 | OriginalPayload = OriginalPayload, 109 | ViewMode = SectionViewMode.Landscape 110 | }; 111 | } 112 | } 113 | } -------------------------------------------------------------------------------- /src/Jellyfin.Plugin.HomeScreenSections/HomeScreen/Sections/LiveTvSection.cs: -------------------------------------------------------------------------------- 1 | using Jellyfin.Data.Entities; 2 | using Jellyfin.Plugin.HomeScreenSections.Configuration; 3 | using Jellyfin.Plugin.HomeScreenSections.Library; 4 | using Jellyfin.Plugin.HomeScreenSections.Model.Dto; 5 | using MediaBrowser.Controller.Dto; 6 | using MediaBrowser.Controller.Entities; 7 | using MediaBrowser.Controller.Library; 8 | using MediaBrowser.Controller.LiveTv; 9 | using MediaBrowser.Model.Dto; 10 | using MediaBrowser.Model.Entities; 11 | using MediaBrowser.Model.Querying; 12 | using Microsoft.AspNetCore.Http; 13 | 14 | namespace Jellyfin.Plugin.HomeScreenSections.HomeScreen.Sections 15 | { 16 | internal class LiveTvSection : IHomeScreenSection 17 | { 18 | public string? Section => "LiveTV"; 19 | 20 | public string? DisplayText { get; set; } = "Live TV"; 21 | 22 | public int? Limit => 1; 23 | 24 | public string? Route => null; 25 | 26 | public string? AdditionalData { get; set; } 27 | 28 | public object? OriginalPayload => null; 29 | 30 | private IUserManager UserManager { get; set; } 31 | 32 | private IDtoService DtoService { get; set; } 33 | 34 | private ILiveTvManager LiveTvManager { get; set; } 35 | 36 | public LiveTvSection(IUserManager userManager, IDtoService dtoService, ILiveTvManager liveTvManager) 37 | { 38 | UserManager = userManager; 39 | DtoService = dtoService; 40 | LiveTvManager = liveTvManager; 41 | } 42 | 43 | public IHomeScreenSection CreateInstance(Guid? userId, IEnumerable? otherInstances = null) 44 | { 45 | return this; 46 | } 47 | 48 | public QueryResult GetResults(HomeScreenSectionPayload payload, IQueryCollection queryCollection) 49 | { 50 | DtoOptions? dtoOptions = new DtoOptions 51 | { 52 | Fields = new List 53 | { 54 | ItemFields.PrimaryImageAspectRatio 55 | }, 56 | ImageTypeLimit = 1, 57 | ImageTypes = new List 58 | { 59 | ImageType.Thumb, 60 | ImageType.Backdrop, 61 | ImageType.Primary, 62 | } 63 | }; 64 | 65 | User user = UserManager.GetUserById(payload.UserId)!; 66 | 67 | return LiveTvManager.GetRecommendedProgramsAsync(new InternalItemsQuery(user) 68 | { 69 | Limit = 24, 70 | EnableTotalRecordCount = false, 71 | IsAiring = true, 72 | User = user 73 | }, dtoOptions, CancellationToken.None).ConfigureAwait(false).GetAwaiter().GetResult(); 74 | } 75 | 76 | public HomeScreenSectionInfo GetInfo() 77 | { 78 | return new HomeScreenSectionInfo 79 | { 80 | Section = Section, 81 | DisplayText = DisplayText, 82 | AdditionalData = AdditionalData, 83 | Route = Route, 84 | Limit = Limit ?? 1, 85 | OriginalPayload = OriginalPayload, 86 | ViewMode = SectionViewMode.Landscape 87 | }; 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/Jellyfin.Plugin.HomeScreenSections/HomeScreen/Sections/MyListSection.cs: -------------------------------------------------------------------------------- 1 | using Jellyfin.Data.Entities; 2 | using Jellyfin.Plugin.HomeScreenSections.Configuration; 3 | using Jellyfin.Plugin.HomeScreenSections.Library; 4 | using Jellyfin.Plugin.HomeScreenSections.Model.Dto; 5 | using MediaBrowser.Controller.Dto; 6 | using MediaBrowser.Controller.Entities; 7 | using MediaBrowser.Controller.Library; 8 | using MediaBrowser.Controller.Playlists; 9 | using MediaBrowser.Model.Dto; 10 | using MediaBrowser.Model.Entities; 11 | using MediaBrowser.Model.Querying; 12 | using Microsoft.AspNetCore.Http; 13 | 14 | namespace Jellyfin.Plugin.HomeScreenSections.HomeScreen.Sections 15 | { 16 | internal class MyListSection : IHomeScreenSection 17 | { 18 | public string? Section => "MyList"; 19 | 20 | public string? DisplayText { get; set; } = "My List"; 21 | 22 | public int? Limit => 1; 23 | 24 | public string? Route => null; 25 | 26 | public string? AdditionalData { get; set; } 27 | 28 | public object? OriginalPayload => null; 29 | 30 | private IUserManager UserManager { get; set; } 31 | 32 | private IDtoService DtoService { get; set; } 33 | 34 | private IPlaylistManager PlaylistManager { get; set; } 35 | 36 | public MyListSection(IUserManager userManager, IDtoService dtoService, IPlaylistManager playlistManager) 37 | { 38 | UserManager = userManager; 39 | DtoService = dtoService; 40 | PlaylistManager = playlistManager; 41 | } 42 | 43 | public IHomeScreenSection CreateInstance(Guid? userId, IEnumerable? otherInstances = null) 44 | { 45 | return this; 46 | } 47 | 48 | public QueryResult GetResults(HomeScreenSectionPayload payload, IQueryCollection queryCollection) 49 | { 50 | DtoOptions? dtoOptions = new DtoOptions 51 | { 52 | Fields = new List 53 | { 54 | ItemFields.PrimaryImageAspectRatio 55 | }, 56 | ImageTypeLimit = 1, 57 | ImageTypes = new List 58 | { 59 | ImageType.Thumb, 60 | ImageType.Backdrop, 61 | ImageType.Primary, 62 | } 63 | }; 64 | 65 | User user = UserManager.GetUserById(payload.UserId)!; 66 | 67 | IEnumerable playlists = PlaylistManager.GetPlaylists(user.Id); 68 | Playlist? myListPlaylist = playlists.FirstOrDefault(x => x.Name == "My List"); 69 | 70 | List results = new List(); 71 | 72 | if (myListPlaylist != null) 73 | { 74 | results.AddRange(myListPlaylist.GetChildren(user, true, new InternalItemsQuery(user) 75 | { 76 | IsAiring = true 77 | })); 78 | } 79 | 80 | QueryResult? result = new QueryResult(DtoService.GetBaseItemDtos(results, dtoOptions, user)); 81 | 82 | return result; 83 | } 84 | 85 | public HomeScreenSectionInfo GetInfo() 86 | { 87 | return new HomeScreenSectionInfo 88 | { 89 | Section = Section, 90 | DisplayText = DisplayText, 91 | AdditionalData = AdditionalData, 92 | Route = Route, 93 | Limit = Limit ?? 1, 94 | OriginalPayload = OriginalPayload, 95 | ViewMode = SectionViewMode.Landscape 96 | }; 97 | } 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /src/Jellyfin.Plugin.HomeScreenSections/HomeScreen/Sections/MyMediaSection.cs: -------------------------------------------------------------------------------- 1 | using Jellyfin.Data.Entities; 2 | using Jellyfin.Plugin.HomeScreenSections.Configuration; 3 | using Jellyfin.Plugin.HomeScreenSections.Library; 4 | using Jellyfin.Plugin.HomeScreenSections.Model.Dto; 5 | using MediaBrowser.Controller.Dto; 6 | using MediaBrowser.Controller.Entities; 7 | using MediaBrowser.Controller.Library; 8 | using MediaBrowser.Model.Dto; 9 | using MediaBrowser.Model.Library; 10 | using MediaBrowser.Model.Querying; 11 | using Microsoft.AspNetCore.Http; 12 | 13 | namespace Jellyfin.Plugin.HomeScreenSections.HomeScreen.Sections 14 | { 15 | /// 16 | /// My Media Section. 17 | /// 18 | public class MyMediaSection : IHomeScreenSection 19 | { 20 | /// 21 | public string Section => "MyMedia"; 22 | 23 | /// 24 | public string? DisplayText { get; set; } = "My Media"; 25 | 26 | /// 27 | public int? Limit => 1; 28 | 29 | /// 30 | public string? Route => null; 31 | 32 | /// 33 | public string? AdditionalData { get; set; } = null; 34 | 35 | public object? OriginalPayload => null; 36 | 37 | private readonly IUserViewManager m_userViewManager; 38 | private readonly IUserManager m_userManager; 39 | private readonly IDtoService m_dtoService; 40 | 41 | /// 42 | /// Constructor. 43 | /// 44 | /// Instance of interface. 45 | /// Instance of interface. 46 | /// Instance of interface. 47 | public MyMediaSection(IUserViewManager userViewManager, 48 | IUserManager userManager, 49 | IDtoService dtoService) 50 | { 51 | m_userViewManager = userViewManager; 52 | m_userManager = userManager; 53 | m_dtoService = dtoService; 54 | } 55 | 56 | /// 57 | public QueryResult GetResults(HomeScreenSectionPayload payload, IQueryCollection queryCollection) 58 | { 59 | User? user = m_userManager.GetUserById(payload.UserId); 60 | 61 | if (user == null) 62 | { 63 | return new QueryResult(); 64 | } 65 | 66 | UserViewQuery query = new UserViewQuery 67 | { 68 | User = user, 69 | IncludeHidden = false 70 | }; 71 | 72 | Folder[]? folders = m_userViewManager.GetUserViews(query); 73 | 74 | DtoOptions dtoOptions = new DtoOptions(); 75 | List f = new List 76 | { 77 | ItemFields.PrimaryImageAspectRatio, 78 | ItemFields.DisplayPreferencesId 79 | }; 80 | 81 | dtoOptions.Fields = f.ToArray(); 82 | 83 | BaseItemDto[] dtos = folders.Select(i => m_dtoService.GetBaseItemDto(i, dtoOptions, user)) 84 | .ToArray(); 85 | 86 | return new QueryResult(dtos); 87 | } 88 | 89 | /// 90 | public IHomeScreenSection CreateInstance(Guid? userId, IEnumerable? otherInstances = null) 91 | { 92 | return this; 93 | } 94 | 95 | public HomeScreenSectionInfo GetInfo() 96 | { 97 | return new HomeScreenSectionInfo 98 | { 99 | Section = Section, 100 | DisplayText = DisplayText, 101 | AdditionalData = AdditionalData, 102 | Route = Route, 103 | Limit = Limit ?? 1, 104 | OriginalPayload = OriginalPayload, 105 | ViewMode = SectionViewMode.Landscape, 106 | AllowViewModeChange = false 107 | }; 108 | } 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /src/Jellyfin.Plugin.HomeScreenSections/HomeScreen/Sections/NextUpSection.cs: -------------------------------------------------------------------------------- 1 | using Jellyfin.Data.Entities; 2 | using Jellyfin.Plugin.HomeScreenSections.Configuration; 3 | using Jellyfin.Plugin.HomeScreenSections.Library; 4 | using Jellyfin.Plugin.HomeScreenSections.Model.Dto; 5 | using MediaBrowser.Controller.Dto; 6 | using MediaBrowser.Controller.Entities; 7 | using MediaBrowser.Controller.Library; 8 | using MediaBrowser.Controller.Session; 9 | using MediaBrowser.Controller.TV; 10 | using MediaBrowser.Model.Dto; 11 | using MediaBrowser.Model.Entities; 12 | using MediaBrowser.Model.Querying; 13 | using Microsoft.AspNetCore.Http; 14 | using Microsoft.Extensions.Primitives; 15 | 16 | namespace Jellyfin.Plugin.HomeScreenSections.HomeScreen.Sections 17 | { 18 | /// 19 | /// Next Up Section. 20 | /// 21 | public class NextUpSection : IHomeScreenSection 22 | { 23 | /// 24 | public string Section => "NextUp"; 25 | 26 | /// 27 | public string? DisplayText { get; set; } = "Next Up"; 28 | 29 | /// 30 | public int? Limit => 1; 31 | 32 | /// 33 | public string? Route => "nextup"; 34 | 35 | /// 36 | public string? AdditionalData { get; set; } = null; 37 | 38 | public object? OriginalPayload => null; 39 | 40 | private readonly IUserViewManager m_userViewManager; 41 | private readonly IUserManager m_userManager; 42 | private readonly IDtoService m_dtoService; 43 | private readonly ILibraryManager m_libraryManager; 44 | private readonly ISessionManager m_sessionManager; 45 | private readonly ITVSeriesManager m_tvSeriesManager; 46 | 47 | /// 48 | /// Constructor. 49 | /// 50 | /// Instance of interface. 51 | /// Instance of interface. 52 | /// Instance of interface. 53 | /// Instance of interface. 54 | /// Instance of interface. 55 | /// Instance of interface. 56 | public NextUpSection(IUserViewManager userViewManager, 57 | IUserManager userManager, 58 | IDtoService dtoService, 59 | ILibraryManager libraryManager, 60 | ISessionManager sessionManager, 61 | ITVSeriesManager tvSeriesManager) 62 | { 63 | m_userViewManager = userViewManager; 64 | m_userManager = userManager; 65 | m_dtoService = dtoService; 66 | m_libraryManager = libraryManager; 67 | m_sessionManager = sessionManager; 68 | m_tvSeriesManager = tvSeriesManager; 69 | } 70 | 71 | /// 72 | public QueryResult GetResults(HomeScreenSectionPayload payload, IQueryCollection queryCollection) 73 | { 74 | User? user = m_userManager.GetUserById(payload.UserId); 75 | 76 | List fields = new List 77 | { 78 | ItemFields.PrimaryImageAspectRatio, 79 | ItemFields.DateCreated, 80 | ItemFields.Path, 81 | ItemFields.MediaSourceCount 82 | }; 83 | 84 | DtoOptions options = new DtoOptions { Fields = fields }; 85 | options.ImageTypeLimit = 1; 86 | options.ImageTypes = new List 87 | { 88 | ImageType.Thumb, 89 | ImageType.Backdrop, 90 | ImageType.Primary, 91 | }; 92 | 93 | bool enableRewatching = true; // Enabled by default 94 | if (queryCollection.TryGetValue("EnableRewatching", out StringValues enableRewatchingValue)) 95 | { 96 | enableRewatching = enableRewatchingValue.FirstOrDefault() == "true"; 97 | } 98 | 99 | DateTime nextUpDateCutoff = DateTime.MinValue; 100 | if (queryCollection.TryGetValue("NextUpDateCutoff", out StringValues nextUpDateCutoffValue)) 101 | { 102 | if (DateTime.TryParse(nextUpDateCutoffValue.FirstOrDefault(), out DateTime nextUpDateCutoffParsed)) 103 | { 104 | nextUpDateCutoff = nextUpDateCutoffParsed; 105 | } 106 | } 107 | 108 | QueryResult result = m_tvSeriesManager.GetNextUp( 109 | new NextUpQuery 110 | { 111 | Limit = 24, 112 | SeriesId = null, 113 | StartIndex = null, 114 | User = user!, 115 | EnableTotalRecordCount = false, 116 | DisableFirstEpisode = true, 117 | NextUpDateCutoff = nextUpDateCutoff, 118 | EnableRewatching = enableRewatching 119 | }, 120 | options); 121 | 122 | IReadOnlyList returnItems = m_dtoService.GetBaseItemDtos(result.Items, options, user); 123 | 124 | return new QueryResult( 125 | null, 126 | result.TotalRecordCount, 127 | returnItems); 128 | } 129 | 130 | /// 131 | public IHomeScreenSection CreateInstance(Guid? userId, IEnumerable? otherInstances = null) 132 | { 133 | return this; 134 | } 135 | 136 | public HomeScreenSectionInfo GetInfo() 137 | { 138 | return new HomeScreenSectionInfo 139 | { 140 | Section = Section, 141 | DisplayText = DisplayText, 142 | AdditionalData = AdditionalData, 143 | Route = Route, 144 | Limit = Limit ?? 1, 145 | OriginalPayload = OriginalPayload, 146 | ViewMode = SectionViewMode.Landscape 147 | }; 148 | } 149 | } 150 | } 151 | -------------------------------------------------------------------------------- /src/Jellyfin.Plugin.HomeScreenSections/HomeScreen/Sections/PluginDefinedSection.cs: -------------------------------------------------------------------------------- 1 | using Jellyfin.Plugin.HomeScreenSections.Configuration; 2 | using Jellyfin.Plugin.HomeScreenSections.Library; 3 | using Jellyfin.Plugin.HomeScreenSections.Model.Dto; 4 | using MediaBrowser.Model.Dto; 5 | using MediaBrowser.Model.Querying; 6 | using Microsoft.AspNetCore.Http; 7 | 8 | namespace Jellyfin.Plugin.HomeScreenSections.HomeScreen.Sections 9 | { 10 | public class PluginDefinedSection : IHomeScreenSection 11 | { 12 | public delegate QueryResult GetResultsDelegate(HomeScreenSectionPayload payload); 13 | 14 | public string? Section { get; } 15 | public string? DisplayText { get; set; } 16 | public int? Limit { get; } 17 | public string? Route { get; } 18 | public string? AdditionalData { get; set; } 19 | 20 | public object? OriginalPayload => null; 21 | 22 | public required GetResultsDelegate OnGetResults { get; set; } 23 | 24 | public PluginDefinedSection(string sectionUuid, string displayText, string? route = null, string? additionalData = null) 25 | { 26 | Section = sectionUuid; 27 | DisplayText = displayText; 28 | Limit = 1; 29 | Route = route; 30 | AdditionalData = additionalData; 31 | } 32 | 33 | public QueryResult GetResults(HomeScreenSectionPayload payload, IQueryCollection queryCollection) 34 | { 35 | return OnGetResults(payload); 36 | } 37 | 38 | public IHomeScreenSection CreateInstance(Guid? userId, IEnumerable? otherInstances = null) 39 | { 40 | return this; 41 | } 42 | 43 | public HomeScreenSectionInfo GetInfo() 44 | { 45 | return new HomeScreenSectionInfo 46 | { 47 | Section = Section, 48 | DisplayText = DisplayText, 49 | AdditionalData = AdditionalData, 50 | Route = Route, 51 | Limit = Limit ?? 1, 52 | OriginalPayload = OriginalPayload, 53 | ViewMode = SectionViewMode.Landscape 54 | }; 55 | } 56 | } 57 | } -------------------------------------------------------------------------------- /src/Jellyfin.Plugin.HomeScreenSections/HomeScreen/Sections/RecentlyAddedMoviesSection.cs: -------------------------------------------------------------------------------- 1 | using Jellyfin.Data.Entities; 2 | using Jellyfin.Data.Enums; 3 | using Jellyfin.Plugin.HomeScreenSections.Configuration; 4 | using Jellyfin.Plugin.HomeScreenSections.Library; 5 | using Jellyfin.Plugin.HomeScreenSections.Model.Dto; 6 | using MediaBrowser.Controller.Dto; 7 | using MediaBrowser.Controller.Entities; 8 | using MediaBrowser.Controller.Entities.Audio; 9 | using MediaBrowser.Controller.Library; 10 | using MediaBrowser.Model.Dto; 11 | using MediaBrowser.Model.Entities; 12 | using MediaBrowser.Model.Querying; 13 | using Microsoft.AspNetCore.Http; 14 | 15 | namespace Jellyfin.Plugin.HomeScreenSections.HomeScreen.Sections 16 | { 17 | /// 18 | /// Latest Movies Section. 19 | /// 20 | public class RecentlyAddedMoviesSection : IHomeScreenSection 21 | { 22 | /// 23 | public string? Section => "RecentlyAddedMovies"; 24 | 25 | /// 26 | public string? DisplayText { get; set; } = "Recently Added Movies"; 27 | 28 | /// 29 | public int? Limit => 1; 30 | 31 | /// 32 | public string? Route => "movies"; 33 | 34 | /// 35 | public string? AdditionalData { get; set; } = "movies"; 36 | 37 | public object? OriginalPayload { get; set; } = null; 38 | 39 | private readonly IUserViewManager m_userViewManager; 40 | private readonly IUserManager m_userManager; 41 | private readonly ILibraryManager m_libraryManager; 42 | private readonly IDtoService m_dtoService; 43 | 44 | /// 45 | /// Constructor. 46 | /// 47 | /// Instance of interface. 48 | /// Instance of interface. 49 | /// Instance of interface. 50 | public RecentlyAddedMoviesSection(IUserViewManager userViewManager, 51 | IUserManager userManager, 52 | ILibraryManager libraryManager, 53 | IDtoService dtoService) 54 | { 55 | m_userViewManager = userViewManager; 56 | m_userManager = userManager; 57 | m_libraryManager = libraryManager; 58 | m_dtoService = dtoService; 59 | } 60 | 61 | /// 62 | public QueryResult GetResults(HomeScreenSectionPayload payload, IQueryCollection queryCollection) 63 | { 64 | User? user = m_userManager.GetUserById(payload.UserId); 65 | 66 | DtoOptions? dtoOptions = new DtoOptions 67 | { 68 | Fields = new List 69 | { 70 | ItemFields.PrimaryImageAspectRatio, 71 | ItemFields.Path 72 | } 73 | }; 74 | 75 | dtoOptions.ImageTypeLimit = 1; 76 | dtoOptions.ImageTypes = new List 77 | { 78 | ImageType.Thumb, 79 | ImageType.Backdrop, 80 | ImageType.Primary, 81 | }; 82 | 83 | MyMediaSection myMedia = new MyMediaSection(m_userViewManager, m_userManager, m_dtoService); 84 | QueryResult media = myMedia.GetResults(payload, queryCollection); 85 | 86 | Guid parentId = media.Items.FirstOrDefault(x => x.Name == payload.AdditionalData)?.Id ?? Guid.Empty; 87 | 88 | List>>? list = m_userViewManager.GetLatestItems( 89 | new LatestItemsQuery 90 | { 91 | GroupItems = false, 92 | Limit = 16, 93 | ParentId = parentId, 94 | User = user, 95 | IncludeItemTypes = new BaseItemKind[] 96 | { 97 | BaseItemKind.Movie 98 | } 99 | }, 100 | dtoOptions); 101 | 102 | IEnumerable? dtos = list.Select(i => 103 | { 104 | BaseItem? item = i.Item2[0]; 105 | int childCount = 0; 106 | 107 | if (i.Item1 != null && (i.Item2.Count > 1 || i.Item1 is MusicAlbum)) 108 | { 109 | item = i.Item1; 110 | childCount = i.Item2.Count; 111 | } 112 | 113 | BaseItemDto? dto = m_dtoService.GetBaseItemDto(item, dtoOptions, user); 114 | 115 | dto.ChildCount = childCount; 116 | 117 | return dto; 118 | }); 119 | 120 | return new QueryResult(dtos.ToList()); 121 | } 122 | 123 | /// 124 | public IHomeScreenSection CreateInstance(Guid? userId, IEnumerable? otherInstances = null) 125 | { 126 | User? user = m_userManager.GetUserById(userId ?? Guid.Empty); 127 | 128 | Folder? folder = m_libraryManager.GetUserRootFolder() 129 | .GetChildren(user, true) 130 | .OfType() 131 | .Select(x => x as ICollectionFolder) 132 | .Where(x => x != null) 133 | .FirstOrDefault(x => x!.CollectionType == CollectionType.movies) as Folder; 134 | 135 | BaseItemDto? originalPayload = null; 136 | if (folder != null) 137 | { 138 | DtoOptions dtoOptions = new DtoOptions(); 139 | dtoOptions.Fields = 140 | [..dtoOptions.Fields, ItemFields.PrimaryImageAspectRatio, ItemFields.DisplayPreferencesId]; 141 | 142 | originalPayload = Array.ConvertAll(new[] { folder }, i => m_dtoService.GetBaseItemDto(i, dtoOptions, user)).First(); 143 | } 144 | 145 | return new RecentlyAddedMoviesSection(m_userViewManager, m_userManager, m_libraryManager, m_dtoService) 146 | { 147 | AdditionalData = AdditionalData, 148 | DisplayText = DisplayText, 149 | OriginalPayload = originalPayload 150 | }; 151 | } 152 | 153 | public HomeScreenSectionInfo GetInfo() 154 | { 155 | return new HomeScreenSectionInfo 156 | { 157 | Section = Section, 158 | DisplayText = DisplayText, 159 | AdditionalData = AdditionalData, 160 | Route = Route, 161 | Limit = Limit ?? 1, 162 | OriginalPayload = OriginalPayload, 163 | ViewMode = SectionViewMode.Landscape 164 | }; 165 | } 166 | } 167 | } 168 | -------------------------------------------------------------------------------- /src/Jellyfin.Plugin.HomeScreenSections/HomeScreen/Sections/RecentlyAddedShowsSection.cs: -------------------------------------------------------------------------------- 1 | using Jellyfin.Data.Entities; 2 | using Jellyfin.Data.Enums; 3 | using Jellyfin.Plugin.HomeScreenSections.Configuration; 4 | using Jellyfin.Plugin.HomeScreenSections.Library; 5 | using Jellyfin.Plugin.HomeScreenSections.Model.Dto; 6 | using MediaBrowser.Controller.Dto; 7 | using MediaBrowser.Controller.Entities; 8 | using MediaBrowser.Controller.Entities.Audio; 9 | using MediaBrowser.Controller.Entities.TV; 10 | using MediaBrowser.Controller.Library; 11 | using MediaBrowser.Model.Dto; 12 | using MediaBrowser.Model.Entities; 13 | using MediaBrowser.Model.Querying; 14 | using Microsoft.AspNetCore.Http; 15 | 16 | namespace Jellyfin.Plugin.HomeScreenSections.HomeScreen.Sections 17 | { 18 | 19 | 20 | 21 | public class RecentlyAddedShowsSection : IHomeScreenSection 22 | { 23 | 24 | public string? Section => "RecentlyAddedShows"; 25 | 26 | 27 | public string? DisplayText { get; set; } = "Recently Added Shows"; 28 | 29 | 30 | public int? Limit => 1; 31 | 32 | 33 | public string? Route => "tvshows"; 34 | 35 | 36 | public string? AdditionalData { get; set; } = "tvshows"; 37 | 38 | public object? OriginalPayload { get; set; } = null; 39 | 40 | private readonly IUserViewManager m_userViewManager; 41 | private readonly IUserManager m_userManager; 42 | private readonly ILibraryManager m_libraryManager; 43 | private readonly IDtoService m_dtoService; 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | public RecentlyAddedShowsSection(IUserViewManager userViewManager, 52 | IUserManager userManager, 53 | ILibraryManager libraryManager, 54 | IDtoService dtoService) 55 | { 56 | m_userViewManager = userViewManager; 57 | m_userManager = userManager; 58 | m_libraryManager = libraryManager; 59 | m_dtoService = dtoService; 60 | } 61 | 62 | 63 | public QueryResult GetResults(HomeScreenSectionPayload payload, IQueryCollection queryCollection) 64 | { 65 | User? user = m_userManager.GetUserById(payload.UserId); 66 | 67 | DtoOptions? dtoOptions = new DtoOptions 68 | { 69 | Fields = new List 70 | { 71 | ItemFields.PrimaryImageAspectRatio, 72 | ItemFields.Path 73 | } 74 | }; 75 | 76 | dtoOptions.ImageTypeLimit = 1; 77 | dtoOptions.ImageTypes = new List 78 | { 79 | ImageType.Thumb, 80 | ImageType.Backdrop, 81 | ImageType.Primary, 82 | }; 83 | 84 | List episodes = m_libraryManager.GetItemList(new InternalItemsQuery(user) 85 | { 86 | IncludeItemTypes = new[] { BaseItemKind.Episode }, 87 | OrderBy = new[] { (ItemSortBy.DateCreated, SortOrder.Descending) }, 88 | DtoOptions = new DtoOptions 89 | { Fields = new[] { ItemFields.SeriesPresentationUniqueKey }, EnableImages = false } 90 | }); 91 | 92 | List series = episodes 93 | .Where(x => !x.IsUnaired && !x.IsVirtualItem) 94 | .Select(x => (x.FindParent(), (x as Episode)?.DateCreated)) 95 | .GroupBy(x => x.Item1) 96 | .Select(x => (x.Key, x.Max(y => y.DateCreated))) 97 | .OrderByDescending(x => x.Item2) 98 | .Select(x => x.Key as BaseItem) 99 | .Take(16) 100 | .ToList(); 101 | 102 | return new QueryResult(Array.ConvertAll(series.ToArray(), 103 | i => m_dtoService.GetBaseItemDto(i, dtoOptions, user))); 104 | } 105 | 106 | 107 | public IHomeScreenSection CreateInstance(Guid? userId, IEnumerable? otherInstances = null) 108 | { 109 | User? user = m_userManager.GetUserById(userId ?? Guid.Empty); 110 | 111 | Folder? folder = m_libraryManager.GetUserRootFolder() 112 | .GetChildren(user, true) 113 | .OfType() 114 | .Select(x => x as ICollectionFolder) 115 | .Where(x => x != null) 116 | .FirstOrDefault(x => x!.CollectionType == CollectionType.tvshows) as Folder; 117 | 118 | BaseItemDto? originalPayload = null; 119 | if (folder != null) 120 | { 121 | DtoOptions dtoOptions = new DtoOptions(); 122 | dtoOptions.Fields = 123 | [..dtoOptions.Fields, ItemFields.PrimaryImageAspectRatio, ItemFields.DisplayPreferencesId]; 124 | 125 | originalPayload = Array.ConvertAll(new[] { folder }, i => m_dtoService.GetBaseItemDto(i, dtoOptions, user)).First(); 126 | } 127 | 128 | return new RecentlyAddedShowsSection(m_userViewManager, m_userManager, m_libraryManager, m_dtoService) 129 | { 130 | AdditionalData = AdditionalData, 131 | DisplayText = DisplayText, 132 | OriginalPayload = originalPayload 133 | }; 134 | } 135 | 136 | public HomeScreenSectionInfo GetInfo() 137 | { 138 | return new HomeScreenSectionInfo 139 | { 140 | Section = Section, 141 | DisplayText = DisplayText, 142 | AdditionalData = AdditionalData, 143 | Route = Route, 144 | Limit = Limit ?? 1, 145 | OriginalPayload = OriginalPayload, 146 | ViewMode = SectionViewMode.Landscape 147 | }; 148 | } 149 | } 150 | } 151 | -------------------------------------------------------------------------------- /src/Jellyfin.Plugin.HomeScreenSections/HomeScreen/Sections/TopTenSection.cs: -------------------------------------------------------------------------------- 1 | using Jellyfin.Data.Entities; 2 | using Jellyfin.Plugin.HomeScreenSections.Configuration; 3 | using Jellyfin.Plugin.HomeScreenSections.Helpers; 4 | using Jellyfin.Plugin.HomeScreenSections.Library; 5 | using Jellyfin.Plugin.HomeScreenSections.Model.Dto; 6 | using MediaBrowser.Controller.Collections; 7 | using MediaBrowser.Controller.Dto; 8 | using MediaBrowser.Controller.Entities; 9 | using MediaBrowser.Controller.Entities.Movies; 10 | using MediaBrowser.Controller.Entities.TV; 11 | using MediaBrowser.Controller.Library; 12 | using MediaBrowser.Model.Dto; 13 | using MediaBrowser.Model.Entities; 14 | using MediaBrowser.Model.Querying; 15 | using Microsoft.AspNetCore.Http; 16 | 17 | namespace Jellyfin.Plugin.HomeScreenSections.HomeScreen.Sections; 18 | 19 | public class TopTenSection : IHomeScreenSection 20 | { 21 | private enum TopTenType 22 | { 23 | Movies, 24 | Shows 25 | } 26 | private readonly IUserManager m_userManager; 27 | private readonly ICollectionManager m_collectionManager; 28 | private readonly IDtoService m_dtoService; 29 | public string? Section => "TopTen"; 30 | public string? DisplayText { get; set; } = "Top Ten"; 31 | public int? Limit => 2; 32 | public string? Route => null; 33 | public string? AdditionalData { get; set; } = null; 34 | public object? OriginalPayload => null; 35 | 36 | private TopTenType Type { get; set; } 37 | 38 | public TopTenSection(IUserManager userManager, 39 | ICollectionManager collectionManager, 40 | IDtoService dtoService) 41 | { 42 | m_userManager = userManager; 43 | m_collectionManager = collectionManager; 44 | m_dtoService = dtoService; 45 | } 46 | 47 | public QueryResult GetResults(HomeScreenSectionPayload payload, IQueryCollection queryCollection) 48 | { 49 | DtoOptions dtoOptions = new DtoOptions 50 | { 51 | Fields = new[] 52 | { 53 | ItemFields.PrimaryImageAspectRatio, 54 | ItemFields.MediaSourceCount 55 | }, 56 | ImageTypes = new[] 57 | { 58 | ImageType.Thumb, 59 | ImageType.Backdrop, 60 | ImageType.Primary, 61 | }, 62 | ImageTypeLimit = 1 63 | }; 64 | 65 | User user = m_userManager.GetUserById(payload.UserId)!; 66 | 67 | // TODO: Add config variable for collection name. 68 | BoxSet? collection = m_collectionManager.GetCollections(user) 69 | .FirstOrDefault(x => x.Name == "Top Ten"); 70 | 71 | TopTenType type = Enum.Parse(payload.AdditionalData ?? "Movies"); 72 | 73 | List items = collection?.GetChildren(user, true) ?? new List(); 74 | items = items.Where(x => (x is Movie && type == TopTenType.Movies) || (x is Series && type == TopTenType.Shows)).ToList(); 75 | 76 | items = items.Take(Math.Min(items.Count, 10)).ToList(); 77 | 78 | return new QueryResult(m_dtoService.GetBaseItemDtos(items, dtoOptions, user)); 79 | } 80 | 81 | public IHomeScreenSection CreateInstance(Guid? userId, IEnumerable? otherInstances = null) 82 | { 83 | if (otherInstances == null || 84 | !otherInstances.Any(x => x is TopTenSection { Type: TopTenType.Movies })) 85 | { 86 | return new TopTenSection(m_userManager, m_collectionManager, m_dtoService) 87 | { 88 | AdditionalData = TopTenType.Movies.ToString(), 89 | DisplayText = $"{DisplayText} Movies", 90 | Type = TopTenType.Movies, 91 | }; 92 | } 93 | else 94 | { 95 | if (otherInstances!.Any(x => x is TopTenSection { Type: TopTenType.Shows })) 96 | { 97 | throw new Exception("Ahhhh"); 98 | } 99 | 100 | return new TopTenSection(m_userManager, m_collectionManager, m_dtoService) 101 | { 102 | AdditionalData = TopTenType.Shows.ToString(), 103 | DisplayText = $"{DisplayText} Shows", 104 | Type = TopTenType.Shows, 105 | }; 106 | } 107 | } 108 | 109 | public HomeScreenSectionInfo GetInfo() 110 | { 111 | return new HomeScreenSectionInfo 112 | { 113 | Section = Section, 114 | DisplayText = DisplayText, 115 | AdditionalData = AdditionalData, 116 | Route = Route, 117 | Limit = Limit ?? 1, 118 | OriginalPayload = OriginalPayload, 119 | ContainerClass = "top-ten", 120 | DisplayTitleText = false, 121 | ShowDetailsMenu = false, 122 | ViewMode = SectionViewMode.Portrait, 123 | AllowViewModeChange = false 124 | }; 125 | } 126 | } -------------------------------------------------------------------------------- /src/Jellyfin.Plugin.HomeScreenSections/HomeScreen/Sections/WatchAgainSection.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics.CodeAnalysis; 2 | using Jellyfin.Data.Entities; 3 | using Jellyfin.Data.Enums; 4 | using Jellyfin.Plugin.HomeScreenSections.Configuration; 5 | using Jellyfin.Plugin.HomeScreenSections.Library; 6 | using Jellyfin.Plugin.HomeScreenSections.Model.Dto; 7 | using MediaBrowser.Controller.Collections; 8 | using MediaBrowser.Controller.Dto; 9 | using MediaBrowser.Controller.Entities; 10 | using MediaBrowser.Controller.Entities.Movies; 11 | using MediaBrowser.Controller.Entities.TV; 12 | using MediaBrowser.Controller.Library; 13 | using MediaBrowser.Controller.TV; 14 | using MediaBrowser.Model.Dto; 15 | using MediaBrowser.Model.Entities; 16 | using MediaBrowser.Model.Querying; 17 | using Microsoft.AspNetCore.Http; 18 | 19 | namespace Jellyfin.Plugin.HomeScreenSections.HomeScreen.Sections 20 | { 21 | internal class WatchAgainSection : IHomeScreenSection 22 | { 23 | class EpisodeEqualityComparer : IEqualityComparer 24 | { 25 | public bool Equals(Episode? x, Episode? y) 26 | { 27 | if (x == null && y == null) 28 | { 29 | return false; 30 | } 31 | 32 | return x?.Id == y?.Id; 33 | } 34 | 35 | public int GetHashCode([DisallowNull] Episode obj) 36 | { 37 | return obj.GetHashCode(); 38 | } 39 | } 40 | 41 | public string? Section => "WatchAgain"; 42 | 43 | public string? DisplayText { get; set; } = "Watch It Again"; 44 | 45 | public int? Limit => 1; 46 | 47 | public string? Route => null; 48 | 49 | public string? AdditionalData { get; set; } 50 | 51 | public object? OriginalPayload => null; 52 | 53 | private ICollectionManager CollectionManager { get; set; } 54 | 55 | private IUserManager UserManager { get; set; } 56 | 57 | private IDtoService DtoService { get; set; } 58 | 59 | private IUserDataManager UserDataManager { get; set; } 60 | 61 | private ITVSeriesManager TVSeriesManager { get; set; } 62 | 63 | private ILibraryManager LibraryManager { get; set; } 64 | 65 | private CollectionManagerProxy CollectionManagerProxy { get; set; } 66 | 67 | public WatchAgainSection( 68 | ICollectionManager collectionManager, 69 | IUserManager userManager, 70 | IDtoService dtoService, 71 | IUserDataManager userDataManager, 72 | ITVSeriesManager tvSeriesManager, 73 | ILibraryManager libraryManager, 74 | CollectionManagerProxy collectionManagerProxy) 75 | { 76 | CollectionManager = collectionManager; 77 | UserManager = userManager; 78 | DtoService = dtoService; 79 | UserDataManager = userDataManager; 80 | TVSeriesManager = tvSeriesManager; 81 | LibraryManager = libraryManager; 82 | CollectionManagerProxy = collectionManagerProxy; 83 | } 84 | 85 | public QueryResult GetResults(HomeScreenSectionPayload payload, IQueryCollection queryCollection) 86 | { 87 | DtoOptions? dtoOptions = new DtoOptions 88 | { 89 | Fields = new List 90 | { 91 | ItemFields.PrimaryImageAspectRatio 92 | }, 93 | ImageTypeLimit = 1, 94 | ImageTypes = new List 95 | { 96 | ImageType.Thumb, 97 | ImageType.Backdrop, 98 | ImageType.Primary, 99 | } 100 | }; 101 | 102 | User user = UserManager.GetUserById(payload.UserId)!; 103 | 104 | List results = new List(); 105 | 106 | { 107 | IEnumerable collections = CollectionManagerProxy.GetCollections(user) 108 | .Where(x => x.IsPlayed(user)) 109 | .Select(x => 110 | { 111 | List? children = x.GetChildren(user, true); 112 | 113 | if (children.Any()) 114 | { 115 | return children.Cast().OrderBy(y => y.PremiereDate).First(); 116 | } 117 | 118 | return null; 119 | }) 120 | .Where(x => x != null) 121 | //.Where(x => 122 | //{ 123 | // UserItemData data = UserDataManager.GetUserData(user.Id, x); 124 | // 125 | // return data.LastPlayedDate < DateTime.Now.Subtract(TimeSpan.FromDays(28)); 126 | //}) 127 | .Cast(); 128 | 129 | results.AddRange(collections.ToList()); 130 | } 131 | 132 | { 133 | 134 | IEnumerable? series = LibraryManager.GetItemList(new InternalItemsQuery 135 | { 136 | IncludeItemTypes = new[] { BaseItemKind.Series } 137 | }).Cast().Where(x => x.IsPlayed(user)); 138 | EpisodeEqualityComparer? eqComp = new EpisodeEqualityComparer(); 139 | 140 | IEnumerable firstEpisodes = series 141 | //.Where(x => 142 | //{ 143 | // UserItemData data = UserDataManager.GetUserData(user.Id, x); 144 | // 145 | // return data.LastPlayedDate < DateTime.Now.Subtract(TimeSpan.FromDays(28)); 146 | //}) 147 | .Select(x => 148 | { 149 | return x.GetChildren(user, true).Cast().Where(y => y.IndexNumber == 1).FirstOrDefault()?.GetChildren(user, true).Cast().Where(y => y.IndexNumber == 1 && !y.IsMissingEpisode).FirstOrDefault(); 150 | }).Distinct(eqComp); 151 | 152 | results.AddRange(firstEpisodes.Where(x => x != null).Cast()); 153 | } 154 | 155 | results = results.OrderBy(x => 156 | { 157 | UserItemData data = UserDataManager.GetUserData(user, x); 158 | 159 | return data.LastPlayedDate; 160 | }).Take(16).ToList(); 161 | 162 | QueryResult? result = new QueryResult(DtoService.GetBaseItemDtos(results, dtoOptions, user)); 163 | 164 | return result; 165 | } 166 | 167 | public IHomeScreenSection CreateInstance(Guid? userId, IEnumerable? otherInstances = null) 168 | { 169 | return this; 170 | } 171 | 172 | public HomeScreenSectionInfo GetInfo() 173 | { 174 | return new HomeScreenSectionInfo 175 | { 176 | Section = Section, 177 | DisplayText = DisplayText, 178 | AdditionalData = AdditionalData, 179 | Route = Route, 180 | Limit = Limit ?? 1, 181 | OriginalPayload = OriginalPayload, 182 | ViewMode = SectionViewMode.Landscape 183 | }; 184 | } 185 | } 186 | } 187 | -------------------------------------------------------------------------------- /src/Jellyfin.Plugin.HomeScreenSections/HomeScreenSectionsPlugin.cs: -------------------------------------------------------------------------------- 1 | using Jellyfin.Plugin.HomeScreenSections.Configuration; 2 | using MediaBrowser.Common.Configuration; 3 | using MediaBrowser.Common.Net; 4 | using MediaBrowser.Common.Plugins; 5 | using MediaBrowser.Controller.Configuration; 6 | using MediaBrowser.Model.Plugins; 7 | using MediaBrowser.Model.Serialization; 8 | using Newtonsoft.Json; 9 | using Newtonsoft.Json.Linq; 10 | 11 | namespace Jellyfin.Plugin.HomeScreenSections 12 | { 13 | public class HomeScreenSectionsPlugin : BasePlugin, IPlugin, IHasPluginConfiguration, IHasWebPages 14 | { 15 | internal IServerConfigurationManager ServerConfigurationManager { get; private set; } 16 | 17 | public override Guid Id => Guid.Parse("b8298e01-2697-407a-b44d-aa8dc795e850"); 18 | 19 | public override string Name => "Home Screen Sections"; 20 | 21 | public static HomeScreenSectionsPlugin Instance { get; private set; } = null!; 22 | 23 | public HomeScreenSectionsPlugin(IApplicationPaths applicationPaths, IXmlSerializer xmlSerializer, IServerConfigurationManager serverConfigurationManager) : base(applicationPaths, xmlSerializer) 24 | { 25 | Instance = this; 26 | 27 | ServerConfigurationManager = serverConfigurationManager; 28 | 29 | string homeScreenSectionsConfigDir = Path.Combine(applicationPaths.PluginConfigurationsPath, "Jellyfin.Plugin.HomeScreenSections"); 30 | if (!Directory.Exists(homeScreenSectionsConfigDir)) 31 | { 32 | Directory.CreateDirectory(homeScreenSectionsConfigDir); 33 | } 34 | 35 | string pluginPagesConfig = Path.Combine(applicationPaths.PluginConfigurationsPath, "Jellyfin.Plugin.PluginPages", "config.json"); 36 | 37 | JObject config = new JObject(); 38 | if (!File.Exists(pluginPagesConfig)) 39 | { 40 | FileInfo info = new FileInfo(pluginPagesConfig); 41 | info.Directory?.Create(); 42 | } 43 | else 44 | { 45 | config = JObject.Parse(File.ReadAllText(pluginPagesConfig)); 46 | } 47 | 48 | if (!config.ContainsKey("pages")) 49 | { 50 | config.Add("pages", new JArray()); 51 | } 52 | 53 | if (!config.Value("pages")!.Any(x => x.Value("Id") == typeof(HomeScreenSectionsPlugin).Namespace)) 54 | { 55 | string rootUrl = ServerConfigurationManager.GetNetworkConfiguration().BaseUrl.TrimStart('/').Trim(); 56 | if (!string.IsNullOrEmpty(rootUrl)) 57 | { 58 | rootUrl = $"/{rootUrl}"; 59 | } 60 | 61 | config.Value("pages")!.Add(new JObject 62 | { 63 | { "Id", typeof(HomeScreenSectionsPlugin).Namespace }, 64 | { "Url", $"{rootUrl}/ModularHomeViews/settings" }, 65 | { "DisplayText", "Modular Home" }, 66 | { "Icon", "ballot" } 67 | }); 68 | 69 | File.WriteAllText(pluginPagesConfig, config.ToString(Formatting.Indented)); 70 | } 71 | } 72 | 73 | public IEnumerable GetPages() 74 | { 75 | string? prefix = GetType().Namespace; 76 | 77 | yield return new PluginPageInfo 78 | { 79 | Name = Name, 80 | EmbeddedResourcePath = $"{prefix}.Configuration.config.html" 81 | }; 82 | } 83 | 84 | /// 85 | /// Get the views that the plugin serves. 86 | /// 87 | /// Array of . 88 | public IEnumerable GetViews() 89 | { 90 | return new[] 91 | { 92 | new PluginPageInfo 93 | { 94 | Name = "settings", 95 | EmbeddedResourcePath = $"{GetType().Namespace}.Config.settings.html" 96 | } 97 | }; 98 | } 99 | } 100 | } -------------------------------------------------------------------------------- /src/Jellyfin.Plugin.HomeScreenSections/Inject/HomeScreenSections.css: -------------------------------------------------------------------------------- 1 | .top-ten .card:before { 2 | content: var(--card-number); 3 | position:fixed; 4 | margin-left: 20px; 5 | font-size:75px; 6 | width:50px; 7 | text-align:right; 8 | height: 100px; 9 | vertical-align: middle; 10 | --card-number: attr(data-number); 11 | bottom: calc(50% - 50px); 12 | font-weight: bold; 13 | -webkit-text-stroke: 3px var(--borderColor); 14 | color: var(--darkerGradientPoint); 15 | text-shadow: 0 0 10px var(--borderColor); 16 | } 17 | 18 | .top-ten .card .cardBox { 19 | margin-left: 4.2em !important; 20 | } 21 | 22 | .top-ten .cardFooter { 23 | display:none; 24 | } 25 | 26 | @media (min-width:100em) { 27 | .top-ten .card:before { 28 | margin-left: 12px; 29 | font-size:6vw; 30 | height: 120px; 31 | bottom: calc(50% - 60px); 32 | } 33 | } -------------------------------------------------------------------------------- /src/Jellyfin.Plugin.HomeScreenSections/Inject/HomeScreenSections.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | if (typeof TopTenSectionHandler == 'undefined') { 4 | const TopTenSectionHandler = { 5 | init: function () { 6 | var MutationObserver = window.MutationObserver || window.WebKitMutationObserver; 7 | var myObserver = new MutationObserver(this.mutationHandler); 8 | var observerConfig = {childList: true, characterData: true, attributes: true, subtree: true}; 9 | 10 | $("body").each(function () { 11 | myObserver.observe(this, observerConfig); 12 | }); 13 | }, 14 | mutationHandler: function (mutationRecords) { 15 | mutationRecords.forEach(function (mutation) { 16 | if (mutation.addedNodes && mutation.addedNodes.length > 0) { 17 | [].some.call(mutation.addedNodes, function (addedNode) { 18 | if ($(addedNode).hasClass('card')) { 19 | if ($(addedNode).parents('.top-ten').length > 0) { 20 | var index = parseInt($(addedNode).attr('data-index')); 21 | $(addedNode).attr('data-number', index + 1); 22 | } 23 | } 24 | }); 25 | } 26 | }); 27 | } 28 | } 29 | 30 | setTimeout(function () { 31 | TopTenSectionHandler.init(); 32 | }, 50); 33 | } 34 | -------------------------------------------------------------------------------- /src/Jellyfin.Plugin.HomeScreenSections/Jellyfin.Plugin.HomeScreenSections.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net8.0 5 | enable 6 | enable 7 | false 8 | 2.3.0.0 9 | https://github.com/IAmParadox27/jellyfin-plugin-home-sections 10 | GitHub 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | false 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /src/Jellyfin.Plugin.HomeScreenSections/Library/IHomeScreenManager.cs: -------------------------------------------------------------------------------- 1 | using Jellyfin.Plugin.HomeScreenSections.Configuration; 2 | using Jellyfin.Plugin.HomeScreenSections.Model.Dto; 3 | using MediaBrowser.Model.Dto; 4 | using MediaBrowser.Model.Querying; 5 | using Microsoft.AspNetCore.Http; 6 | 7 | namespace Jellyfin.Plugin.HomeScreenSections.Library 8 | { 9 | public interface IHomeScreenManager 10 | { 11 | void RegisterResultsDelegate() where T : IHomeScreenSection; 12 | 13 | void RegisterResultsDelegate(T handler) where T : IHomeScreenSection; 14 | 15 | IEnumerable GetSectionTypes(); 16 | 17 | QueryResult InvokeResultsDelegate(string key, HomeScreenSectionPayload payload, IQueryCollection queryCollection); 18 | 19 | bool GetUserFeatureEnabled(Guid userId); 20 | 21 | void SetUserFeatureEnabled(Guid userId, bool enabled); 22 | 23 | ModularHomeUserSettings? GetUserSettings(Guid userId); 24 | 25 | bool UpdateUserSettings(Guid userId, ModularHomeUserSettings userSettings); 26 | } 27 | 28 | public interface IHomeScreenSection 29 | { 30 | public string? Section { get; } 31 | 32 | public string? DisplayText { get; set; } 33 | 34 | public int? Limit { get; } 35 | 36 | public string? Route { get; } 37 | 38 | public string? AdditionalData { get; set; } 39 | 40 | public object? OriginalPayload { get; } 41 | 42 | public QueryResult GetResults(HomeScreenSectionPayload payload, IQueryCollection queryCollection); 43 | 44 | public IHomeScreenSection CreateInstance(Guid? userId, IEnumerable? otherInstances = null); 45 | 46 | public HomeScreenSectionInfo GetInfo(); 47 | } 48 | 49 | public class HomeScreenSectionInfo 50 | { 51 | public string? Section { get; set; } 52 | 53 | public string? DisplayText { get; set; } 54 | 55 | public int Limit { get; set; } = 1; 56 | 57 | public string? Route { get; set; } 58 | 59 | public string? AdditionalData { get; set; } 60 | 61 | public string? ContainerClass { get; set; } 62 | 63 | public SectionViewMode? ViewMode { get; set; } = null; 64 | 65 | public bool DisplayTitleText { get; set; } = true; 66 | 67 | public bool ShowDetailsMenu { get; set; } = true; 68 | 69 | public object? OriginalPayload { get; set; } 70 | 71 | public bool AllowViewModeChange { get; set; } = true; 72 | } 73 | 74 | public class ModularHomeUserSettings 75 | { 76 | public Guid UserId { get; set; } 77 | 78 | public List EnabledSections { get; set; } = new List(); 79 | } 80 | 81 | public static class HomeScreenSectionExtensions 82 | { 83 | public static HomeScreenSectionInfo AsInfo(this IHomeScreenSection section) 84 | { 85 | return section.GetInfo(); 86 | } 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/Jellyfin.Plugin.HomeScreenSections/Model/Dto/HomeScreenSectionPayload.cs: -------------------------------------------------------------------------------- 1 | namespace Jellyfin.Plugin.HomeScreenSections.Model.Dto 2 | { 3 | 4 | 5 | 6 | public class HomeScreenSectionPayload 7 | { 8 | 9 | 10 | 11 | public Guid UserId { get; set; } 12 | 13 | 14 | 15 | 16 | 17 | public string? AdditionalData { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Jellyfin.Plugin.HomeScreenSections/Model/PatchRequestPayload.cs: -------------------------------------------------------------------------------- 1 | using System.Text.Json.Serialization; 2 | 3 | namespace Jellyfin.Plugin.HomeScreenSections.Model 4 | { 5 | public class PatchRequestPayload 6 | { 7 | [JsonPropertyName("contents")] 8 | public string? Contents { get; set; } 9 | } 10 | } -------------------------------------------------------------------------------- /src/Jellyfin.Plugin.HomeScreenSections/Model/SectionRegisterPayload.cs: -------------------------------------------------------------------------------- 1 | using System.Text.Json.Serialization; 2 | 3 | namespace Jellyfin.Plugin.HomeScreenSections.Model 4 | { 5 | public class SectionRegisterPayload 6 | { 7 | [JsonPropertyName("id")] 8 | public required string Id { get; set; } 9 | 10 | [JsonPropertyName("displayText")] 11 | public string? DisplayText { get; set; } 12 | 13 | [JsonPropertyName("limit")] 14 | public int? Limit { get; set; } 15 | 16 | [JsonPropertyName("route")] 17 | public string? Route { get; set; } 18 | 19 | [JsonPropertyName("additionalData")] 20 | public string? AdditionalData { get; set; } 21 | 22 | [JsonPropertyName("resultsEndpoint")] 23 | public string? ResultsEndpoint { get; set; } 24 | } 25 | } -------------------------------------------------------------------------------- /src/Jellyfin.Plugin.HomeScreenSections/PluginServiceRegistrator.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using Jellyfin.Plugin.HomeScreenSections.HomeScreen; 3 | using Jellyfin.Plugin.HomeScreenSections.Library; 4 | using Jellyfin.Plugin.HomeScreenSections.Services; 5 | using MediaBrowser.Common.Configuration; 6 | using MediaBrowser.Controller; 7 | using MediaBrowser.Controller.Plugins; 8 | using Microsoft.Extensions.DependencyInjection; 9 | 10 | namespace Jellyfin.Plugin.HomeScreenSections 11 | { 12 | public class PluginServiceRegistrator : IPluginServiceRegistrator 13 | { 14 | public void RegisterServices(IServiceCollection serviceCollection, IServerApplicationHost applicationHost) 15 | { 16 | serviceCollection.AddSingleton(); 17 | serviceCollection.AddSingleton(services => 18 | { 19 | IApplicationPaths appPaths = services.GetRequiredService(); 20 | 21 | HomeScreenManager homeScreenManager = ActivatorUtilities.CreateInstance(services); 22 | 23 | string pluginLocation = Path.Combine(appPaths.PluginConfigurationsPath, typeof(HomeScreenSectionsPlugin).Namespace!); 24 | 25 | string[] extraDlls = Directory.GetFiles(pluginLocation, "*.dll", SearchOption.AllDirectories).ToArray(); 26 | 27 | foreach (string extraDll in extraDlls) 28 | { 29 | Assembly extraPluginAssembly = Assembly.LoadFile(extraDll); 30 | 31 | Type[] homeScreenSectionTypes = extraPluginAssembly.GetTypes().Where(x => x.IsAssignableTo(typeof(IHomeScreenSection))).ToArray(); 32 | 33 | foreach (Type homeScreenSectionType in homeScreenSectionTypes) 34 | { 35 | homeScreenManager.RegisterResultsDelegate(homeScreenSectionType); 36 | } 37 | } 38 | 39 | return homeScreenManager; 40 | }); 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /src/Jellyfin.Plugin.HomeScreenSections/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | [assembly: AssemblyCompany("IAmParadox27")] 3 | [assembly: AssemblyProduct("Jellyfin.Plugin.HomeScreenSections")] 4 | [assembly: AssemblyDescription("")] 5 | [assembly: AssemblyTitle("Jellyfin.Plugin.HomeScreenSections")] 6 | [assembly: AssemblyVersion("2.3.0.0")] -------------------------------------------------------------------------------- /src/Jellyfin.Plugin.HomeScreenSections/Services/StartupService.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | using System.IO.Pipes; 3 | using System.Net.Http.Headers; 4 | using System.Reflection; 5 | using System.Runtime.Loader; 6 | using System.Text; 7 | using Jellyfin.Plugin.HomeScreenSections.Helpers; 8 | using Jellyfin.Plugin.HomeScreenSections.Model; 9 | using MediaBrowser.Common.Configuration; 10 | using MediaBrowser.Controller; 11 | using MediaBrowser.Model.Tasks; 12 | using Microsoft.Extensions.Logging; 13 | using Newtonsoft.Json; 14 | using Newtonsoft.Json.Linq; 15 | 16 | namespace Jellyfin.Plugin.HomeScreenSections.Services 17 | { 18 | public class StartupService : IScheduledTask 19 | { 20 | public string Name => "HomeScreenSections Startup"; 21 | 22 | public string Key => "Jellyfin.Plugin.HomeScreenSections.Startup"; 23 | 24 | public string Description => "Startup Service for HomeScreenSections"; 25 | 26 | public string Category => "Startup Services"; 27 | 28 | private readonly IServerApplicationHost m_serverApplicationHost; 29 | private readonly IApplicationPaths m_applicationPaths; 30 | private readonly ILogger m_logger; 31 | 32 | public StartupService(IServerApplicationHost serverApplicationHost, IApplicationPaths applicationPaths, ILogger logger) 33 | { 34 | m_serverApplicationHost = serverApplicationHost; 35 | m_applicationPaths = applicationPaths; 36 | m_logger = logger; 37 | } 38 | 39 | public async Task ExecuteAsync(IProgress progress, CancellationToken cancellationToken) 40 | { 41 | // Look through the web path and find the file that contains `",loadSections:` 42 | List payloads = new List(); 43 | { 44 | JObject payload = new JObject(); 45 | payload.Add("id", "e531b5a0-5493-42b0-b632-619e2d06db5c"); 46 | payload.Add("fileNamePattern", "index.html"); 47 | payload.Add("callbackAssembly", GetType().Assembly.FullName); 48 | payload.Add("callbackClass", typeof(TransformationPatches).FullName); 49 | payload.Add("callbackMethod", nameof(TransformationPatches.IndexHtml)); 50 | payloads.Add(payload); 51 | } 52 | 53 | string[] allJsChunks = Directory.GetFiles(m_applicationPaths.WebPath, "*.chunk.js", SearchOption.AllDirectories); 54 | foreach (string jsChunk in allJsChunks) 55 | { 56 | if (File.ReadAllText(jsChunk).Contains(",loadSections:")) 57 | { 58 | JObject payload = new JObject(); 59 | payload.Add("id", "ea4045f3-6604-4ba4-9581-f91f96bbd2ae"); 60 | payload.Add("fileNamePattern", Path.GetFileName(jsChunk)); 61 | payload.Add("callbackAssembly", GetType().Assembly.FullName); 62 | payload.Add("callbackClass", typeof(TransformationPatches).FullName); 63 | payload.Add("callbackMethod", nameof(TransformationPatches.LoadSections)); 64 | payloads.Add(payload); 65 | break; 66 | } 67 | } 68 | 69 | Assembly? fileTransformationAssembly = 70 | AssemblyLoadContext.All.SelectMany(x => x.Assemblies).FirstOrDefault(x => 71 | x.FullName?.Contains(".FileTransformation") ?? false); 72 | 73 | if (fileTransformationAssembly != null) 74 | { 75 | Type? pluginInterfaceType = fileTransformationAssembly.GetType("Jellyfin.Plugin.FileTransformation.PluginInterface"); 76 | 77 | if (pluginInterfaceType != null) 78 | { 79 | foreach (JObject payload in payloads) 80 | { 81 | pluginInterfaceType.GetMethod("RegisterTransformation")?.Invoke(null, new object?[] { payload }); 82 | } 83 | } 84 | } 85 | } 86 | 87 | public IEnumerable GetDefaultTriggers() 88 | { 89 | yield return new TaskTriggerInfo() 90 | { 91 | Type = TaskTriggerInfo.TriggerStartup 92 | }; 93 | } 94 | } 95 | } -------------------------------------------------------------------------------- /src/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IAmParadox27/jellyfin-plugin-home-sections/07f005f47d2b32b7b3d815134aeaa599b71ae9a7/src/logo.png --------------------------------------------------------------------------------