Skip to content

Instantly share code, notes, and snippets.

@cptangry
Last active July 25, 2017 11:50
Show Gist options
  • Save cptangry/490e9ef66b862b5a704a846887892000 to your computer and use it in GitHub Desktop.
Save cptangry/490e9ef66b862b5a704a846887892000 to your computer and use it in GitHub Desktop.
Ruby ile bir youtube playlistindeki linkleri ve video adlarını almak(format atacağım karalama olarak yazmıştım css sini çözmek için)
# coding: utf-8
require 'nokogiri'
require 'open-uri'
require 'yaml'
print "Bir Youtube Playlist Linki Girin: " unless ARGV[0] # İlk parametre boşsa yazdır
# Parametre verilmemişse kullanıcı playlist linki girecek
PLAYLIST = ARGV[0] || gets.chomp
SAYFA = Nokogiri::HTML(open(PLAYLIST).read) # SAYFA sabitine playlist linki çözümlenecek
YoutubeREGEX = /(youtu\.be\/|youtube\.com\/(watch\?(.*&)?v=|(embed|v)\/))([^\?&"'>]+)/
# Video Adı => Video linki içeren hash üretilecek
sarkilar = Hash[SAYFA.css('table.pl-video-table')
.css('a.pl-video-title-link').map {|link|
[link.text.strip, "https://www.youtube.com#{link["href"]}"
.match(YoutubeREGEX)[0]]}]
File.write("Playlist-#{Time.now.to_a(3..6).join('-')}.yml", sarkilar.to_yaml)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment