mirror of
https://github.com/viq/NewsBlur.git
synced 2025-09-18 21:43:31 +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
|
# psycopg2==2.5.2
|
||||||
httplib2==0.8
|
httplib2==0.8
|
||||||
iconv==1.0
|
iconv==1.0
|
||||||
|
isodate==0.5.1
|
||||||
kombu==2.5.7
|
kombu==2.5.7
|
||||||
lxml==3.3.5
|
lxml==3.3.5
|
||||||
mongoengine==0.8.2
|
mongoengine==0.8.2
|
||||||
|
@ -37,7 +38,7 @@ raven==3.1.17
|
||||||
readline==6.2.4.1
|
readline==6.2.4.1
|
||||||
redis==2.8.0
|
redis==2.8.0
|
||||||
hiredis==0.1.1
|
hiredis==0.1.1
|
||||||
requests==2.3.0
|
requests==2.5.2
|
||||||
seacucumber==1.5
|
seacucumber==1.5
|
||||||
South==0.7.6
|
South==0.7.6
|
||||||
stripe==1.12.2
|
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
|
print images
|
||||||
image_id = images[IMAGE_NAME]
|
image_id = images[IMAGE_NAME]
|
||||||
else:
|
else:
|
||||||
|
if image == "task":
|
||||||
|
image = "task_05-2015"
|
||||||
IMAGE_NAME = image
|
IMAGE_NAME = image
|
||||||
images = dict((s.name, s.id) for s in doapi.images(show_all=False))
|
images = dict((s.name, s.id) for s in doapi.images(show_all=False))
|
||||||
image_id = images[IMAGE_NAME]
|
image_id = images[IMAGE_NAME]
|
||||||
|
|
|
@ -2722,6 +2722,10 @@ body {
|
||||||
max-width: 99% !important;
|
max-width: 99% !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.NB-feed-story .NB-youtube-stats {
|
||||||
|
margin-top: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
.NB-feed-story .NB-feed-story-content div {
|
.NB-feed-story .NB-feed-story-content div {
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ import pymongo
|
||||||
import re
|
import re
|
||||||
import requests
|
import requests
|
||||||
import dateutil.parser
|
import dateutil.parser
|
||||||
|
import isodate
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db import IntegrityError
|
from django.db import IntegrityError
|
||||||
from django.core.cache import cache
|
from django.core.cache import cache
|
||||||
|
@ -180,13 +181,14 @@ class FetchFeed:
|
||||||
for video_id in video_ids_soup.findAll('yt:videoid'):
|
for video_id in video_ids_soup.findAll('yt:videoid'):
|
||||||
video_ids.append(video_id.getText())
|
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))
|
(','.join(video_ids), settings.YOUTUBE_API_KEY))
|
||||||
videos = json.decode(videos_json.content)
|
videos = json.decode(videos_json.content)
|
||||||
|
channel_url = video_ids_soup.find('author').find('uri').getText()
|
||||||
|
|
||||||
data = {}
|
data = {}
|
||||||
data['title'] = "%s's YouTube Videos" % username
|
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['description'] = description
|
||||||
data['lastBuildDate'] = datetime.datetime.utcnow()
|
data['lastBuildDate'] = datetime.datetime.utcnow()
|
||||||
data['generator'] = 'NewsBlur YouTube API v3 Decrapifier - %s' % settings.NEWSBLUR_URL
|
data['generator'] = 'NewsBlur YouTube API v3 Decrapifier - %s' % settings.NEWSBLUR_URL
|
||||||
|
@ -200,10 +202,26 @@ class FetchFeed:
|
||||||
thumbnail = video['snippet']['thumbnails'].get('high')
|
thumbnail = video['snippet']['thumbnails'].get('high')
|
||||||
if not thumbnail:
|
if not thumbnail:
|
||||||
thumbnail = video['snippet']['thumbnails'].get('medium')
|
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>
|
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>
|
<div class="NB-youtube-description">%s</div>
|
||||||
<img src="%s" style="display:none" />""" % (
|
<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'])),
|
linkify(linebreaks(video['snippet']['description'])),
|
||||||
thumbnail['url'] if thumbnail else "",
|
thumbnail['url'] if thumbnail else "",
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Reference in a new issue