I want to :
1/Fetch youtube-channel or playlist
2/take the url of videos.
3/process them : view them to the user, or start downloading by anotrher download manager.
Function to get information from youtube-dl :
thanks to jaimeMF answer
import time
import youtube_dl
def myfunc(url):
ydl = youtube_dl.YoutubeDL()
# Add all the available extractors
ydl.add_default_info_extractors()
result = ydl.extract_info( url , download=False)
## ydl.extract_info() collect `url fetched info` in local variable called "ie_result"; It return this "ie_result" when finshed.
if 'entries' in result: # Can be a playlist or a list of videos
video = result['entries'][0]
else:
# Just a video
video = result # get desired data
res.append(desired data)
return res
Problem:
If the url
is youtube:channel
or youtube:playlist
; youtube-dl will fetch urls one by one; consuming long time to return information; you can imagine the time of fetching cannel contaiing 500 videos information
.
So I want to get the res
list simultaneously; to start viewing them to the user or start downloading them by another downloader. etc.
Trial:
I think in the following design :
def get_res():
args = ['http://www.youtube.com/channel/url']
thread1 = threading.Thread(target=myfun , args )
thread1.run()
# access myfun.res.ie_result by anyway #.... this is the problem
# return its value
def worker():
processed_res = []
while True:
res = get_res()
for item in res :
if item not in processed_res:
# do something like;
# start viewing it to the user,
# or start downloading them by another downloader.
processed_res.append(item)
time.sleep(1)
# break when tread1 terminate
get_res()
worker()
The code defect:
The actual problem remain in *access myfun.res.ie_result by anyway * in the function get_res
;
in brief:
Is it possible to access the local variable of running function from other thread ? Any help is appreciated :D Any trial to solve the problem by another way is also.
* Items to be remembered :*
I have edited the code to bit clarify it.
the
myfun
call theextract_info()
function. in itsresult
local variable.the
extract_info()
function collect results in variable calledie_result
extract_info
fetch the url data one by one the return all in a list. collecting it.The
myfun.res.ie_result
is equal toydl.extract_info(url).ie_result