Siriusmart / youtube-tui

An aesthetically pleasing YouTube TUI written in Rust
https://siriusmart.github.io/youtube-tui
GNU General Public License v3.0
313 stars 12 forks source link

[BUG] panic if invidious has popular feed disable #26

Closed LuckyTurtleDev closed 1 year ago

LuckyTurtleDev commented 1 year ago

Youtube-tui does panic if invidious has popular feed disable:

thread 'main' panicked at 'index out of bounds: the len is 0 but the index is 0', src/items/itemlist.rs:42:16
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

If I enable the popular feed at server youtube-tui does work again. I have try to disable popular at the page,yml but this has not fix the problem.

main.yml:

mouse_support: true
invidious_instance: https://youtube.luckyturtle.dev
max_watch_history: 50
allow_unicode: true
message_bar_default: All good :)
images: Sixels
refresh_after_modifying_search_filters: true
image_index: 4
provider: YouTube
env:
  terminal-emulator: alacritty -e
  video-player: mpv
  download-path: '''~/Downloads/%(title)s-%(id)s.%(ext)s'''
  youtube-downloader: yt-dlp
  browser: firefox

pages.yml:

main_menu:
  layout:
  - type: NonCenteredRow
    items:
    - SearchBar
    - SearchFilters
  - type: CenteredRow
    items:
   # - Popular
    - Trending
    - History
  - type: NonCenteredRow
    items:
    - ItemList
  - type: NonCenteredRow
    items:
    - MessageBar
  message: Loading main menu...
search:
  layout:
  - type: NonCenteredRow
    items:
    - SearchBar
    - SearchFilters
  - type: NonCenteredRow
    items:
    - ItemList
  - type: NonCenteredRow
    items:
    - MessageBar
  message: Loading search results...
singleitem:
  layout:
  - type: NonCenteredRow
    items:
    - SearchBar
    - SearchFilters
  - type: NonCenteredRow
    items:
    - SingleItemInfo
  - type: NonCenteredRow
    items:
    - MessageBar
  message: Loading item details...
channeldisplay:
  layout:
  - type: NonCenteredRow
    items:
    - SearchBar
    - SearchFilters
  - type: CenteredRow
    items:
    - ChannelMain
    - ChannelVideos
    - ChannelPlaylists
  - type: NonCenteredRow
    items:
    - ChannelDisplay
  - type: NonCenteredRow
    items:
    - MessageBar
  message: Loading channel details...
Siriusmart commented 1 year ago

Fix

In commands.yml, change launch_command to something else (for example loadpage watchhistory ;; flush ;; history clear).

What happened

I believe when you disable the popular feed, instead of returning nothing on the api request, it returns an empty array (instead of an error) which itemlist sorta freaks out.

The Popular item in pages.yml is just the popular page button, by all it does is load a page (similar to a hyperlink). But because in the launch command in commands.yml loads the popular page on start, as soon as the page loads it crashes because it was not expected to recieve an empty array.

I'm gonna catch this case so it doesnt crash maybe later

LuckyTurtleDev commented 1 year ago

Invidious returns a different json with status 500 if popular is disable. https://youtube.luckyturtle.dev/api/v1/popular

{"error":"Closed stream"}

It would possible a good idea to check the status code with the .error_for_status() function.

Siriusmart commented 1 year ago

Apparently it was already fixed a few git commits ago, its just that the latest crates.io version (0.6.2) is not new enough to include this fix, but it will be included in the next crates.io version

this is the current behavior: image