ColdGrub1384 / LibTerm

iOS sandboxed terminal with Python, Lua and Clang
https://libterm.app
MIT License
630 stars 115 forks source link

Pafy error #16

Closed masterxp22 closed 5 years ago

masterxp22 commented 5 years ago

Hi i have installed Pafy module in libterm and when executing a python script from file (2.7 and 3.7) the first time it works but when i execute it the second time it gives me error. If i kill the app and reopen it, script first works and second time it fails. It seems like python does’t close properly after executing the script.

This is the script:

import pafy urlyoutube = ('https://youtu.be/aDCcLQto5BM') video = pafy.new(urlyoutube) print (video.title)

And here you can see the error:

LibTerm version 4.3 (1), 14 Jan 2019 at 20:40 Last login: 19 Jan 2019 at 15:31 iPhone $ python maininput.py Danny Ocean - Me Rehúso (Official Audio) iPhone $ python maininput.py Traceback (most recent call last): File "maininput.py", line 3, in video = pafy.new(urlyoutube) File "/var/mobile/Containers/Data/Application/477FB538-0FA2-452F-82A9-275A79C028E8/Documents/site-packages3/pafy/pafy.py", line 124, in new return Pafy(url, basic, gdata, size, callback, ydl_opts) File "/var/mobile/Containers/Data/Application/477FB538-0FA2-452F-82A9-275A79C028E8/Documents/site-packages3/pafy/backend_youtube_dl.py", line 29, in init super(YtdlPafy, self).init(*args, **kwargs) File "/var/mobile/Containers/Data/Application/477FB538-0FA2-452F-82A9-275A79C028E8/Documents/site-packages3/pafy/backend_shared.py", line 96, in init self._fetch_basic() File "/var/mobile/Containers/Data/Application/477FB538-0FA2-452F-82A9-275A79C028E8/Documents/site-packages3/pafy/backend_youtube_dl.py", line 38, in _fetch_basic self._ydl_info = ydl.extract_info(self.videoid, download=False) File "/var/mobile/Containers/Data/Application/477FB538-0FA2-452F-82A9-275A79C028E8/Documents/site-packages3/youtube_dl/YoutubeDL.py", line 793, in extract_info ie_result = ie.extract(url) File "/var/mobile/Containers/Data/Application/477FB538-0FA2-452F-82A9-275A79C028E8/Documents/site-packages3/youtube_dl/extractor/common.py", line 508, in extract ie_result = self._real_extract(url) File "/var/mobile/Containers/Data/Application/477FB538-0FA2-452F-82A9-275A79C028E8/Documents/site-packages3/youtube_dl/extractor/youtube.py", line 2026, in _real_extract upload_date = unified_strdate(upload_date) File "/var/mobile/Containers/Data/Application/477FB538-0FA2-452F-82A9-275A79C028E8/Documents/site-packages3/youtube_dl/utils.py", line 1249, in unified_strdate upload_date = datetime.datetime.strptime(date_str, expression).strftime('%Y%m%d') TypeError: 'NoneType' object is not callable

ColdGrub1384 commented 5 years ago

Thanks for reporting. The error is raised by youtube_dl on file youtube_dl/utils.py.

try:
    upload_date = datetime.datetime(*timetuple[:6]).strftime('%Y%m%d')
except ValueError:
     pass

It's raised on this line:

upload_date = datetime.datetime(*timetuple[:6]).strftime('%Y%m%d')

The script only catches ValueError but a TypeError is raised so the error isn't handled.

I replaced

try:
    upload_date = datetime.datetime(*timetuple[:6]).strftime('%Y%m%d')
except ValueError:
     pass

by

try:
    upload_date = datetime.datetime(*timetuple[:6]).strftime('%Y%m%d')
except ValueError:
     pass
except TypeError:
     pass

To fix the error run these commands:

$ rm ~/Documents/site-packages3/youtube_dl/utils.py
$ curl https://raw.githubusercontent.com/ColdGrub1384/youtube-dl_LibTerm/master/youtube_dl/utils.py -o site-packages3/youtube_dl/utils.py
masterxp22 commented 5 years ago

Thank you very much for the fix. It works! So does this behavior of Libterm is right? For example in Pythonista it doesn’t give this error (even without the fix). And even in Libterm if i execute script (without the fix) in python’s console multiple times it works. But if i quit console with “stop” button and re execute script it will give error, otherwise quiting python with os._exit(0) it works.

ColdGrub1384 commented 5 years ago

The behavior of LibTerm is different than Pythonista. And both are also different than on a computer. Pythonista is an IDE, without command line (except the REPL). What Pythonista does is that the REPL is always running and runs scripts on top of it. LibTerm runs the interpreter and when its stoped the thread running it is stopped. So I think the problem should be when "Stop" is pressed the thread is just stopped but no cleanup functions is called. I will include this youtube_dl version in the next update.

masterxp22 commented 5 years ago

Very well! Do you know a way to call a cleanup function after executing a script from file with python? It could be a fix for other modules. Or you should include it in stop button and after a script file finish to run. Because for example after youtube-dl’s bug, sometimes python crash on startup and cleanup with os._exit() doesn’t work anymore. The only way is to kill the app.

masterxp22 commented 5 years ago

I’m not sure Apple will appreciate youtube-dl on AppStore. :D Be carefull we don’t want Libterm to be removed from AppStore.