Esempio n. 1
0
def tweet_uyd(api):
    if path.isfile(last_epfile):
        last_ep = datetime.strptime(open(last_epfile, 'r').read(), '%a, %d %b %Y %H:%M:%S +0000')
    else:
        last_ep = datetime.strptime('Fri, 15 Jul 2016 19:51:00 +0000', '%a, %d %b %Y %H:%M:%S +0000')

    #req = requests.get('http://uhhyeahdude.com/podcast/')
    #feed = xml.etree.ElementTree.parse(req.content).getroot()
    feed = untangle.parse('http://uhhyeahdude.com/podcast/')
    eps = feed.rss.channel.item
    new_eps = []
    for ep in eps:
        pubdate = datetime.strptime(ep.pubDate.cdata, '%a, %d %b %Y %H:%M:%S +0000')
        if pubdate > last_ep:
            new_eps.append(ep)
            last_ep = pubdate

    if new_eps == []:
        #print 'No new eps'
        return

    #pickle.dump(last_ep, open(last_epfile, 'w'))
    open(last_epfile, 'w').write(last_ep.strftime('%a, %d %b %Y %H:%M:%S +0000'))
    for ep in reversed(new_eps):
        desc = ep.description.cdata
        desc = desc.replace('\n', ' ').replace('\t', ' ')
        words = desc.split(' ')
        if set(['intro:', 'outro:', 'http://uhhyeahdude.com']).issubset(set(words)):
            intro = ' '.join(words[words.index('intro:')+1:words.index('outro:')-1])
            intro_url = youtube_search.search(intro)
            api.PostUpdate('{0} intro: {1} {2}'.format(ep.title.cdata, intro, intro_url))
            outro = ' '.join(words[words.index('outro:')+1:words.index('http://uhhyeahdude.com')])
            outro_url = youtube_search.search(outro)
            api.PostUpdate('{0} outro: {1} {2}'.format(ep.title.cdata, outro, outro_url))
Esempio n. 2
0
def get_artists(query):
    video_data = youtube_search.search({'q': query, 'max_results': 5})
    if video_data:
        tokens = []
        for datum in video_data:
            tokens.extend(re.split('[-|,]', datum[0]))
        tokens = set(tokens)

        artists = []
        for token in tokens:
            if is_artist(token.strip()):
                artists.append(token.strip().lower())

        return set(map(lambda x: x.title(), artists))
Esempio n. 3
0
def post_action():
    try:
        body = request.form.get('Body')
        if body =='#stop':
            print('[RECEIVED] STOP request') 
            change_mode('0')
            os.system('pkill vlc')
            return "Success: STOP"
        elif body == '#queue':
            print('[RECEIVED] QUEUE request')
            change_mode('1')
            os.system('pkill vlc')
            subprocess.Popen('./play.py') 
            return "Success: QUEUE MODE ON"
        elif body == '#next':
            if check_mode() == '1':
                print('[RECEIVED] NEXT request')
                os.system('pkill vlc')
                return "Success: NEXT"
            return "Fail: Not in queue mode"
        else:
            if check_mode() == '0':
                print('[RECEIVED] PLAY request')
                url = youtube_search.search(body)
                if url is None:
                    return "Fail: Could not find song"
                os.system('pkill vlc')
                cmd = "youtube-dl -f 140 -o - " + url + "| vlc-wrapper --play-and-exit --novideo --intf dummy -"
                subprocess.Popen(cmd, shell=True)
                return "Success: PLAYING '" + body + "'"
            else:
                print('[RECEIVED] ADD request')
                fo = open('playlist.txt', 'a')
                fo.write(body + '\n')
                fo.close()
                if not is_process_running('vlc'):
                    subprocess.Popen('./play.py')
                return "Success: ADDED TO QUEUE '" + body + "'"
    except Exception, err:
        print(traceback.format_exc())
