Use data extractor module on /watch
This commit is contained in:
parent
a7c1eff8e2
commit
0451f6c16e
@ -7,6 +7,7 @@ from requests_futures.sessions import FuturesSession
|
|||||||
from werkzeug.datastructures import Headers
|
from werkzeug.datastructures import Headers
|
||||||
from concurrent.futures import as_completed
|
from concurrent.futures import as_completed
|
||||||
from werkzeug.utils import secure_filename
|
from werkzeug.utils import secure_filename
|
||||||
|
from youtube_data import videos as ytvids
|
||||||
from youtube_search import YoutubeSearch
|
from youtube_search import YoutubeSearch
|
||||||
from werkzeug.urls import url_parse
|
from werkzeug.urls import url_parse
|
||||||
from youtube_dl import YoutubeDL
|
from youtube_dl import YoutubeDL
|
||||||
@ -298,7 +299,6 @@ def unfollowYoutubeChannel(channelId):
|
|||||||
if channel:
|
if channel:
|
||||||
db.session.delete(channel)
|
db.session.delete(channel)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
print(channel)
|
|
||||||
flash("{} unfollowed!".format(name))
|
flash("{} unfollowed!".format(name))
|
||||||
except:
|
except:
|
||||||
flash("There was an error unfollowing the user. Try again.")
|
flash("There was an error unfollowing the user. Try again.")
|
||||||
@ -319,22 +319,20 @@ def channel(id):
|
|||||||
@login_required
|
@login_required
|
||||||
def watch():
|
def watch():
|
||||||
id = request.args.get('v', None)
|
id = request.args.get('v', None)
|
||||||
ydl = YoutubeDL()
|
info = ytvids.get_video_info(id)
|
||||||
data = ydl.extract_info(id, False)
|
|
||||||
if data['formats'][-1]['url'].find("manifest.googlevideo") > 0:
|
|
||||||
flash("Livestreams are not yet supported!")
|
|
||||||
return redirect(url_for('youtube'))
|
|
||||||
|
|
||||||
video = {
|
video = {
|
||||||
'title':data['title'],
|
'title':info['video']['title'],
|
||||||
'description':Markup(markupString(data['description'])),
|
'description':Markup(markupString(info['video']['description'])),
|
||||||
'viewCount':data['view_count'],
|
'viewCount':info['video']['views'],
|
||||||
'author':data['uploader'],
|
'author':info['video']['author'],
|
||||||
'authorUrl':data['uploader_url'],
|
'authorUrl':"/channel/{}".format(info['owner']['id']),
|
||||||
'channelId': data['uploader_id'],
|
'channelId': info['owner']['id'],
|
||||||
'id':id,
|
'id':id,
|
||||||
'averageRating': str((float(data['average_rating'])/5)*100),
|
'averageRating': str((float(info['video']['rating'])/5)*100),
|
||||||
'videoUrl': data['formats'][-1]['url']
|
'videoUrl': info['video']['url'],
|
||||||
|
'isLive': info['video']['isLive'],
|
||||||
|
'isUpcoming': info['video']['isUpcoming'],
|
||||||
|
'thumbnail': info['video']['thumbnail']
|
||||||
}
|
}
|
||||||
return render_template("video.html", video=video, title='{}'.format(video['title']), config=config)
|
return render_template("video.html", video=video, title='{}'.format(video['title']), config=config)
|
||||||
|
|
||||||
@ -755,21 +753,30 @@ def getYoutubePosts(ids):
|
|||||||
# Try to get time diff
|
# Try to get time diff
|
||||||
time = datetime.datetime.now() - datetime.datetime(*vid.published_parsed[:6])
|
time = datetime.datetime.now() - datetime.datetime(*vid.published_parsed[:6])
|
||||||
except:
|
except:
|
||||||
# If youtube rss fucks it up set time to 0.
|
# If youtube rss does not have parsed time, generate it. Else set time to 0.
|
||||||
time = datetime.datetime.now() - datetime.datetime.now()
|
try:
|
||||||
|
time = datetime.datetime.now() - datetime.datetime(datetime.datetime.strptime(vid.published, '%y-%m-%dT%H:%M:%S+00:00'))
|
||||||
|
except:
|
||||||
|
time = datetime.datetime.now() - datetime.datetime.now()
|
||||||
|
|
||||||
if time.days >=7:
|
if time.days >=6:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
video = ytPost()
|
video = ytPost()
|
||||||
try:
|
try:
|
||||||
video.date = vid.published_parsed
|
video.date = vid.published_parsed
|
||||||
except:
|
except:
|
||||||
video.date = datetime.datetime.utcnow().timetuple()
|
try:
|
||||||
|
video.date = datetime.datetime.strptime(vid.published, '%y-%m-%dT%H:%M:%S+00:00').timetuple()
|
||||||
|
except:
|
||||||
|
video.date = datetime.datetime.utcnow().timetuple()
|
||||||
try:
|
try:
|
||||||
video.timeStamp = getTimeDiff(vid.published_parsed)
|
video.timeStamp = getTimeDiff(vid.published_parsed)
|
||||||
except:
|
except:
|
||||||
video.timeStamp = "Unknown"
|
if time != 0:
|
||||||
|
video.timeStamp = "{} days".format(str(time.days))
|
||||||
|
else:
|
||||||
|
video.timeStamp = "Unknown"
|
||||||
|
|
||||||
video.channelName = vid.author_detail.name
|
video.channelName = vid.author_detail.name
|
||||||
video.channelId = vid.yt_channelid
|
video.channelId = vid.yt_channelid
|
||||||
|
Reference in New Issue
Block a user