mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-09-18 21:50:56 +00:00
Adding duration and channel info to youtube videos.
This commit is contained in:
parent
23fd3cccc1
commit
d22d81859a
4 changed files with 30 additions and 5 deletions
|
@ -20,6 +20,7 @@ gunicorn==19.1.1
|
|||
# psycopg2==2.5.2
|
||||
httplib2==0.8
|
||||
iconv==1.0
|
||||
isodate==0.5.1
|
||||
kombu==2.5.7
|
||||
lxml==3.3.5
|
||||
mongoengine==0.8.2
|
||||
|
@ -37,7 +38,7 @@ raven==3.1.17
|
|||
readline==6.2.4.1
|
||||
redis==2.8.0
|
||||
hiredis==0.1.1
|
||||
requests==2.3.0
|
||||
requests==2.5.2
|
||||
seacucumber==1.5
|
||||
South==0.7.6
|
||||
stripe==1.12.2
|
||||
|
|
2
fabfile.py
vendored
2
fabfile.py
vendored
|
@ -1146,6 +1146,8 @@ def setup_do(name, size=2, image=None):
|
|||
print images
|
||||
image_id = images[IMAGE_NAME]
|
||||
else:
|
||||
if image == "task":
|
||||
image = "task_05-2015"
|
||||
IMAGE_NAME = image
|
||||
images = dict((s.name, s.id) for s in doapi.images(show_all=False))
|
||||
image_id = images[IMAGE_NAME]
|
||||
|
|
|
@ -2722,6 +2722,10 @@ body {
|
|||
max-width: 99% !important;
|
||||
}
|
||||
|
||||
.NB-feed-story .NB-youtube-stats {
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
.NB-feed-story .NB-feed-story-content div {
|
||||
max-width: 100%;
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import pymongo
|
|||
import re
|
||||
import requests
|
||||
import dateutil.parser
|
||||
import isodate
|
||||
from django.conf import settings
|
||||
from django.db import IntegrityError
|
||||
from django.core.cache import cache
|
||||
|
@ -180,13 +181,14 @@ class FetchFeed:
|
|||
for video_id in video_ids_soup.findAll('yt:videoid'):
|
||||
video_ids.append(video_id.getText())
|
||||
|
||||
videos_json = requests.get("https://www.googleapis.com/youtube/v3/videos?part=player%%2Csnippet&id=%s&key=%s" %
|
||||
videos_json = requests.get("https://www.googleapis.com/youtube/v3/videos?part=contentDetails%%2Csnippet&id=%s&key=%s" %
|
||||
(','.join(video_ids), settings.YOUTUBE_API_KEY))
|
||||
videos = json.decode(videos_json.content)
|
||||
|
||||
channel_url = video_ids_soup.find('author').find('uri').getText()
|
||||
|
||||
data = {}
|
||||
data['title'] = "%s's YouTube Videos" % username
|
||||
data['link'] = video_ids_soup.find('author').find('uri').getText()
|
||||
data['link'] = channel_url
|
||||
data['description'] = description
|
||||
data['lastBuildDate'] = datetime.datetime.utcnow()
|
||||
data['generator'] = 'NewsBlur YouTube API v3 Decrapifier - %s' % settings.NEWSBLUR_URL
|
||||
|
@ -200,10 +202,26 @@ class FetchFeed:
|
|||
thumbnail = video['snippet']['thumbnails'].get('high')
|
||||
if not thumbnail:
|
||||
thumbnail = video['snippet']['thumbnails'].get('medium')
|
||||
duration_sec = isodate.parse_duration(video['contentDetails']['duration']).seconds
|
||||
if duration_sec >= 3600:
|
||||
hours = (duration_sec / 3600)
|
||||
minutes = (duration_sec - (hours*3600)) / 60
|
||||
seconds = duration_sec - (hours*3600) - (minutes*60)
|
||||
duration = "%s:%s:%s" % (hours, '{0:02d}'.format(minutes), '{0:02d}'.format(seconds))
|
||||
else:
|
||||
minutes = duration_sec / 60
|
||||
seconds = duration_sec - (minutes*60)
|
||||
duration = "%s:%s" % ('{0:02d}'.format(minutes), '{0:02d}'.format(seconds))
|
||||
content = """<div class="NB-youtube-player"><iframe allowfullscreen="true" src="%s"></iframe></div>
|
||||
<div class="NB-youtube-stats"><small>
|
||||
<b>From:</b> <a href="%s">%s</a><br />
|
||||
<b>Duration:</b> %s<br />
|
||||
</small></div><hr>
|
||||
<div class="NB-youtube-description">%s</div>
|
||||
<img src="%s" style="display:none" />""" % (
|
||||
("http://www.youtube.com/embed/" + video['id']),
|
||||
("https://www.youtube.com/embed/" + video['id']),
|
||||
channel_url, username,
|
||||
duration,
|
||||
linkify(linebreaks(video['snippet']['description'])),
|
||||
thumbnail['url'] if thumbnail else "",
|
||||
)
|
||||
|
|
Loading…
Add table
Reference in a new issue