Skip to content

Commit

Permalink
Merge pull request #16 from NikhilNarayana/develop
Browse files Browse the repository at this point in the history
Merge for Version 2.3
  • Loading branch information
NikhilNarayana committed Oct 19, 2016
2 parents 26e29db + fa6e50f commit b89f7f8
Show file tree
Hide file tree
Showing 13 changed files with 70 additions and 121 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
language: python
python:
- "2.7"
cache: pip
# command to install dependencies
install: "pip install -r requirements.txt"
# command to run tests
script: nosetests
script: python test.py
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,27 @@ A YouTube Uploader with FRC Matches in mind.


## How to Setup
1. Install Python 2.7 for your OS
1. Install Python 2.7 for your OS with the PATH added and make sure there are no other versions of python.
2. Clone this repository into the folder that will contain the videos
3. Install the requirements for the script with `pip install -r /path/to/requirements.txt`
4. Add the thumbnail to the same folder as `thumbnail.png`
5. Make your recording program follow this naming scheme: [EVENT_NAME] - [MATCH TYPE] ex. 2016 Indiana State Championship - Qualification Match 1. Also use the Tiebreaker scheme when necessary.
5. Start the program by running `python start.py` and navigating to `localhost:8080` in your browser
5. Start the program by running `start.py` and navigating to `localhost:8080` in your browser
6. Add in the necessary info.
7. Hit submit everytime a match finishes. No need to update Match Number unless you are entering eliminations.
8. Enjoy not having to deal with YouTube's front end 🎉

