Xonshiz / anime-dl

Anime-dl is a command-line program to download anime from CrunchyRoll and Funimation.
MIT License
229 stars 37 forks source link

"List Index out of range" error when using xargs? #118

Open IngwiePhoenix opened 4 years ago

IngwiePhoenix commented 4 years ago

I put together a list of links in Notepad and wanted to use anime-dl from WSL2 running Debian to run through the links I picked.

$ xargs -a links.txt -d "\n" -L 1 anime dl
anime: anime-downloader 4.5.0
anime: Extracting episode info from page
ERROR: list index out of range

If I copy/paste the link and write the command in myself ($ anime dl "...") it works. But weirdly, not here.

I had tried to use a script previously but, same result:

#!/bin/bash
if [ "x$1" = "x" ]; then
  echo "$0 <link list>";
  exit 1;
fi

if [ ! -f "$1" ]; then
  echo "$1: File not found.";
  exit 1;
fi

for i in $(cat $1); do
  echo "URL: $i"
  anime dl "$i"
done

I am a bit confused... Ideas? o.o

IngwiePhoenix commented 4 years ago

A bit of an update:

$ ./get.sh links.txt
URL: https://9anime.to/watch/that-time-i-got-reincarnated-as-a-slime-dub.8w2y
2020-08-05 01:38:49 bigboi anime_downloader.util[1457] INFO anime-downloader 4.5.0
2020-08-05 01:38:49 bigboi anime_downloader.util[1457] DEBUG Platform: Linux-4.19.104-microsoft-standard-x86_64-with-debian-10.5
2020-08-05 01:38:49 bigboi anime_downloader.util[1457] DEBUG Python 3.7.3
2020-08-05 01:38:49 bigboi anime_downloader.sites.anime[1457] INFO Extracting episode info from page
2020-08-05 01:38:49 bigboi anime_downloader.sites.helpers.request[1457] DEBUG -----
2020-08-05 01:38:49 bigboi anime_downloader.sites.helpers.request[1457] DEBUG GET https://9anime.to/watch/that-time-i-got-reincarnated-as-a-slime-dub.8w2y
2020-08-05 01:38:49 bigboi anime_downloader.sites.helpers.request[1457] DEBUG {}
2020-08-05 01:38:49 bigboi anime_downloader.sites.helpers.request[1457] DEBUG {'user-agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.6 (KHTML, like Gecko) Chrome/20.0.1092.0 Safari/536.6'}
2020-08-05 01:38:49 bigboi anime_downloader.sites.helpers.request[1457] DEBUG -----
2020-08-05 01:38:49 bigboi anime_downloader.session[1457] DEBUG cached request
2020-08-05 01:38:49 bigboi anime_downloader.sites.helpers.request[1457] DEBUG https://9anime.to/search?keyword=that%20time%20i%20got%20reincarnated%20as%20a%20slime%20dub
2020-08-05 01:38:49 bigboi anime_downloader.sites.helpers.request[1457] DEBUG /tmp/animedluctgblgk/tmpzk2e0344
2020-08-05 01:38:49 bigboi anime_downloader.sites.anime[1457] DEBUG Metadata scraping error: list index out of range
2020-08-05 01:38:49 bigboi anime_downloader.sites.helpers.request[1457] DEBUG -----
2020-08-05 01:38:49 bigboi anime_downloader.sites.helpers.request[1457] DEBUG GET https://9anime.to/watch/that-time-i-got-reincarnated-as-a-slime-dub.8w2y
2020-08-05 01:38:49 bigboi anime_downloader.sites.helpers.request[1457] DEBUG {}
2020-08-05 01:38:49 bigboi anime_downloader.sites.helpers.request[1457] DEBUG {'user-agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.6 (KHTML, like Gecko) Chrome/20.0.1092.0 Safari/536.6'}
2020-08-05 01:38:49 bigboi anime_downloader.sites.helpers.request[1457] DEBUG -----
2020-08-05 01:38:49 bigboi anime_downloader.session[1457] DEBUG cached request
2020-08-05 01:38:49 bigboi anime_downloader.sites.helpers.request[1457] DEBUG https://9anime.to/search?keyword=that%20time%20i%20got%20reincarnated%20as%20a%20slime%20dub
2020-08-05 01:38:49 bigboi anime_downloader.sites.helpers.request[1457] DEBUG /tmp/animedluctgblgk/tmp2j7pfagx
Traceback (most recent call last):
  File "/home/ingwie/.local/bin/anime", line 8, in <module>
    sys.exit(main())
  File "/home/ingwie/.local/pipx/venvs/anime-downloader/lib/python3.7/site-packages/anime_downloader/cli.py", line 53, in main
    cli()
  File "/home/ingwie/.local/pipx/venvs/anime-downloader/lib/python3.7/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/home/ingwie/.local/pipx/venvs/anime-downloader/lib/python3.7/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/home/ingwie/.local/pipx/venvs/anime-downloader/lib/python3.7/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/ingwie/.local/pipx/venvs/anime-downloader/lib/python3.7/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/ingwie/.local/pipx/venvs/anime-downloader/lib/python3.7/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/home/ingwie/.local/pipx/venvs/anime-downloader/lib/python3.7/site-packages/click/decorators.py", line 21, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/ingwie/.local/pipx/venvs/anime-downloader/lib/python3.7/site-packages/anime_downloader/commands/dl.py", line 102, in command
    fallback_qualities=fallback_qualities)
  File "/home/ingwie/.local/pipx/venvs/anime-downloader/lib/python3.7/site-packages/anime_downloader/sites/anime.py", line 84, in __init__
    self._episode_urls = self.get_data()
  File "/home/ingwie/.local/pipx/venvs/anime-downloader/lib/python3.7/site-packages/anime_downloader/sites/anime.py", line 165, in get_data
    self._episode_urls = self._scrape_episodes()
  File "/home/ingwie/.local/pipx/venvs/anime-downloader/lib/python3.7/site-packages/anime_downloader/sites/nineanime.py", line 29, in _scrape_episodes
    title_id = soup.select("div#player")[0]
IndexError: list index out of range

Looks like I was confused in the wrong place. This seems to be a nineanime issue - nothing more or less. Please close, if my estimate is right: 9anime doesn't like me flooding them with requests through a shell script. ^^;

EDIT: Invoking the program from the shell directly and passing the url directly too, this issue no longer occurs. Also, it seems that the last line of the text file also passes.

IngwiePhoenix commented 4 years ago

Issue found. I might update the script later - but really, the issue is so silly, I forgot it was a thing. So, Microsoft Notepad saves using CRLF line endings - but my script blatantly expected LF - and a random CR character was always passed at the end of the url.

# The list of urls:
https://...\r\n
# Then in the loop:
$i = https://...\r\n
# In the command:
anime dl $i\r

Solution will be to sed for CRLF alltogether. I just used dos2unix because I was lazy for now but...that was why.