Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # begin createplaylist.py
- #!/usr/bin/python
- import httplib2
- import os
- import sys
- from apiclient.discovery import build
- from oauth2client.file import Storage
- from oauth2client.client import flow_from_clientsecrets
- from oauth2client.tools import run
- import time
- filename = sys.argv[1]
- vids = [x.strip() for x in open(filename).readlines()]
- title = sys.argv[2]
- CLIENT_SECRETS_FILE = "client_secrets.json"
- MISSING_CLIENT_SECRETS_MESSAGE = "your configuration a shit"
- # An OAuth 2 access scope that allows for full read/write access.
- YOUTUBE_READ_WRITE_SCOPE = "https://www.googleapis.com/auth/youtube"
- YOUTUBE_API_SERVICE_NAME = "youtube"
- YOUTUBE_API_VERSION = "v3"
- flow = flow_from_clientsecrets(CLIENT_SECRETS_FILE,
- message=MISSING_CLIENT_SECRETS_MESSAGE,
- scope=YOUTUBE_READ_WRITE_SCOPE)
- storage = Storage("%s-oauth2.json" % sys.argv[0])
- credentials = storage.get()
- if credentials is None or credentials.invalid:
- credentials = run(flow, storage)
- youtube = build(YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION,
- http=credentials.authorize(httplib2.Http()))
- playlist = youtube.playlists().insert(
- part="snippet,status",
- body=dict(
- snippet=dict(
- title=title,
- description=""
- ),
- status=dict(
- privacyStatus="private"
- )
- )
- ).execute()
- print 'created playlist', playlist['id']
- for v in vids:
- try:
- videoinsert = youtube.playlistItems().insert(
- part='snippet,id',
- body={
- 'snippet': {
- 'playlistId': playlist['id'],
- 'resourceId': {
- 'videoId': v,
- 'kind': 'youtube#video'
- }
- }
- }).execute()
- print 'added', v
- except Exception:
- print 'failed to add', v
- print "New playlist id: %s" % playlist["id"]
- # end createplaylist.py
- # begin eqdpage.py
- #!/usr/bin/python
- from urllib2 import urlopen
- from urlparse import urlparse, parse_qs
- from bs4 import BeautifulSoup
- import sys
- import re
- from pyutils.xutils import *
- print 'getting eqd page'
- page = sys.argv[1]
- page = urlopen(page).read()
- page = BeautifulSoup(page)
- validdomains = ('www.youtube.com', 'youtube.com', 'www.youtu.be', 'youtu.be')
- links = filter(lambda x: x, map(lambda x: x.get('href'), page.findAll('a')))
- urls = map(lambda x: urlparse(x), links)
- yturls = filter(lambda x: x.netloc in validdomains, urls)
- queries = filter(lambda x: x, map(lambda x: x.query, yturls))
- queries = map(lambda x: parse_qs(x), queries)
- linkedvideoids = filter(lambda x: x, map(lambda x: x.get('v'), queries))
- linkedvideoids = map(lambda x: x[0], linkedvideoids)
- frames = filter(lambda x: x, map(lambda x: x.get('src'), page.findAll('iframe')))
- urls = map(lambda x: urlparse(x), frames)
- ytframes = filter(lambda x: x.netloc in validdomains, urls)
- paths = filter(lambda x: x, map(lambda x: x.path, ytframes))
- embeddedvideoids = map(lambda x: x.split('/')[2], paths)
- videoids = linkedvideoids + embeddedvideoids
- seen = set()
- playlist = []
- for v in videoids:
- if v in seen:
- continue
- playlist.append(v)
- seen.add(v)
- print 'got playlist: %d videos' % len(playlist)
- title = page.title.text
- print 'creating playlist:', title
- p = x(['createplaylist.py', '<playlist', title])
- out = getwritepipe('playlist')
- out.write('\n'.join(playlist))
- out.close()
- p.wait()
- # end eqdpage.py
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement