Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Hof Plexexport Bundle Laravel Package

devjoghurt/hof-plexexport-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation Add the bundle via Composer:

    composer require devjoghurt/hof-plexexport-bundle:dev-master
    

    Register the bundle in app/AppKernel.php:

    new Hof\PlexExportBundle\HofPlexExportBundle(),
    
  2. Basic Configuration Add minimal config in app/config/config.yml (optional if defaults suffice):

    hof_plex_export:
        config:
            plex_url: "http://your-plex-server:32400"
            data_dir: "%kernel.root_dir%/../web/data/plex"
    
  3. First Use Case Render Plex media in a Twig template:

    {{ plex_export() }}
    

    Verify the output displays your Plex library (movies/shows) with thumbnails.


Implementation Patterns

Core Workflows

  1. Dynamic Export Rendering Use the plex_export() Twig function to display media in any template:

    {% for item in plex_export() %}
        <h2>{{ item.title }}</h2>
        <img src="{{ item.thumbnail }}" />
    {% endfor %}
    
  2. Custom Templates Override the default template by passing a custom path:

    {{ plex_export("AppBundle:Media:custom_plex.html.twig") }}
    
  3. Configuration Overrides Pass runtime options to modify behavior:

    {{ plex_export("AppBundle:Media:plex.html.twig", {
        "sections": ["movies", "shows"],
        "thumbnail_width": 300
    }) }}
    
  4. Integration with Symfony Forms Use the bundle to populate forms or grids with Plex metadata:

    $plexData = $this->get('hof_plex_export.plex_export')->getData();
    foreach ($plexData as $item) {
        $form->add('media_item', EntityType::class, [
            'class' => 'App\Entity\Media',
            'choices' => [$item->id => $item->title],
        ]);
    }
    
  5. Scheduled Exports Trigger exports via a Symfony command (extend the bundle or create a custom one):

    // src/Command/ExportPlexCommand.php
    class ExportPlexCommand extends Command {
        protected function execute(InputInterface $input, OutputInterface $output) {
            $export = $this->getContainer()->get('hof_plex_export.plex_export');
            $export->export(); // Hypothetical method (check bundle for actual API)
        }
    }
    

Gotchas and Tips

Pitfalls

  1. Plex Server Authentication

    • The bundle assumes unauthenticated access. If your Plex server requires authentication, extend the PlexExport service to include headers:
      hof_plex_export:
          config:
              plex_url: "http://user:pass@your-plex-server:32400"
      
    • Alternatively, override the Hof\PlexExportBundle\Service\PlexExport class to add custom auth logic.
  2. File Permissions

    • Ensure data_dir is writable by the web server:
      chmod -R 755 %kernel.root_dir%/../web/data/plex
      
  3. Thumbnail Generation

    • Thumbnails are generated on first export. Large libraries may cause timeouts. Adjust thumbnail_width/height or disable thumbnails:
      thumbnail_width: 0  # Disables thumbnails
      
  4. Section Filtering

    • The sections config accepts "all" or an array of section names (e.g., ["movies", "shows"]). Verify your Plex library’s section names match exactly.
  5. Caching Issues

    • The bundle does not cache exports by default. For performance, implement a cache layer (e.g., Symfony Cache component) around the getData() method.

Debugging

  1. Check Plex API Response

    • Enable debug mode and inspect the raw Plex API response:
      $client = $this->get('hof_plex_export.plex_export')->getClient();
      $response = $client->request('GET', '/library/sections');
      var_dump($response->getContent());
      
  2. Log Export Errors

    • Add logging to the PlexExport service:
      $this->logger->error('Plex export failed', ['error' => $e->getMessage()]);
      
  3. Validate Config

    • Use Symfony’s parameter validation to ensure data_dir and plex_url are correct:
      # app/config/validation.yml
      services:
          hof_plex_export.validator:
              class: Symfony\Component\Validator\Validator\ValidatorInterface
              arguments: [@validator]
              calls:
                  - [validate, [%hof_plex_export.config%]]
      

Extension Points

  1. Custom Exporters

    • Extend the bundle to support additional Plex features (e.g., ratings, genres):
      // src/Hof/PlexExportBundle/Service/CustomPlexExport.php
      class CustomPlexExport extends PlexExport {
          public function getGenres() {
              // Custom logic to fetch genres
          }
      }
      
    • Register the service in services.yml:
      services:
          hof_plex_export.custom_export:
              class: App\Service\CustomPlexExport
              arguments: [%hof_plex_export.config%]
              tags: [hof_plex_export.exporter]
      
  2. Twig Extensions

    • Add custom Twig filters for Plex data:
      // src/Twig/PlexExtension.php
      class PlexExtension extends \Twig_Extension {
          public function getFilters() {
              return [
                  new \Twig_SimpleFilter('plex_duration', [$this, 'formatDuration']),
              ];
          }
      }
      
    • Register the extension in services.yml:
      services:
          app.twig.plex_extension:
              class: App\Twig\PlexExtension
              tags: [twig.extension]
      
  3. Event Listeners

    • Listen for export events to modify data pre-render:
      // src/EventListener/PlexExportListener.php
      class PlexExportListener {
          public function onPlexExport(ExportEvent $event) {
              $event->setData($this->modifyData($event->getData()));
          }
      }
      
    • Bind the listener in services.yml:
      services:
          app.plex_export_listener:
              class: App\EventListener\PlexExportListener
              tags:
                  - { name: kernel.event_listener, event: hof_plex_export.export, method: onPlexExport }
      
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed