#Use image Ubuntu
FROM ubuntu:jammy

#Update and install dependencies
RUN apt-get update
RUN apt-get install -y wget
RUN apt-get install -y xz-utils
RUN apt-get install -y libicu-dev
RUN apt-get install -y ffmpeg
  
#Install Node.js y npm
RUN apt-get update && apt-get install -y curl && \
    curl -fsSL https://deb.nodesource.com/setup_18.x | bash - && \
    apt-get install -y nodejs

#Install dependencies project
COPY package.json .
RUN npm install

#Working directory
WORKDIR /app
 
#Copy server.js to container
COPY ./server.js .
#COPY ./mp4decrypt /usr/local/bin/mp4decrypt

#Install FFMPEG ( ERROR DOWNLOAD )
#RUN wget https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz \
#&& tar -xf ffmpeg-release-amd64-static.tar.xz \
#&& cd ffmpeg-6.1-amd64-static/ \
#&& mv ffmpeg /usr/bin/ \
#&& mv ffprobe /usr/bin/

#Copy ffmpeg-release-amd64-static.tar.xz to container
#COPY ./lib/ffmpeg-release-amd64-static.tar.xz /tmp/

#Install FFMPEG
#RUN tar -xf /tmp/ffmpeg-release-amd64-static.tar.xz -C /tmp/ \
#  && mv /tmp/ffmpeg-*/ffmpeg /usr/bin/ \
#  && mv /tmp/ffmpeg-*/ffprobe /usr/bin/ \
#  && rm -rf /tmp/ffmpeg-*

#Download and config N_m3u8DL-RE
RUN wget https://github.com/nilaoda/N_m3u8DL-RE/releases/download/v0.2.1-beta/N_m3u8DL-RE_Beta_linux-x64_20240828.tar.gz \
    && tar xf N_m3u8DL-RE_Beta_linux-x64_20240828.tar.gz --strip-components 1 \
    && chmod +x N_m3u8DL-RE \
    && mv N_m3u8DL-RE /usr/local/bin

#Download and config shaka-packager
RUN wget https://github.com/shaka-project/shaka-packager/releases/download/v2.6.1/packager-linux-x64 \
    && chmod +x packager-linux-x64 \
    && mv packager-linux-x64 /usr/local/bin

#Create temp directory and grant permission
RUN mkdir /tmp/ramdisk \
    && chmod 777 /tmp/ramdisk
	
#Config ENV RE_LIVE_PIPE_OPTIONS
ENV RE_LIVE_PIPE_OPTIONS="-c copy -f mpegts pipe:1"

#Expose internal port server
EXPOSE 8080

#run server
CMD ["sh", "-c", "node server.js"]
