Last active
September 7, 2016 19:05
-
-
Save Tomin1/e87fe3f099e1ad01a073 to your computer and use it in GitHub Desktop.
Elisa skriptejä
This file contains 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
#!/bin/bash | |
# Public domain | |
# Requires: elisa_url.py, vlc, wget | |
# Recommends: inotifywait (inotify-tools) | |
# Use: elisa_katso.sh url_of_the_video_page_in_elisa_viihde | |
TMP_FILE="/tmp/elisa-viihde-$$.mpg" | |
#TMP_FILE="$HOME/.cache/elisa-viihde-$$.mpg" | |
URL=$(elisa_url.py "${@: -1}") | |
if [ "$?" -ne "0" ]; then | |
echo "Ei voitu hakea osoitetta videolle!" | |
exit 2 | |
fi | |
if [ -z $(which inotifywait 2> /dev/null) ]; then | |
sh -c "sleep 10 && vlc $TMP_FILE" & | |
else | |
sh -c "inotifywait -e create --include $TMP_FILE ${TMP_FILE%/*} && vlc $TMP_FILE" & | |
sleep 1 | |
fi | |
wget ${@: 1:${#@}-1} -O "$TMP_FILE" "$URL" | |
wait && rm "$TMP_FILE" |
This file contains 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
#!/bin/bash | |
# Public domain | |
# Requires: elisa_url.py, wget | |
# Use: elisa_latain.sh url_of_the_video_page_in_elisa_viihde video_file | |
URL=$(elisa_url.py "${@: -2:1}") | |
if [ "$?" -ne "0" ]; then | |
echo "Ei voitu hakea osoitetta videolle!" | |
exit 2 | |
fi | |
wget ${@: 1:${#@}-2} -O "${@: -1}" "$URL" |
This file contains 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
#!/usr/bin/env python3 | |
# | |
# Elisa Viihde url hakija | |
# Copyright (c) Tomi Leppänen, 2014-2015 | |
# | |
# Permission is hereby granted, free of charge, to any person obtaining a copy | |
# of this software and associated documentation files (the "Software"), to deal | |
# in the Software without restriction, including without limitation the rights | |
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
# copies of the Software, and to permit persons to whom the Software is | |
# furnished to do so, subject to the following conditions: | |
# | |
# The above copyright notice and this permission notice shall be included in | |
# all copies or substantial portions of the Software. | |
# | |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
# THE SOFTWARE. | |
# | |
from http.cookiejar import CookieJar | |
from urllib.request import urlopen, build_opener, HTTPCookieProcessor | |
from urllib.parse import urlencode, urlparse, parse_qsl | |
from json import loads as json_loads | |
from re import compile as re_compile | |
USERNAME='laita käyttäjä tähän' | |
PASSWORD='laita salasana tähän' | |
BASE_URL = "http://api.elisaviihde.fi/etvrecorder/" | |
LOGIN_URL = BASE_URL + "login.sl" | |
PROGRAM_INFO_URL = BASE_URL + "program.sl" | |
PROGRAM_VIDEO_PAGE_REGEX = re_compile( | |
r"https?://elisaviihde.fi/tallenteet/katso/(?P<id>\d+)" | |
) | |
PROGRAM_INFO_PAGE_REGEX = re_compile( | |
r"https?://elisaviihde.fi/ohjelmaopas/ohjelma/(?P<id>\d+)" | |
) | |
def login(username, password): | |
cookies = CookieJar() | |
opener = build_opener(HTTPCookieProcessor(cookies)) | |
response = opener.open(LOGIN_URL, data=urlencode({ | |
'username': username, | |
'password': password, | |
'savelogin': None, | |
'ajax': True, | |
}).encode('utf-8') | |
) | |
if response.read() != b"TRUE": | |
return None | |
return cookies | |
def get_programid(string): | |
try: | |
value = int(string) | |
except ValueError: | |
pass | |
else: | |
return value | |
m = PROGRAM_VIDEO_PAGE_REGEX.match(string) | |
if m is None: | |
m = PROGRAM_INFO_PAGE_REGEX.match(string) | |
if m is None: | |
return None | |
return int(m.group("id")) | |
def get_program_info(login, programid): | |
opener = build_opener(HTTPCookieProcessor(login)) | |
response = opener.open(PROGRAM_INFO_URL, data=urlencode({ | |
'programid': programid, | |
'ajax': True, | |
}).encode('utf-8') | |
) | |
try: | |
data = json_loads(response.read().decode('utf-8')) | |
except ValueError: | |
return None | |
return data | |
def main(prog=None, program=None): | |
from sys import stderr | |
creds = login(USERNAME, PASSWORD) | |
if creds is None: | |
stderr.write("Login was not successful!\n") | |
return 2 | |
if program is None: | |
stderr.write("No program id given. Type program id or url: ") | |
program = input() | |
programid = get_programid(program) | |
if programid is None: | |
stderr.write("Invalid program id or url!\n") | |
return 3 | |
program_info = get_program_info(creds, programid) | |
print(program_info['url'], end='') | |
return 0 | |
if __name__ == '__main__': | |
from sys import argv | |
main(*argv) |
This file contains 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
<?xml version="1.0" encoding="UTF-8"?> | |
<configurations xmlns="http://launchy.mozdev.org/configurations"> | |
<application> | |
<label>Katso Elisa Viihteestä</label> | |
<type>3</type> | |
<command>/usr/local/bin/elisa_katso.sh</command> | |
</application> | |
</configurations> |
This file contains 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
Elisa Viihde -skriptejä | |
======================= | |
Erilaisia skriptejä Elisa Viihteen käyttöön. Laita kaikki skriptit `/usr/local/bin`-hakemistoon ja anna niille suoritusoikeudet (`chmod +x`). | |
`elisa_url.py` on Python-skripti, joka hakee videotiedoston url-osoitteen annetun sivun url-osoitteen perusteella. Sitä käytetään yleensä osana jotain muuta skriptiä, kuten tässä olevat bash-skriptit. | |
`elisa_latain.sh` on bash-skripti, joka lataa videon annetun URL-osoitteen perusteella annettuun hakemistoon käyttäen `elisa_url.py`:tä ja `wget`:iä. Sitä käytetään antamalla toiseksi viimeiseksi parametriksi videon sivun osoite ja viimeiseksi kohdetiedosto. Muut parametrit annetaan suoraan `wget`:lle. | |
`elisa_katso.sh` on bash-skripti, joka toistaa videon VLC-soittimella ladaten sitä samaan aikaan `wget`:llä. Se käyttää `elisa_url.py`:tä ja myös `inotifywait`:iä, mikäli se on käytettävissä. Videon katselun päätyttyä eli kun VLC suljetaan, video poistetaan koneelta. Oletus tallennuspaikka on `/tmp`-hakemistossa, mutta sitä kannattaa muuttaa mikäli `/tmp` on sijoitettu keskusmuistiin tai on muuten liian pieni. Skriptissä on ehdotettu `.cache`-hakemistoa kotihakemistossa. Tätä skriptiä käytetään antamalla viimeisenä parametrina videon sivun osoite. Muut parametrit annetaan suoraan `wget`:lle. | |
`launchy.xml` on Firefoxin Launchy-lisäosan asetustiedosto, joka laitetaan hakemistoon `~/.mozilla/firefox/profiilisi/chrome` ja Firefoxiin asennetaan Lauchy-lisäosa. Tämän jälkeen on mahdollista avata viedoita klikkaamalla niiden linkkiä oikealla hiirennapilla ja valitsemalla *Launchy / Open Link in Katso Elisa Viihteessä*. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment