Skip to content
This repository was archived by the owner on Aug 20, 2021. It is now read-only.

Commit 0f936a9

Browse files
authored
Merge pull request #6 from geniuslounge/latest
update the latest work so that it uses the proper urls.
2 parents 3fc2a75 + da35787 commit 0f936a9

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,4 @@ All you need to do is set the following environment variables:
4040
* `DISABLE_COLLECTSTATIC = 1` - For heroku config, this was required, as it doesn't even have a DB, or defined static files!
4141
* `django_secret_key` - because making your secret key public in GitHub is bad luck.
4242
* `yt_api_key` - Your [YouTube API key](https://console.cloud.google.com/apis/library/youtube.googleapis.com?q=youtube)
43+
* `channel_id` - Your YouTube channel id, for `/latest/` lookups, etc...

youtube/urls.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from django.urls import path
22

33
from . import views
4+
import os
5+
channel_id = os.environ['channel_id']
46

57
urlpatterns = [
68
path('', views.home, name='index'),
@@ -9,10 +11,10 @@
911
path('android', views.redirect, {"url": "https://www.youtube.com/playlist?list=PLdr1YBmf_Da8do3vXAz72j8xGChHJM-3h"}),
1012
path('favicon.ico', views.redirect, {"url":"https://assets.geniuslounge.com/favicon.ico"}),
1113
path('static/favicon.ico', views.redirect, {"url":"https://assets.geniuslounge.com/favicon.ico"}),
12-
path('latest', views.redirect, {"url":"https://www.tubebuddy.com/quicknav/latest/UCU261fOCKtUwxigoCcZuVHQ"}),
14+
path('latest', views.redirect, {"url":"http://"+os.environ['channel_domain']+"/"+views.latest_video(channel_id)}),
1315
path('feed/<slug:channel_id>', views.feed, name='feed'),
1416
path('live/', views.home, name='live'),
1517
path('live', views.home, name='live'),
1618
path('live/<slug:video_id>', views.index, name='live'),
1719
path('<slug:video_id>', views.index, name='index'), # Needs to be last so all the other possibilites can go first.
18-
]
20+
]

youtube/views.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,9 @@ def feed(request, channel_id):
4545

4646
}
4747
return HttpResponse(template.render(context,request))
48+
49+
50+
def latest_video(channel_id):
51+
latest_video_dict = channel_feed(channel_id,1)
52+
video_id = latest_video_dict['items'][0]['id']['videoId']
53+
return video_id

youtube/yt_fetch.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ def request_is_live(request, video_id):
7070
return False
7171

7272

73-
def channel_feed(channel_id):
73+
def channel_feed(channel_id, number_of_feed_items=25):
7474
"""Outputs a RFC822 compatible RSS feed for the last 25 videos from a given channel_id"""
7575
payload = { 'part':'snippet',
7676
'channelId':channel_id,
77-
'maxResults':"25",
77+
'maxResults':number_of_feed_items,
7878
'order':'date',
7979
'type':'video',
8080
'key':yt_api_key

0 commit comments

Comments
 (0)