[PLUGIN] YouTube2

OK, did the same with 2 YT songs in the queue and single repeat on the first and indeed it jumped to the second. After the second it didn’t go back to the first.

With normal repeat on it does loop both songs in the queue.

Not only for this plugin, but with my other plugins as well… Not surprising as they use more or less the same playback method.
I need time to identify the cause.

Cause identified. In statemachine.js (yep, it’s statemachine again):

CoreStateMachine.prototype.syncState = function (stateService, sService) {
...
} else if (stateService.status === 'stop') {
    if (this.currentStatus === 'play') {
      // Service has stopped without client request, meaning it is finished playing its track block. Move on to next track block.
      // this.currentPosition = stateService.position;
      this.currentSeek = stateService.seek;
      this.currentDuration = stateService.duration;
      this.currentTrackType = null;
      this.currentTitle = null;
      this.currentArtist = null;
      this.currentAlbum = null;
      this.currentAlbumArt = '/albumart';
      this.currentUri = stateService.uri;
      this.currentSampleRate = null;
      this.currentBitDepth = null;
      this.currentChannels = null;

      this.commandRouter.pushDebugConsoleMessage('CURRENT POSITION ' + this.currentPosition);

      if (trackBlock !== undefined && trackBlock.service !== 'webradio') {
        if (this.currentConsume !== undefined && this.currentConsume == true) {
          this.playQueue.removeQueueItem(this.currentPosition);
        } else {
          if (this.currentRandom !== undefined && this.currentRandom === true) {
            var nextSongIndex = 0;

            /**
                         * Using nextRandomIndex because prefetch may have picked one sone randomly
                         * from another service (thus not prefetched). This way we use the same index
                         */
            if (this.nextRandomIndex) { this.currentPosition = this.nextRandomIndex; } else { this.currentPosition = this.randomQueue.next(); }
          } else {
            if (this.currentPosition == null || this.currentPosition === undefined) { this.currentPosition = 0; } else this.currentPosition++;
          }
        }
      }

      this.commandRouter.pushDebugConsoleMessage('CURRENT POSITION ' + this.currentPosition);

      this.currentStatus = 'stop';
      if (this.isConsume) {
        this.consumeState.status = 'stop';
        this.consumeState.seek = 0;
      }

      // Checking repeat status
      if (this.currentRepeat && this.currentRepeatSingleSong) {
        if (this.prefetchDone == false) {
          this.play(this.currentPosition)
            .then(self.pushState.bind(self))
            .fail(this.pushError.bind(this));

          this.askedForPrefetch = false;
          this.simulateStopStartDone = false;
        } else {
...

This part gets triggered when playback of a YT track stops. It reaches the following line, which increments the current queue position by 1 (currentPosition):

if (this.currentPosition == null || this.currentPosition === undefined) { this.currentPosition = 0; } else this.currentPosition++;

Then, further down, it checks whether ‘repeat single song’ is enabled:

// Checking repeat status
if (this.currentRepeat && this.currentRepeatSingleSong) {
    if (this.prefetchDone == false) {
      this.play(this.currentPosition)
        .then(self.pushState.bind(self))
        .fail(this.pushError.bind(this));
...

This plugin doesn’t support prefetch, so statemachine plays currentPosition. But currentPosition has just been incremented, so the check for ‘repeat single song’ at this point is actually useless. It should perform this check before incrementing currentPosition.

So the issue stems from statemachine, not the plugin.

1 Like

@mervinio @volumio

@SimonE @patrickkfkan
Thank you for your information. I have modified the statemachine.js by moving the block of checking repeat to before block of currentPosition increament and restart volumio then it can repeat a single song. I have not test other use cases, only one that in a queue of several songs with mixed local and youtube, i can loop a youtube song with when i set repeat icon with a ‘1’.
I attached my statemachine.js for other reference.
statemachine.zip (8.9 KB)

Thanks~

I am running vol 3.378_x86. I did make a secret and ID with the guide/google youtube api, but got error (no results) when I am yousung youtube2. Can not browse to my account.
Trying youtube 2 because cast plugin does not work with Fusion DSP

Long overdue update: v1.0.1, which you can find in the beta channel of plugin store.

To install from beta channel:

  • Uninstall current version.
  • Enable Plugins Test Mode in http://<volumio address>/dev
  • Find the YouTube2 plugin in the plugin store. Click the Details button under it and choose latest beta version to install.
  • Restart Volumio.

Like the YouTube Music plugin, this plugin uses a modified version of the YouTube.js library for content fetching and login. Credit goes to the developers of that library. If you like this plugin, consider sponsoring that project or giving it a star.

This is a major update which brings about the following changes (for better or worse - I hope better):

  • Much simpler sign-in process (like YouTube Music plugin): no Google API credentials required.
  • Much wider contents, mirroring as closely as possible those of YouTube website.
    • Navigation probably needs getting used to, because where on YouTube (or any modern website) you get menus, tabs, in-page loading / refresh of contents, you have none of these in Volumio UI. The plugin tries to map these UI elements to the basic folder->file type navigation framework of Volumio.
  • Browsing and playback of your saved playlists (not just created ones), private / unlisted videos, etc.
  • Live stream support

Few things to note

  • Playback follows YouTube behavior:
    • When you click on a video that is not in a playlist, only that video is added to the queue and played. If you enable Autoplay, then when that video finishes the next one will get loaded into the queue.
    • If you click on a Mix, then the first batch of videos in the Mix’s playlist will get loaded. After they have finished playing, and Autoplay is enabled, the plugin will load the next batch into the queue. Same for ‘Play All’ links.
    • If you click on a video in a playlist, then all videos currently shown will be added to the queue. You can enable ‘Load full playlist’ in the plugin settings to show all playlist items on a single page (beware of extended loading times).
  • Live streams:
    • Live streams can take longer to load before playback starts.
    • If you experience choppy playback, go to plugin settings and set ‘Live Stream Quality’ to a lower value (start with 144p or 240p). This is because, unlike regular tracks where only audio streams are fetched, live streams are fetched with audio + video. There is a lot more network traffic and overhead in processing. If ‘Live Stream Quality’ is set to ‘Auto’, then the player determines the best quality to use (adaptive bitrate) but sometimes it overestimates its capability. Note that with YouTube, lower quality usually refers to video resolution, so fetching a lower quality live stream does not necessarily mean worse SQ.
    • If you stop playback of a live stream, the Stop button will change to the Play icon momentarily and then changes back to Stop even though playback has indeed stopped. This is not a bug in the plugin.
  • Thumbnails, like previous versions, appear squashed. This is not a bug in the plugin. It’s a Volumio UI thing (assuming all album art covers have 1:1 square aspect ratio).
  • I am thinking how to better present different types of media appearing on the same page (playlists, videos, live streams, channels, etc.), but probably won’t have a satisfactory solution.
  • By default, the landing page of the plugin shows the contents of the expanded left hand side menu of YouTube website. If you have many playlists or subscriptions, the page might look cluttered. You can change ‘Landing page contents’ to ‘Simple’ to show only the primary entries.
4 Likes

Hi @patrickkfkan,

Thanks for this update! I gave it a try yesterday on one of my pi’s and I like the simpler login and more access to library items like “Watch later”.

I mostly use your youtube2 plugin with auto play switched on and just use that to sometime discover new music.

So far, I’ve noticed with this update, there is a loop of the same two songs that would auto play back-to-back. this has happened a with a few different sets of songs and I’m not sure how to get out of the loop other than manually searching or choosing a new song. Then after a little while, a loop of two other songs will begin. See attached for screenshot of queue. Have you experienced this?

This is interesting. Does this happen regardless of where you are playing from (e.g. a playlist) or whether you are signed in?

Could you also PM me (don’t post here) the contents of http://<your volumio addr/dev? If there are many entries under player queue, you can just send me the 5 entries before the repeating ones, as well as the first 5 repeating entries.

i think it stopped working the plugin with the google api. any idea?

Hi Giorgosperi,
I’m not clear what exactly you mean by saying “with the google api”, but perhaps it’s helpful for you: For me the plugin is working fine.
Regards Axel

hi, under youtube we can use the google api to login with our youtube account. it stopped working to me.

ok, thx. This does not apply to me because I do not have a youtube account.
But I’m curios, what’s the advantage if one has a youtube account and use the google api?

no problem. thanks also for your response. just i can find my liked videos and playlists that i do from an other device.

i think i figured it out. for some reason the api that i had its not working probably did records to the limit.
i added different api and it worked…

Plugin version 1.x no longer requires Google API credentials for signing into YT.

Updated v1.1.0:

  • Support prefetching next track
  • Add option to fetch autoplay videos from Mixes and Related Videos in preference to using YouTube’s default. If you find YouTube’s autoplay algorithm quirky, you can try enabling this option.
  • Autoplay doesn’t work well when “Add to History” is disabled - there can be a high number of repeating videos. The plugin now warns you when you set Autoplay to ON and “Add to History” to OFF in the plugin settings.

The plugin has been recoded in TypeScript with the view of easier maintenance down the road. There may be regressions – if you come across any, please report them here.

v1.1.0 is currently in beta channel of Volumio plugin store. To install:

  • Uninstall current version.
  • Enable Plugins Test Mode in http://<volumio address>/dev
  • Restart Volumio.
  • Find the YouTube2 plugin in the plugin store. Click the “Details” button under it and choose latest beta version to install.

(All steps mandatory)

2 Likes

when i install the plugin, and go to settings my rpi4 freezes and upon reboot only gives me white screens. i cant acces anymore on browser only when i delete the folder in ssh and reboot it returns to normal state :open_mouth:

It think it was just today that YouTube changed something that caused the underlying YouTube.js library to block the system process when trying to authenticate, making Volumio unresponsive. I have identified the cause and should be able to provide an update later in the day.

Updated v1.1.2, which addresses this:

For unfortunate souls who installed a previous version and now has an unresponsive Volumio, you can try the following:

  1. Wait and see if the issue clears itself. While appearing unresponsive, the plugin (more precisely, the underlying YouTube.js library) is actually trying to parse an YT authentication script. It will fail eventually but it could take many, many hours. Once Volumio becomes responsive again, uninstall the plugin immediately. Don’t try to disable and re-enable it or you would have to wait again.
  2. ssh into Volumio and run the following command to delete the youtube2 plugin folder, followed by restarting Volumio:
    rm -rf /data/plugins/music_service/youtube2 
    

To install the updated plugin from beta channel:

  • Uninstall current version.
  • Enable Plugins Test Mode in http://<volumio address>/dev
  • Restart Volumio.
  • Find the YouTube2 plugin in the plugin store. Click the “Details” button under it and choose latest beta version to install.