Skip to content

Instantly share code, notes, and snippets.

@tfl
Created October 25, 2016 18:03
Show Gist options
  • Save tfl/45afc0931ce5531e317380421d2c10e1 to your computer and use it in GitHub Desktop.
Save tfl/45afc0931ce5531e317380421d2c10e1 to your computer and use it in GitHub Desktop.
Example for querying 3sat.de mediathek in Ruby - did not get HD material though
require 'nokogiri'
require 'open-uri'
# 3SAT mediathek URL
base_uri = "http://www.3sat.de/mediathek"
# 3SAT rss feed url
rss_feed = "#{base_uri}/rss/mediathek.xml"
# 3SAT webservice
detail_uri = "#{base_uri}/xmlservice/web/beitragsDetails?ak=web&id="
# Video type and such
VIDEO_TYPE = "h264_aac_mp4_http_na_na"
QUALITY = "veryhigh"
# open rss feed
doc = Nokogiri::XML(open(rss_feed))
# parse xml
rss_items = doc.xpath("//rss//channel/item")
# loop though each item
rss_items.each do |rss_item|
title = rss_item.at_xpath(".//title").text
link = rss_item.at_xpath(".//link").text
# we need this later:
# we could also use URI class but... this is simpler and
# does not need additional libraries
media_id = link.split('=')[1]
# build detail uri and open it
xml = Nokogiri::XML(open("#{detail_uri}#{media_id}"))
# build a list formitaeten
details = xml.xpath("//video/formitaeten/formitaet")
# loop through each formitaet
details.each do |detail|
quality = detail.at_xpath(".//quality").text
if quality == QUALITY && detail.attribute_nodes[0].text == VIDEO_TYPE
url = detail.at_xpath(".//url").text
puts "'#{title}'\t'#{url}'"
break # there are more then one h264_aac_mp4_http_na_na and veryhigh marked movies - but we quit here
# full list of properties available via detail.at_xpath("...").text
# - quality (string)
# - ratio (string)
# - height (number)
# - width (number)
# - videoBitrate (number)
# - audioBitrate (number)
# - filesize (number)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment