Last active
July 25, 2017 11:50
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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