### Web UI Breakdown
A bit out of date, but still shows the idea behind the program.
[![IMAGE ALT TEXT HERE](http://img.youtube.com/vi/6HuZ1sHrGR0/0.jpg)](http://www.youtube.com/watch?v=6HuZ1sHrGR0)

This demo shows a basic use of the application. In addition I have the data being sent to the backend shown in the console beforehand.
![alt text](http://i.imgur.com/z9PxgCP.png)

I focused on simplicty and usability. All the necessary details fit into one small space allowing you to easily place this anywhere on your screen without needing to see all of it.

##### Match File Locations
You can now pick whether the match files are in the same folder as the scripts or the one above. Default is one above.

##### Production Team/Facebook Name/Twitter Handle/Website Link
Constants that used to be in the script it self, you can now edit them as you see fit without going into the code.

##### Event Name
You can name this as you wish, but it should also be used at the start of every video filename. Generally includes [YEAR] [NAME OF EVENT]

Expand Down
5 changes: 3 additions & 2 deletions TBA.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#!/usr/bin/python
#!/usr/bin/env python

import urllib2
import tbaAPI as tba
import requests
import simplejson as json

def get_event_type(event_key):
tba.set_api_key("Nikki-Narayana","FRC-Match-Uploader","2.2")
tba.set_api_key("Nikki-Narayana","FRC-Match-Uploader","2.3")
event = tba.event_get(event_key)
return event.info["event_type_string"]

Expand Down
2 changes: 1 addition & 1 deletion addtoplaylist.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python

import httplib2
import os
Expand Down
2 changes: 1 addition & 1 deletion form_values.csv
Original file line number Diff line number Diff line change
@@ -1 +1 @@
,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,
71 changes: 39 additions & 32 deletions start.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@
import youtubeup as yup
import argparse
import csv
import pdb
from datetime import datetime

render = web.template.render('webpage/')

urls = ('/', 'index')
app = web.application(urls, globals())

dataform = form.Form(
form.Dropdown("where",
[("../","Parent Folder to Scripts"),("", "Same Folder as Scripts")],
description="Match Files Location"),
form.Textbox("prodteam", description="Production Team", size=41),
form.Textbox("twit", description="Twitter Handle", size=41),
form.Textbox("fb", description="Facebook Name", size=41),
Expand Down Expand Up @@ -62,23 +65,24 @@ def GET(self):
for value in row:
if value is not "":
switcher = {
0: form.prodteam,
1: form.twit,
2: form.fb,
3: form.web,
4: form.ename,
5: form.ecode,
6: form.pID,
7: form.tbaID,
8: form.tbaSecret,
9: form.description,
10: form.mnum,
11: form.mcode,
12: form.tiebreak,
13: form.tba,
14: form.end,
0: form.where,
1: form.prodteam,
2: form.twit,
3: form.fb,
4: form.web,
5: form.ename,
6: form.ecode,
7: form.pID,
8: form.tbaID,
9: form.tbaSecret,
10: form.description,
11: form.mnum,
12: form.mcode,
13: form.tiebreak,
14: form.tba,
15: form.end,
}
if i == 12 or i == 13:
if i == 13 or i == 14:
if value == "True": switcher[i].set_value(True)
if value == "False": switcher[i].set_value(False)
else : switcher[i].set_value(value)
Expand All @@ -91,27 +95,30 @@ def POST(self):
if not form.validates():
return render.forms(form)
else:
then = datetime.now()
reader = csv.reader(open('form_values.csv'))
row = next(reader)
parser = argparse.ArgumentParser(description='Upload videos to YouTube for FRC matches')
args = parser.parse_args()
formdata = web.input()
args.then = then
args.gui = True
args.prodteam = row[0] = form.d.prodteam
args.twit = row[1] = form.d.twit
args.fb = row[2] = form.d.fb
args.web = row[3] = form.d.web
args.ename = row[4] = form.d.ename
args.ecode = row[5] = form.d.ecode
args.pID = row[6] = form.d.pID
args.tbaID = row[7] = form.d.tbaID
args.tbaSecret = row[8] = form.d.tbaSecret
args.description = row[9] = form.d.description
args.mnum = row[10] = int(form.d.mnum)
args.mcode = row[11] = form.d.mcode
args.tiebreak, row[12] = formdata.has_key('tiebreak'), str(formdata.has_key('tiebreak'))
args.tba, row[13] = formdata.has_key('tba'), str(formdata.has_key('tba'))
args.end = row[14] = form.d.end
args.where = row[0] = form.d.where
args.prodteam = row[1] = form.d.prodteam
args.twit = row[2] = form.d.twit
args.fb = row[3] = form.d.fb
args.web = row[4] = form.d.web
args.ename = row[5] = form.d.ename
args.ecode = row[6] = form.d.ecode
args.pID = row[7] = form.d.pID
args.tbaID = row[8] = form.d.tbaID
args.tbaSecret = row[9] = form.d.tbaSecret
args.description = row[10] = form.d.description
args.mnum = row[11] = int(form.d.mnum)
args.mcode = row[12] = form.d.mcode
args.tiebreak, row[13] = formdata.has_key('tiebreak'), str(formdata.has_key('tiebreak'))
args.tba, row[14] = formdata.has_key('tba'), str(formdata.has_key('tba'))
args.end = row[15] = form.d.end
yup.init(args)
if form.d.end == "Only for batch uploads":
form.mnum.set_value(str(int(form.d.mnum) + 1))
Expand Down
Empty file modified tbaAPI.py
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion test.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python

import unittest
import tbaAPI
Expand Down
2 changes: 1 addition & 1 deletion updatePlaylistThumbnails.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python

from apiclient.errors import HttpError
from oauth2client.tools import argparser
Expand Down
Empty file modified updateThumbnail.py
100644 → 100755
Empty file.
5 changes: 0 additions & 5 deletions webpage/forms.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,4 @@ <h1>FRC Youtube Uploader</h1>
<br>
<br>
<br>
<footer>
<h5 style="margin: 3 0 0 0">Disclaimer: This has only been tested at official events and requires</h5>
<h5 style="margin: 3 0 0 0">- a high speed internet connection </h5>
<h5 style="margin: 3 0 0 0">- Event updates on TheBlueAlliance</h5>
</footer>
</body>
2 changes: 1 addition & 1 deletion youtubeAuthenticate.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python

import httplib
import httplib2
Expand Down
82 changes: 12 additions & 70 deletions youtubeup.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
#!/usr/bin/python

import httplib
import httplib2
import os
import random
import sys
import time
import argparse
import pdb

from apiclient.errors import HttpError
from apiclient.http import MediaFileUpload
Expand Down Expand Up @@ -274,12 +271,12 @@ def init(args):
print "An HTTP error %d occurred:\n%s" % (e.resp.status, e.content)

def initialize_upload(youtube, spreadsheet, options):
print "Initializing upload for %s match %s" % (options.mcode, options.mnum)
tags = None
if options.tba:
print "Initializing upload for %s match %s" % (options.mcode, options.mnum)
tags = None
blue_data, red_data, mcode = tba_results(options)

if args.dtags:
if options.dtags:
tags = options.tags.split(",")
tags.append("frc" + str(blue_data[1]))
tags.append("frc" + str(blue_data[2]))
Expand All @@ -301,17 +298,7 @@ def initialize_upload(youtube, spreadsheet, options):
privacyStatus=VALID_PRIVACY_STATUSES[options.privacyStatus]
)
)
insert_request = youtube.videos().insert(
part=",".join(body.keys()),
body=body,
media_body=MediaFileUpload(
create_filename(options), chunksize=-1, resumable=True)
)

resumable_upload(insert_request, options.mnum, mcode, youtube)
else:
print "Initializing upload for %s match %s" % (options.mcode, options.mnum)
tags = None
mcode = get_match_code(options.mcode, int(options.mnum))

if options.tags:
Expand All @@ -329,14 +316,13 @@ def initialize_upload(youtube, spreadsheet, options):
privacyStatus=VALID_PRIVACY_STATUSES[options.privacyStatus]
)
)
insert_request = youtube.videos().insert(
insert_request = youtube.videos().insert(
part=",".join(body.keys()),
body=body,
media_body=MediaFileUpload(
create_filename(options), chunksize=-1, resumable=True)
media_body=MediaFileUpload(options.where+create_filename(options), chunksize=-1, resumable=True)
)

resumable_upload(insert_request, options, mcode, youtube, spreadsheet)
resumable_upload(insert_request, options, mcode, youtube, spreadsheet)

def resumable_upload(insert_request, options, mcode, youtube, spreadsheet):
response = None
Expand All @@ -359,12 +345,14 @@ def resumable_upload(insert_request, options, mcode, youtube, spreadsheet):
request_body = json.dumps({mcode: response['id']})
if options.tba is True:
post_video(options.tbaID, options.tbaSecret, request_body, options.ecode)
totalTime = datetime.now() - options.then
spreadsheetID = "18flsXvAcYvQximmeyG0-9lhYtb5jd_oRtKzIN7zQDqk"
rowRange = "Data!A1:E1"
values = [[str(datetime.now()),"https://www.youtube.com/watch?v=%s" % response['id'], str(options.tba), options.ename, options.prodteam]]
rowRange = "Data!A1:F1"
if type(options.end) is int: wasBatch = "True"
else: wasBatch = "False"
values = [[str(datetime.now()),str(totalTime),"https://www.youtube.com/watch?v=%s" % response['id'], str(options.tba), options.ename, wasBatch]]
body = {'values': values}
appendSpreadsheet = spreadsheet.spreadsheets().values().append(spreadsheetId=spreadsheetID, range=rowRange, valueInputOption="RAW", body=body).execute()

else:
exit("The upload failed with an unexpected response: %s" %
response)
Expand Down Expand Up @@ -392,50 +380,4 @@ def resumable_upload(insert_request, options, mcode, youtube, spreadsheet):
# COMMAND LINE USE IS DEPRECATED. USING IT WILL CAUSE ERRORS THAT REQUIRE CODE REWRITES
print "COMMAND LINE USE IS DEPRECATED. USING IT WILL CAUSE ERRORS THAT REQUIRE A CODE REWRITE"
print "Use 'python start.py' instead"
sys.exit(0)
#The following is in case you actually want to try to make the command line side work
parser = argparse.ArgumentParser(description='Upload videos to YouTube for FRC matches')
parser.add_argument('--mnum',
type=int,
help="""Match Number to add, if in elims
keep incrementing by one unless for tiebreaker,
in which case add 8(qf), 4(sf), or 2(f) to the tiebreaker number""")
parser.add_argument('--mcode',
type=int,
help='Match code (qm,qf,sf,f) starting at 0 ->3',
default=0)
parser.add_argument('--tiebreak',
type=bool,
help="True or False, default is False",
default=False)
parser.add_argument('--file',
help="Video file to upload. Only necessary if you are using a different naming scheme",
default=DEFAULT_FILE)
parser.add_argument("--title",
help="Video title. Only necessary if you are using a different naming scheme",
default=DEFAULT_TITLE)
parser.add_argument("--description",
help="Video description.",
default=DEFAULT_DESCRIPTION)
parser.add_argument("--category",
help="""Numeric video category.
See https://developers.google.com/youtube/v3/docs/videoCategories/list""",
default=DEFAULT_VIDEO_CATEGORY)
parser.add_argument("--tags",
help="Video keywords, comma separated",
default=DEFAULT_TAGS)
parser.add_argument("--privacyStatus",
"--privacyStatus",
type=int,
help="Video privacy status, public (0), private (1), unlisted (2))",
default=2)
parser.add_argument("--end",
help="""The last match you would like to upload, must be continous.
Only necessary if you want to batch upload""",
default=None)
parser.add_argument("--gui",
help="Switches the program to use the GUI data",
default=False)
args = parser.parse_args()

init(args)
sys.exit(0)

0 comments on commit b89f7f8

Please sign in to comment.