Skip to content

Instantly share code, notes, and snippets.

View ALenfant's full-sized avatar

Antonin Lenfant Kodia ALenfant

View GitHub Profile
@ALenfant
ALenfant / main.py
Created September 2, 2021 20:35
Fetch m3u8 playlist, download individual ts segment files, concatenate and convert to mp4
import m3u8
from multiprocessing.pool import ThreadPool
import os
import requests
import subprocess
url = "http://ENTER_URL_HERE.m3u8"
def file_name_from_url(url):
# assumes that the last segment after the / represents the file name
@ALenfant
ALenfant / kspa_igraph.py
Last active April 12, 2022 13:48
An implementation of the KSPA algorithm (for K-Shortest Paths based on A* found at http://en.cnki.com.cn/Article_en/CJFDTOTAL-JSJY200804041.htm), using the igraph library, in Python 3. This algorithm has the particularity of being able to find the k shortest paths in a multigraph (a graph, directed or not, with parallel edges). Implemented accor…
def heuristic_cost_estimate(graph, source, target):
#Possible implementation here https://gist.github.com/delijati/1629405
return 0 #Heuristic = 0 : same as Dijkstra
def reconstruct_path(came_from, current_node):
if current_node in came_from:
p = reconstruct_path(came_from, came_from[current_node])
return p + [current_node]
else:
return [current_node]
@ALenfant
ALenfant / yen_igraph.py
Last active October 26, 2022 19:39
Yen's algorithm for igraph, adapted from Wikipedia's pseudocode. The arguments are: graph: your igraph graph object (warning: the edge's id will change by using this function, so make a copy with gcopy if you want to keep them intact); source: source vertex; target: target vertex; num_k: number of shortest paths you want; weights: name of the ed…
def path_cost(graph, path, weights=None):
pathcost = 0
for i in range(len(path)):
if i > 0:
edge=graph.es.find(_source=path[i-1], _target=path[i])
if weights != None:
pathcost += edge[weights]
else:
#just count the number of edges
pathcost += 1