View difference between Paste ID: NhbzSuAa and q9XsERAZ
SHOW: | | - or go back to the newest paste.
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python
2-
2+
3-
from pytube import YouTube
3+
from pytube import YouTube
4-
import dailymotion
4+
import dailymotion
5-
import os
5+
import os
6-
import sys
6+
import sys
7-
from urlparse import urlparse
7+
from urlparse import urlparse
8-
from pprint import pprint
8+
from pprint import pprint
9-
import subprocess 
9+
import subprocess 
10-
from apiclient.discovery import build
10+
from apiclient.discovery import build
11-
from apiclient.errors import HttpError
11+
from apiclient.errors import HttpError
12-
from oauth2client.tools import argparser
12+
from oauth2client.tools import argparser
13-
import random
13+
import random
14-
14+
15-
API_KEY    = "" #dailymotion api key
15+
API_KEY    = "" #dailymotion api key
16-
API_SECRET = "" #dailymotion api secret
16+
API_SECRET = "" #dailymotion api secret
17-
USERNAME   = "" #dailymotion username
17+
USERNAME   = "" #dailymotion username
18-
PASSWORD   = "" #dailymotion password
18+
PASSWORD   = "" #dailymotion password
19-
19+
20-
DEVELOPER_KEY = "" #youtube api key
20+
DEVELOPER_KEY = "" #youtube api key
21-
YOUTUBE_API_SERVICE_NAME = "youtube"
21+
YOUTUBE_API_SERVICE_NAME = "youtube"
22-
YOUTUBE_API_VERSION = "v3"
22+
YOUTUBE_API_VERSION = "v3"
23-
23+
24-
def youtube_search(query,options={}):
24+
def youtube_search(query,options={}):
25-
  youtube = build(YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION,
25+
  youtube = build(YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION,
26-
    developerKey=DEVELOPER_KEY)
26+
    developerKey=DEVELOPER_KEY)
27-
27+
28-
  # Call the search.list method to retrieve results matching the specified
28+
  # Call the search.list method to retrieve results matching the specified
29-
  # query term.
29+
  # query term.
30-
  search_response = youtube.search().list(
30+
  search_response = youtube.search().list(
31-
    q=query,
31+
    q=query,
32-
    type='video',
32+
    type='video',
33-
    part="id,snippet",
33+
    part="id,snippet",
34-
    videoDuration='short',
34+
    videoDuration='short',
35-
    maxResults=25
35+
    maxResults=25
36-
  ).execute()
36+
  ).execute()
37-
37+
38-
  videos = []
38+
  videos = []
39-
  channels = []
39+
  channels = []
40-
  playlists = []
40+
  playlists = []
41-
  pprint(search_response)
41+
  for search_result in search_response.get("items", []):
42-
  # Add each result to the appropriate list, and then display the lists of
42+
    if search_result["id"]["kind"] == "youtube#video":
43-
  # matching videos, channels, and playlists.
43+
      videos.append(search_result["id"]["videoId"])
44-
  for search_result in search_response.get("items", []):
44+
45-
    if search_result["id"]["kind"] == "youtube#video":
45+
  return videos
46-
      videos.append(search_result["id"]["videoId"])
46+
47-
47+
vds = youtube_search(sys.argv.pop(1)) #use first word on command line as search 
48-
  return videos
48+
#i just pick a random word from 'usr/share/dict/words
49-
49+
50-
vds = youtube_search(sys.argv.pop(1))
50+
d = dailymotion.Dailymotion()
51-
51+
52-
d = dailymotion.Dailymotion()
52+
d.set_grant_type('password', api_key=API_KEY, api_secret=API_SECRET,
53-
53+
    scope=['manage_videos'], info={'username': USERNAME, 'password': PASSWORD})
54-
d.set_grant_type('password', api_key=API_KEY, api_secret=API_SECRET,
54+
55-
    scope=['manage_videos'], info={'username': USERNAME, 'password': PASSWORD})
55+
result = random.choice(vds)
56-
56+
57-
result = random.choice(vds)
57+
url = "http://youtube.com/watch?v=%s" % result	
58-
58+
print url
59-
url = "http://youtube.com/watch?v=%s" % result	
59+
yt = YouTube(url)
60-
print url
60+
fname = yt.filename
61-
yt = YouTube(url)
61+
if os.path.isfile("/tmp/"+fname+".mp4"):
62-
fname = yt.filename
62+
	print "supa udpa"
63-
if os.path.isfile("/tmp/"+fname+".mp4"):
63+
	os.remove("/tmp/"+fname+".mp4")
64-
	print "supa udpa"
64+
video = yt.get('mp4','360p')
65-
	os.remove("/tmp/"+fname+".mp4")
65+
print "downloading " + fname
66-
video = yt.get('mp4','360p')
66+
video.download("/tmp")
67-
print "downloading " + fname
67+
print "done downloading " + fname
68-
video.download("/tmp")
68+
carg = ["ffmpeg", "-y", "-i", "/tmp/"+fname+".mp4", "-vcodec", "h264", "-acodec", "mp2", "-preset", "ultrafast", "tmp/"+fname+".mp4"]
69-
print "done downloading " + fname
69+
print " ".join(carg)
70-
carg = ["ffmpeg", "-y", "-i", "/tmp/"+fname+".mp4", "-vcodec", "h264", "-acodec", "mp2", "-preset", "ultrafast", "tmp/"+fname+".mp4"]
70+
FNULL = open(os.devnull, 'w')
71-
print " ".join(carg)
71+
subprocess.call(carg,stdout=FNULL, stderr=subprocess.STDOUT)
72-
FNULL = open(os.devnull, 'w')
72+
url = d.upload('tmp/'+fname+'.mp4')
73-
subprocess.call(carg,stdout=FNULL, stderr=subprocess.STDOUT)
73+
opt = d.post('/me/videos', 
74-
url = d.upload('tmp/'+fname+'.mp4')
74+
	{'url': url, 'title': fname, 'published': 'true', 'channel': 'news'}
75-
opt = d.post('/me/videos', 
75+
)
76-
	{'url': url, 'title': fname, 'published': 'true', 'channel': 'news'}
76+
print("url: http://dailymotion.com/video/"+opt['id'])
77-
)
77+
os.remove("/tmp/"+fname+".mp4")
78-
print("url: http://dailymotion.com/video/"+opt['id'])
78+