Esempio n. 4
0
def main(args):

    #load search keys
    if args.file:
        args.searchkeys = playlist.fetch_songs(args.file)

    elif args.ytplaylist:
        args.searchkeys = [args.ytplaylist]

    #get youtube results
    youtube_results = []
    for s in args.searchkeys:
        search_result = youtube_search.search(s, \
                True if args.ytplaylist else False)
        youtube_results.append(search_result)

    #print search results
    if args.search:
        if len(args.searchkeys) == 1:
            print_search_results(youtube_results[0], \
                    True if args.ytplaylist else False)
            sys.exit(0)
        else:
            print('Error: Please enter one search key only')
            sys.exit(1)

    #choose number
    playlist_data = []
    if args.number:
        if len(args.searchkeys) == 1 and 1 <= args.number <= len(youtube_results[0]):
            playlist_data.append(youtube_results[0][args.number-1])
        else:
            if len(args.searchkeys) != 1:
                print('Error: Cannot specify number with multiple search keys')
            if not 1 <= args.number <= len(youtube_results[0]):
                    print('Error: Please enter a number in range {}-{}'.format(1, \
                            len(youtube_results[0])))
            sys.exit(1)
    else:
        for r in youtube_results:
            playlist_data.append(r[0])

    #get and print playlist/video name(s) and id(s)
    yt_ids = []
    if args.open:
        if args.ytplaylist:
            print('Opening: {}'.format( \
                    get_playing_string(playlist_data[0], True)))
            yt_ids.append(get_playlist_id(playlist_data[0]))
        else:
            print('Opening: {}'.format( \
                    get_playing_string(playlist_data[0], False)))
            yt_ids.append(get_video_id(playlist_data[0]))

    elif args.ytplaylist:
        print('Playing YouTube Playlist{}:\n- {}'.format( \
                ' (on repeat)' if args.repeat else '',
                get_playing_string(playlist_data[0], True)))
        yt_ids.append(get_playlist_id(playlist_data[0]))

    else:
        print('Playing song(s){}:'.format(' (on repeat)' if args.repeat else ''))
        for s in playlist_data:
            print('- {}'.format(get_playing_string(s, False)))
            yt_ids.append(get_video_id(s))

    if args.open and len(yt_ids) <= 2:
        url = BASE_URL + ('playlist?list=' if args.ytplaylist else 'watch?v=') + yt_ids[0]
        webbrowser.open(url)
        sys.exit(0)

    #fire and forget
    mpv_gateway.play(BASE_URL, yt_ids, args.ytplaylist, args.video, args.repeat)
Esempio n. 5
0
import praw
import time
from pymongo import MongoClient
from youtube_search import search

db = MongoClient().bot
collection = db.memory

yt_search = "https://www.youtube.com/results?search_query="

r = praw.Reddit(user_agent="humm_youtube")
r.login("humm_youtube", "humm_youtube")
subreddit = r.get_subreddit('hummhumm')
submissions = subreddit.get_new(limit=100)
current_time = time.time()
for submission in submissions:
    sub_age = (current_time - submission.created_utc) / 60 / 60 / 24
    if sub_age < 1 and submission.comments != []:
        for comm in submission.comments:
            if "http" not in comm.body and collection.find_one({"comm_id": str(submission.id) + str(comm.id)}) is None:
                line = comm.body.split("\n")[0]
                res = search(line)
                if res is not None:
                    print(res)
                    comm.reply("[" + line + "](" + res + ")+\n\nI am a video bot !")
                    collection.insert_one({"comm_id": str(submission.id) + str(comm.id)})
Esempio n. 6
0
#!/usr/bin/python

import os
import subprocess
import youtube_search

if os.stat("playlist.txt").st_size > 0:
    with open('playlist.txt', 'r') as playlist:
        song_name = playlist.readline().strip()
    url = youtube_search.search(song_name)
    cmd = "youtube-dl -f 140 -o - " + url + "| vlc-wrapper --play-and-exit --novideo --intf dummy -; if [ $(cat autoplay.txt) -eq '1' ]; then ./deque.py; ./play.py; fi;" 
    subprocess.Popen(cmd, shell=True)
Esempio n. 7
0
# Rotten Tomatoes API for Python
# docs: https://github.com/zachwill/rottentomatoes
from rottentomatoes import RT

# initialize a rotten tomatoes instance
rt = RT( config.api_key )

# get a list of movie openings from RT
opening_movies = rt.lists('movies', 'opening')

# iterate through opening movies and create instances of our Movie class for each
movie_collection = []
for mov in opening_movies['movies']:
    # Find youtube trailer
    options = youtube_search.Options( mov['title'] + ' trailer', 1 )
    trailer_id = youtube_search.search(options)

    # Convert cast names to a comma separated list
    cast = ''
    l = mov['abridged_cast'].__len__() - 1
    for i, actor in enumerate( mov['abridged_cast'] ):
        cast += actor['name']
        if i < l:
            cast += ', '

    movie = media.Movie(mov['title'], mov['synopsis'], mov['posters']['thumbnail'], trailer_id, mov['mpaa_rating'], mov['release_dates']['theater'], mov['ratings']['critics_score'], cast)
    movie_collection.append(movie)

# print movies
my_movie_list.open_movies_page( movie_collection )
# initializing empty movies list to save all Movie objects
movies = []
# looping through the saved titles
for movie_title in movie_names:
    # initializing tmdb object
    search = tmdb.Search()
    # querying tmdb object to search for the movie title
    response = search.movie(query=movie_title)
    # looping through search results
    for s in search.results:
        # check if the result title is the same as movie title
        if s['title'] == movie_title:
            # saves the movie poster path
            poster_path = "https://image.tmdb.org/t/p/w500" + s['poster_path']
            search_query = movie_title + " trailer"
            # gets youtube trailer video's url
            youtube_trailer_url = youtube_search.search(search_query)
            # creating a local movie object with title, plot , poster image
            # and youtube trailer video
            movie_object = media.Movie(s['title'], s['overview'], poster_path,
                                       youtube_trailer_url)
            # adding the movie object to movies lists
            movies.append(movie_object)
            # breaking loop after appropriate result object
            # to avoid looping through extra results
            break

# calling the open_movies_page function from fresh tomatoes
# passing the list of all the movie objects as a parameter
fresh_tomatoes.open_movies_page(movies)