Skip to content

Commit

Permalink
Merge pull request #21 from WKuipers/master
Browse files Browse the repository at this point in the history
Duration werkt weer!
  • Loading branch information
jjmartens committed Jun 9, 2015
2 parents f8d644c + 7035fc2 commit 44dffd5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def add(channel_slug):
video = Video.query.filter_by(code=id).first()
if not video:
title = data["title"]
duration = 183
duration = data["duration"]
video = Video(id, title=title,duration=duration)
db.session.add(video)
db.session.commit()
Expand Down
15 changes: 14 additions & 1 deletion static/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,20 @@ app.controller('IndexController', function ($scope, $http, $log,$timeout, $rootS
}

$scope.add = function (id, title) {
$http.post('/' + $scope.channel + '/add', {"id": id, "title":title}).
$http.get('https://www.googleapis.com/youtube/v3/videos', {
params: {
key: 'AIzaSyBI27WBKxhL4TUZ1XAiPK5Z9CPBRfx7iKA',
part: 'contentDetails',
id: id
}
})
.success( function (data) {
var match = (data.items[0].contentDetails.duration.match(/PT(\d+H)?(\d+M)?(\d+S)?/));
var hours = (parseInt(match[1]) || 0);
var minutes = (parseInt(match[2]) || 0);
var seconds = (parseInt(match[3]) || 0);
var duration = hours * 3600 + minutes * 60 + seconds;
$http.post('/' + $scope.channel + '/add', {"id": id, "title":title, "duration":duration }).
success(function(results) {
$scope.query = "";
$scope.results.length = 0;
Expand Down

0 comments on commit 44dffd5

Please sign in to comment.