所以我的目标是编写代码,以便它可以自动从我订阅的所有 Youtube 频道下载到 mp3 文件。我很难处理EO error
我不清楚的问题,因此我从来不需要处理它,我已经做过研究,但没有什么可以帮助我,所以这里是代码:
import opml
import feedparser
import youtube_dl
from glob import glob
from pprint import pprint
from time import time, mktime, strptime
from datetime import datetime
if len(glob('last.txt')) == 0:
f = open ('last.txt' , 'w')
f.write(str(time()))
print('Initialized last.txt file for timestamp')
f.close()
else:
f = open('last.txt' , 'r')
content = f.read()
f.close()
outline = opml.parse('subs.xml')
ptime = datetime.utcfromtimestamp(float(content))
ftime = time()
urls = []
for i in range(0,len(outline[0])):
urls.append(outline[0][i].xmlUrl)
print(urls)
videos = []
for i in range(0,len(urls)):
print('Parsing through channel '+str(i+1)+' out of '+str(len(urls)), end='\r')
feed = feedparser.parse(urls[i])
for j in range(0,len(feed['items'])):
timef = feed['items'][j]['published_parsed']
dt = datetime.fromtimestamp(mktime(timef))
if dt > ptime:
videos.append(feed['items'][j]['link'])
if len(videos) == 0:
print('Sorry, no new video found')
else:
print(str(len(videos))+' bew vudeis found')
ydl_options = {
'ignoreerrors' : True,
'format': 'bestaudio[filesize<30]',
'keepvideo': False,
'outtmpl': 'filename',
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'audioquality': '0',
'preferredquality': '320',
}]
}
with youtube_dl.YoutubeDL(ydl_options) as ydl:
ydl.download(videos)
我尝试了新的 YoutubeManager subs.xml ,尝试了其他具有不同频道的 Youtube 帐户,他们的 subs.xml 没有任何帮助。
这是我的错误输出
runfile('C:/Users/sound/Desktop/PythonProjets/youtubesubscriptions.py', wdir='C:/Users/sound/Desktop/PythonProjets')
Traceback (most recent call last):
File "<ipython-input-1-ff8a84b96d09>", line 1, in <module>
runfile('C:/Users/sound/Desktop/PythonProjets/youtubesubscriptions.py', wdir='C:/Users/sound/Desktop/PythonProjets')
File "C:\Users\sound\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 786, in runfile
execfile(filename, namespace)
File "C:\Users\sound\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/sound/Desktop/PythonProjets/youtubesubscriptions.py", line 29, in <module>
outline = opml.parse('subs.xml')
File "C:\Users\sound\Anaconda3\lib\site-packages\opml\__init__.py", line 67, in parse
return Opml(lxml.etree.parse(opml_url))
File "src/lxml/etree.pyx", line 3435, in lxml.etree.parse
File "src/lxml/parser.pxi", line 1840, in lxml.etree._parseDocument
File "src/lxml/parser.pxi", line 1866, in lxml.etree._parseDocumentFromURL
File "src/lxml/parser.pxi", line 1770, in lxml.etree._parseDocFromFile
File "src/lxml/parser.pxi", line 1163, in lxml.etree._BaseParser._parseDocFromFile
File "src/lxml/parser.pxi", line 601, in lxml.etree._ParserContext._handleParseResultDoc
File "src/lxml/parser.pxi", line 711, in lxml.etree._handleParseResult
File "src/lxml/parser.pxi", line 638, in lxml.etree._raiseParseError
OSError: Error reading file 'subs.xml': failed to load external entity "subs.xml"