askcompu

Untitled

Jul 21st, 2015
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.90 KB | None | 0 0
  1. ef get_youtube_title(uri, auth_key):
  2.     vid = None
  3.     if 'youtu.be/' not in uri:
  4.         if '?v=' in uri:
  5.             vid = uri[uri.index('?v=')+3:uri.index('?v=') + 14]
  6.         elif '&v=' in uri:
  7.             vid = uri[uri.index('&v=')+3:uri.index('&v=') + 14]
  8.         else:
  9.             return None
  10.     else:
  11.         vid = uri[uri.rindex('be/')+3:uri.rindex('be/')+14]
  12.  
  13.     video_data = query(vid, auth_key)
  14.     if video_data is None:
  15.       return None
  16.     else:
  17.       title, views, time, uploader, likes, dislikes = video_data
  18.     if title == '':
  19.         return None
  20.     percentage = get_percentage(likes, dislikes)
  21.     # Not including the uploader in the title info; it's rarely important in determining a link's quality.
  22.     return "\002You\00300,04Tube\017 " + title + " - " + views + " views - Uploaded by " + uploader + " - " + time + "long - " + likes + " likes - " + dislikes + " dislikes - " + percentage + "%"
Advertisement
Add Comment
Please, Sign In to add comment